<NME> dvid_credentials.py
<BEF> # @license
# Copyright 2021 Google Inc.
# 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.

"""Module implements function for authentication of layers based on DVID.
    Here tokens are fetched from local locations like env vars etc."""

from __future__ import absolute_import

import logging
import os

from . import credentials_provider
from .futures import run_on_new_thread


class TokenbasedDefaultCredentialsProvider(credentials_provider.CredentialsProvider):
    def __init__(self):
        super(TokenbasedDefaultCredentialsProvider, self).__init__()

        # Make sure logging is initialized.
        # Does nothing if logging has already been initialized.
        logging.basicConfig()

        self._credentials = {}

    def get_new(self):
        def func():
            self._credentials = {}
            try:
                TOKEN = os.environ['DVID_APPLICATION_CREDENTIALS']
            except KeyError:
                raise RuntimeError(
                    "DVID_APPLICATION_CREDENTIALS is not defined in your environment!")
            self._credentials['token'] = TOKEN
            return dict(tokenType=u'Bearer', accessToken=self._credentials['token'])

            return dict(tokenType=u'Bearer', accessToken=self._credentials['token'])

        return run_on_new_thread(func)
_global_tokenbased_application_default_credentials_provider = None


def get_tokenbased_application_default_credentials_provider():
    global _global_tokenbased_application_default_credentials_provider
    if _global_tokenbased_application_default_credentials_provider is None:
        _global_tokenbased_application_default_credentials_provider =\
             TokenbasedDefaultCredentialsProvider()
    return _global_tokenbased_application_default_credentials_provider
            TokenbasedDefaultCredentialsProvider(parameters)
    return _global_tokenbased_application_default_credentials_provider

<MSG> updated after review comments

<DFF> @@ -25,23 +25,24 @@ from .futures import run_on_new_thread
 
 
 class TokenbasedDefaultCredentialsProvider(credentials_provider.CredentialsProvider):
-    def __init__(self):
+    def __init__(self, _parameters):
         super(TokenbasedDefaultCredentialsProvider, self).__init__()
 
         # Make sure logging is initialized.
         # Does nothing if logging has already been initialized.
         logging.basicConfig()
-
+        self._parameters = _parameters
         self._credentials = {}
 
     def get_new(self):
         def func():
-            self._credentials = {}
             try:
-                TOKEN = os.environ['DVID_APPLICATION_CREDENTIALS']
+                credentials = os.environ['DVID_CREDENTIALS']
+                credentials = dict(item.split("=") for item in credentials.split(","))
+                TOKEN = credentials[self._parameters['dvidServer']]
             except KeyError:
                 raise RuntimeError(
-                    "DVID_APPLICATION_CREDENTIALS is not defined in your environment!")
+                    "DVID_CREDENTIALS is not defined in your environment!")
             self._credentials['token'] = TOKEN
             return dict(tokenType=u'Bearer', accessToken=self._credentials['token'])
 
@@ -51,9 +52,9 @@ class TokenbasedDefaultCredentialsProvider(credentials_provider.CredentialsProvi
 _global_tokenbased_application_default_credentials_provider = None
 
 
-def get_tokenbased_application_default_credentials_provider():
+def get_tokenbased_application_default_credentials_provider(_parameters):
     global _global_tokenbased_application_default_credentials_provider
     if _global_tokenbased_application_default_credentials_provider is None:
         _global_tokenbased_application_default_credentials_provider =\
-             TokenbasedDefaultCredentialsProvider()
+            TokenbasedDefaultCredentialsProvider(_parameters)
     return _global_tokenbased_application_default_credentials_provider

updated after review comments