diff --git a/neptune/__init__.py b/neptune/__init__.py index 69e518976..7743e36f8 100644 --- a/neptune/__init__.py +++ b/neptune/__init__.py @@ -18,6 +18,7 @@ import threading from neptune import envs +from neptune import constants from neptune.exceptions import MissingProjectQualifiedName, Uninitialized, InvalidNeptuneBackend from neptune.internal.backends.hosted_neptune_backend import HostedNeptuneBackend from neptune.internal.backends.offline_backend import OfflineBackend @@ -38,13 +39,12 @@ """Access Neptune as an anonymous user. You can pass this value as api_token during init() call, either by an environment variable or passing it directly """ -ANONYMOUS = 'ANONYMOUS' +ANONYMOUS = constants.ANONYMOUS """Anonymous user API token. You can pass this value as api_token during init() call, either by an environment variable or passing it directly """ -ANONYMOUS_API_TOKEN = 'eyJhcGlfYWRkcmVzcyI6Imh0dHBzOi8vdWkubmVwdHVuZS5haSIsImFwaV91cmwiOiJodHRwczovL3VpLm5lcHR1bmUuYW' \ - 'kiLCJhcGlfa2V5IjoiYjcwNmJjOGYtNzZmOS00YzJlLTkzOWQtNGJhMDM2ZjkzMmU0In0=' +ANONYMOUS_API_TOKEN = constants.ANONYMOUS_API_TOKEN def init(project_qualified_name=None, api_token=None, proxies=None, backend=None): diff --git a/neptune/constants.py b/neptune/constants.py new file mode 100644 index 000000000..dc8f9815d --- /dev/null +++ b/neptune/constants.py @@ -0,0 +1,22 @@ +# +# Copyright (c) 2020, Neptune Labs Sp. z o.o. +# +# Licensed 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. +# + +"""Constants used by Neptune""" + +ANONYMOUS = 'ANONYMOUS' + +ANONYMOUS_API_TOKEN = 'eyJhcGlfYWRkcmVzcyI6Imh0dHBzOi8vdWkubmVwdHVuZS5haSIsImFwaV91cmwiOiJodHRwczovL3VpLm5lcHR1bmUuYW' \ + 'kiLCJhcGlfa2V5IjoiYjcwNmJjOGYtNzZmOS00YzJlLTkzOWQtNGJhMDM2ZjkzMmU0In0=' diff --git a/neptune/internal/backends/credentials.py b/neptune/internal/backends/credentials.py index 05fd0a873..4bb9bca99 100644 --- a/neptune/internal/backends/credentials.py +++ b/neptune/internal/backends/credentials.py @@ -21,6 +21,7 @@ from neptune import envs from neptune.api_exceptions import InvalidApiKey +from neptune.constants import ANONYMOUS_API_TOKEN from neptune.exceptions import MissingApiToken _logger = logging.getLogger(__name__) @@ -63,6 +64,8 @@ class Credentials(object): def __init__(self, api_token=None): if api_token is None: api_token = os.getenv(envs.API_TOKEN_ENV_NAME) + elif api_token == ANONYMOUS_API_TOKEN: + pass # Do not warn about using public API token else: _logger.warning( "WARNING: It is not secure to place API token in your source code. " diff --git a/neptune/internal/backends/hosted_neptune_backend.py b/neptune/internal/backends/hosted_neptune_backend.py index b64982941..79d61d25c 100644 --- a/neptune/internal/backends/hosted_neptune_backend.py +++ b/neptune/internal/backends/hosted_neptune_backend.py @@ -53,7 +53,7 @@ from neptune.oauth import NeptuneAuthenticator from neptune.projects import Project from neptune.utils import is_float, with_api_exceptions_handler, update_session_proxies - +from neptune.constants import ANONYMOUS, ANONYMOUS_API_TOKEN _logger = logging.getLogger(__name__) @@ -62,7 +62,7 @@ class HostedNeptuneBackend(Backend): @with_api_exceptions_handler def __init__(self, api_token=None, proxies=None): - from neptune import ANONYMOUS, ANONYMOUS_API_TOKEN + if api_token == ANONYMOUS: api_token = ANONYMOUS_API_TOKEN