From e2ea844d3f774ff7e85edfbcb664e92206f5da42 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:09:08 +0300 Subject: [PATCH] v0.0.21 (#16) * v0.0.21 Signed-off-by: Alexander Piskun --- .github/workflows/analysis-coverage.yml | 40 +++++++++---------------- CHANGELOG.md | 10 +++++++ nc_py_api/_session.py | 2 +- nc_py_api/nextcloud.py | 6 +++- tests/gfixture.py | 12 ++++---- tests/nc_app_test.py | 8 +++++ 6 files changed, 44 insertions(+), 34 deletions(-) diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 73c0380c..74fb6c69 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -20,6 +20,14 @@ on: - '.pre-commit-config.yaml' workflow_dispatch: +env: + NEXTCLOUD_URL: "http://localhost:8080/index.php" + APP_ID: "nc_py_api" + APP_VERSION: "1.0.0" + APP_SECRET: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" + NC_AUTH_USER: "admin" + NC_AUTH_PASS: "adminpassword" + jobs: analysis: runs-on: macos-12 @@ -52,13 +60,6 @@ jobs: - nextcloud: "27.0.0" python: "3.10" php-version: "8.2" - env: - nextcloud_url: "http://localhost:8080/index.php" - app_name: "nc_py_api" - app_version: "1.0.0" - app_secret: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" - nc_auth_user: "admin" - nc_auth_pass: "adminpassword" services: mariadb: @@ -136,10 +137,10 @@ jobs: sleep 5s php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \ --net=host --host="127.0.0.1" --expose="local" - php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \ + php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \ --daemon-config-id 1 \ --port 9002 \ - --secret $app_secret \ + --secret $APP_SECRET \ -e --force-scopes --system-app kill -15 $(cat /tmp/_install.pid) timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null @@ -187,12 +188,6 @@ jobs: php-version: "8.2" env: NC_dbname: nextcloud_abz - nextcloud_url: "http://localhost:8080/index.php" - app_name: "nc_py_api" - app_version: "1.0.0" - app_secret: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" - nc_auth_user: "admin" - nc_auth_pass: "adminpassword" services: postgres: @@ -271,10 +266,10 @@ jobs: sleep 5s php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \ --net=host --host="127.0.0.1" --expose="local" - php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \ + php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \ --daemon-config-id 1 \ --port 9002 \ - --secret $app_secret \ + --secret $APP_SECRET \ -e --force-scopes --system-app kill -15 $(cat /tmp/_install.pid) timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null @@ -316,13 +311,6 @@ jobs: nextcloud: [ "27.0.0" ] python: [ "3.11" ] php-version: [ "8.2" ] - env: - nextcloud_url: "http://localhost:8080/index.php" - app_name: "nc_py_api" - app_version: "1.0.0" - app_secret: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" - nc_auth_user: "admin" - nc_auth_pass: "adminpassword" services: oracle: @@ -400,10 +388,10 @@ jobs: sleep 5s php occ app_ecosystem_v2:daemon:register docker-install Docker unix-socket 0 0 \ --net=host --host="127.0.0.1" --expose="local" - php occ app_ecosystem_v2:app:register $app_name $app_version "NcPyApi" \ + php occ app_ecosystem_v2:app:register $APP_ID $APP_VERSION "NcPyApi" \ --daemon-config-id 1 \ --port 9002 \ - --secret $app_secret \ + --secret $APP_SECRET \ -e --force-scopes --system-app kill -15 $(cat /tmp/_install.pid) timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null diff --git a/CHANGELOG.md b/CHANGELOG.md index bfda14ef..f36368eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. +## [0.0.21 - 2023-06-04] + +### Added + +- `app_cfg` property to `NextcloudApp` class. + +### Fixed + +- All input environment variables now in Upper Case. + ## [0.0.20 - 2023-06-03] - Written from the scratch new version of the Nextcloud Python Client. Deep Alpha. diff --git a/nc_py_api/_session.py b/nc_py_api/_session.py index 66e854b2..5935347d 100644 --- a/nc_py_api/_session.py +++ b/nc_py_api/_session.py @@ -48,7 +48,7 @@ def __init__(self, **kwargs): def _get_value(value_name: str, raise_not_found=True, **kwargs): value = kwargs.get(value_name, None) if not value: - value = environ.get(value_name, None) + value = environ.get(value_name.upper(), None) if not value and raise_not_found: raise ValueError(f"`{value_name}` is not found.") return value diff --git a/nc_py_api/nextcloud.py b/nc_py_api/nextcloud.py index d8cc4579..cf07c7aa 100644 --- a/nc_py_api/nextcloud.py +++ b/nc_py_api/nextcloud.py @@ -6,7 +6,7 @@ from fastapi import Request -from ._session import NcSession, NcSessionApp, NcSessionBasic, ServerVersion +from ._session import AppConfig, NcSession, NcSessionApp, NcSessionBasic, ServerVersion from .appconfig_preferences_ex import AppConfigExAPI, PreferencesExAPI from .apps import AppAPI from .constants import APP_V2_BASIC_URL, ApiScope, LogLvl @@ -114,6 +114,10 @@ def user(self, value: str): self._session.user = value self._session.update_server_info() + @property + def app_cfg(self) -> AppConfig: + return self._session.cfg + def request_sign_check(self, request: Request) -> bool: try: self._session.sign_check(request) diff --git a/tests/gfixture.py b/tests/gfixture.py index 37bfb22f..89753c17 100644 --- a/tests/gfixture.py +++ b/tests/gfixture.py @@ -6,12 +6,12 @@ secret = "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" \ "X1T8Pi+T5papEolTLxz3fJSPS8ffC4204YmggxPsbJdCkXHWNPHKWS9B+vTj2SIV" if not environ.get("CI", False): # For local tests - environ["nc_auth_user"] = "admin" - environ["nc_auth_pass"] = "admin" # "MrtGY-KfY24-iiDyg-cr4n4-GLsNZ" - environ["nextcloud_url"] = "http://nextcloud.local/index.php" - environ["app_name"] = "nc_py_api" - environ["app_version"] = "1.0.0" - environ["app_secret"] = secret + environ["NC_AUTH_USER"] = "admin" + environ["NC_AUTH_PASS"] = "admin" # "MrtGY-KfY24-iiDyg-cr4n4-GLsNZ" + environ["NEXTCLOUD_URL"] = "http://nextcloud.local/index.php" + environ["APP_ID"] = "nc_py_api" + environ["APP_VERSION"] = "1.0.0" + environ["APP_SECRET"] = secret NC = Nextcloud() if environ.get("SKIP_NC_WO_AE", False): diff --git a/tests/nc_app_test.py b/tests/nc_app_test.py index 9f9d68b2..93f8615c 100644 --- a/tests/nc_app_test.py +++ b/tests/nc_app_test.py @@ -1,3 +1,4 @@ +from os import environ import pytest from gfixture import NC_APP, NC @@ -22,6 +23,13 @@ def test_scope_allowed(): assert not NC_APP.scope_allowed(999999999) +def test_app_cfg(): + app_cfg = NC_APP.app_cfg + assert app_cfg.app_name == environ["APP_ID"] + assert app_cfg.app_version == environ["APP_VERSION"] + assert app_cfg.app_secret == environ["APP_SECRET"].encode("UTF-8") + + @pytest.mark.skipif(NC is None, reason="Usual Nextcloud mode required for the test") def test_scope_allow_app_ecosystem_disabled(): NC.apps.disable("app_ecosystem_v2")