-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
184 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,9 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
|
||
<!--\n ~ Licensed to the Apache Software Foundation (ASF) under one or more\n ~ contributor license agreements. See the NOTICE file distributed with\n ~ this work for additional information regarding copyright ownership.\n ~ The ASF licenses this file to You under the Apache License, Version 2.0\n ~ (the "License"); you may not use this file except in compliance with\n ~ the License. You may obtain a copy of the License at\n ~\n ~ http://www.apache.org/licenses/LICENSE-2.0\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an "AS IS" BASIS,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n ~\n --> | ||
| OSV URL | Ecosystem | Package | Version | Source | | ||
| --- | --- | --- | --- | --- | | ||
| https://osv.dev/GHSA-599f-7c49-w659 | Maven | org.apache.commons:commons-text | 1.8 | pom.xml | | ||
| https://osv.dev/GHSA-wxqc-pxw9-g2p8 | Maven | org.springframework:spring-core | 6.0.7 | pom.xml | | ||
| https://osv.dev/GHSA-mjmj-j48q-9wg2 | Maven | org.yaml:snakeyaml | 1.33 | pom.xml | | ||
| https://osv.dev/GHSA-px8h-6qxv-m22q | PyPI | werkzeug | 1.0.1 | streampipes-wrapper-python/requirements.txt | | ||
| https://osv.dev/GHSA-xg9f-g7g7-2323 | PyPI | werkzeug | 1.0.1 | streampipes-wrapper-python/requirements.txt | | ||
| https://osv.dev/PYSEC-2022-203 | PyPI | werkzeug | 1.0.1 | streampipes-wrapper-python/requirements.txt | | ||
| https://osv.dev/GHSA-36jr-mh4h-2g58 | npm | d3-color | 1.4.1 | ui/package-lock.json | | ||
| https://osv.dev/GHSA-j8r2-6x86-q33q | PyPI | requests | 2.24.0 | streampipes-wrapper-python/requirements.txt | | ||
| https://osv.dev/GHSA-36jr-mh4h-2g58 | npm | d3-color | 2.0.0 | ui/package-lock.json | | ||
| https://osv.dev/GHSA-ww39-953v-wcq6 | npm | glob-parent | 3.1.0 | ui/package-lock.json | | ||
| https://osv.dev/GHSA-4943-9vgg-gr5r | npm | quill | 1.3.7 | ui/package-lock.json | | ||
| https://osv.dev/GHSA-hc6q-2mpp-qw7j | npm | webpack | 5.74.0 | ui/package-lock.json | | ||
| https://osv.dev/GHSA-f9xv-q969-pqx4 | npm | yaml | 2.2.1 | ui/package-lock.json | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,8 @@ | |
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.environ[\"USER\"] = \"[email protected]\"\n", | ||
"os.environ[\"API-KEY\"] = \"XXX\"\n" | ||
"os.environ[\"SP_USERNAME\"] = \"[email protected]\"\n", | ||
"os.environ[\"SP_API_KEY\"] = \"XXX\"\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
|
@@ -59,7 +59,7 @@ | |
"outputs": [], | ||
"source": [ | ||
"config = StreamPipesClientConfig(\n", | ||
" credential_provider=StreamPipesApiKeyCredentials.from_env(username_env=\"USER\", api_key_env=\"API-KEY\"),\n", | ||
" credential_provider=StreamPipesApiKeyCredentials(),\n", | ||
" host_address=\"localhost\",\n", | ||
" https_disabled=True,\n", | ||
" port=80\n", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,8 @@ | |
"source": [ | ||
"import os\n", | ||
"\n", | ||
"os.environ[\"USER\"] = \"[email protected]\"\n", | ||
"os.environ[\"API-KEY\"] = \"XXX\"\n", | ||
"os.environ[\"SP_USERNAME\"] = \"[email protected]\"\n", | ||
"os.environ[\"SP_API_KEY\"] = \"XXX\"\n", | ||
"\n", | ||
"# Use this if you work locally:\n", | ||
"os.environ[\"BROKER-HOST\"] = \"localhost\" \n", | ||
|
@@ -74,7 +74,7 @@ | |
], | ||
"source": [ | ||
"client_config = StreamPipesClientConfig(\n", | ||
" credential_provider=StreamPipesApiKeyCredentials.from_env(username_env=\"USER\", api_key_env=\"API-KEY\"),\n", | ||
" credential_provider=StreamPipesApiKeyCredentials(),\n", | ||
" host_address=\"localhost\",\n", | ||
" port=80,\n", | ||
" https_disabled=True,\n", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ | |
"source": [ | ||
"import os\n", | ||
"\n", | ||
"os.environ[\"USER\"] = \"[email protected]\"\n", | ||
"os.environ[\"API-KEY\"] = \"XXX\"\n", | ||
"os.environ[\"SP_USERNAME\"] = \"[email protected]\"\n", | ||
"os.environ[\"SP_API_KEY\"] = \"XXX\"\n", | ||
"\n", | ||
"# Use this if you work locally:\n", | ||
"os.environ[\"BROKER-HOST\"] = \"localhost\" \n", | ||
|
@@ -63,7 +63,7 @@ | |
], | ||
"source": [ | ||
"client_config = StreamPipesClientConfig(\n", | ||
" credential_provider=StreamPipesApiKeyCredentials.from_env(username_env=\"USER\", api_key_env=\"API-KEY\"),\n", | ||
" credential_provider=StreamPipesApiKeyCredentials(),\n", | ||
" host_address=\"localhost\",\n", | ||
" port=80,\n", | ||
" https_disabled=True,\n", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
"StreamPipesApiKeyCredentials", | ||
] | ||
|
||
from typing_extensions import deprecated | ||
|
||
|
||
class CredentialProvider(ABC): | ||
"""Abstract implementation of a credential provider. | ||
|
@@ -81,22 +83,36 @@ class StreamPipesApiKeyCredentials(CredentialProvider): | |
The required token can be generated via the StreamPipes UI (see the description on our [start-page](../../../). | ||
Both parameters can either be passed as arguments or remain unset. | ||
If they are not passed, they are retrieved from environment variables: | ||
* `SP_USERNAME` is expected to contain the username | ||
* `SP_API_KEY` is expected to contain the API key | ||
Parameters | ||
---------- | ||
username: str | ||
The username to which the API token is granted, e.g., `[email protected]`. | ||
api_key: str | ||
The StreamPipes API key as it is displayed in the UI. | ||
username: Optional[str] | ||
The username to which the API token is granted, e.g., `[email protected]`.<br> | ||
If not passed, the username is retrieved from environment variable `SP_USERNAME`. | ||
api_key: Optional[str] | ||
The StreamPipes API key as it is displayed in the UI.<br> | ||
If not passed, the api key is retrieved from environment variable `SP_API_KEY` | ||
Examples | ||
-------- | ||
see [StreamPipesClient][streampipes.client.StreamPipesClient] | ||
""" | ||
|
||
_ENV_KEY_API = "SP_API_KEY" | ||
_ENV_KEY_USERNAME = "SP_USERNAME" | ||
|
||
@classmethod | ||
@deprecated("deprecated since 0.93.0; please use the class constructor instead.") | ||
def from_env(cls, username_env: str, api_key_env: str) -> StreamPipesApiKeyCredentials: | ||
"""Returns an api key provider parameterized via environment variables. | ||
"""DEPRECATED - use the class constructor instead | ||
Returns an api key provider parameterized via environment variables. | ||
Parameters | ||
---------- | ||
|
@@ -123,19 +139,60 @@ def from_env(cls, username_env: str, api_key_env: str) -> StreamPipesApiKeyCrede | |
raise KeyError( | ||
f"Ups, the following environment variables have not been found: " | ||
f"{'`' + username_env + '`,' if username is None else ''}" | ||
f"{'`' + api_key_env +'`' if api_key is None else ''}. " # noqa: W291 | ||
f"{'`' + api_key_env + '`' if api_key is None else ''}. " # noqa: W291 | ||
"Please check them to be properly set." | ||
) | ||
|
||
return cls(username=username, api_key=api_key) | ||
|
||
def __init__( | ||
self, | ||
username: str, | ||
api_key: str, | ||
username: Optional[str] = None, | ||
api_key: Optional[str] = None, | ||
): | ||
self.username = username | ||
self.api_key = api_key | ||
# if both parameters are passed we can add them directly to the instance | ||
if all({username, api_key}): | ||
self.username = username | ||
self.api_key = api_key | ||
|
||
# otherwise we need to check if environment variables are properly set | ||
else: | ||
retrieved_api_key = os.environ.get(self._ENV_KEY_API, None) | ||
retrieved_user_name = os.environ.get(self._ENV_KEY_USERNAME, None) | ||
|
||
self.username = retrieved_user_name | ||
self.api_key = retrieved_api_key | ||
|
||
if username: | ||
self.username = username | ||
|
||
if retrieved_api_key is None: | ||
raise AttributeError( | ||
"API key not found in the environment variables - please provide the API key " | ||
"via the parameter `api_key` or ensure that it is passed to " | ||
f"the environment variable `{self._ENV_KEY_API}`." | ||
) | ||
self.api_key = retrieved_api_key | ||
|
||
if api_key: | ||
self.api_key = api_key | ||
|
||
if retrieved_user_name is None: | ||
raise AttributeError( | ||
"Username not found - please provide the username " | ||
"via the parameter `username` or ensure that it is passed to " | ||
f"the environment variable `{self._ENV_KEY_USERNAME}`." | ||
) | ||
self.username = retrieved_user_name | ||
|
||
if not all({self.username, self.api_key}): | ||
if None in {retrieved_user_name, retrieved_api_key}: | ||
raise AttributeError( | ||
"Both parameters not found - please provide both api key and username " | ||
"either via the parameters (`api_key` and `username`) or via " | ||
f"the corresponding environment variables (`{self._ENV_KEY_API}` and " | ||
f"`{self._ENV_KEY_USERNAME}`)." | ||
) | ||
|
||
@property | ||
def _authentication_headers(self) -> Dict[str, str]: | ||
|
@@ -146,7 +203,11 @@ def _authentication_headers(self) -> Dict[str, str]: | |
Dictionary with authentication headers as string key-value pairs. | ||
""" | ||
|
||
user: str = self.username # type: ignore # mypy mistakenly detects this attribute as optional | ||
token: str = self.api_key # type: ignore # mypy mistakenly detects this attribute as optional | ||
|
||
return { | ||
"X-API-User": self.username, | ||
"X-API-Key": self.api_key, | ||
"X-API-User": user, | ||
"X-API-Key": token, | ||
} |
Oops, something went wrong.