Esempio n. 1
0
    def __init__(self, key: str = None, **kwargs: Dict) -> None:
        super().__init__(key=key, **kwargs)

        if key:
            os.environ[self._CREDENTIALS_ENV_NAME] = key

        google_application_credentials = os.getenv(self._CREDENTIALS_ENV_NAME)
        if not os.path.isfile(google_application_credentials):
            raise CredentialsError(
                "Please set environment variable "
                "'GOOGLE_APPLICATION_CREDENTIALS' or provider file path "
                "to Google service account key json file.")

        self._client = storage.Client()
Esempio n. 2
0
    def __init__(self, key: str, secret: str = None, salt: str = None,
                 **kwargs: Dict) -> None:
        super().__init__(key, secret, **kwargs)

        self.base_path = key
        self.salt = salt

        try:
            if not os.path.exists(key):
                os.makedirs(key)
        except PermissionError as err:
            raise CredentialsError(str(err))

        # Check if base path is a directory and not a file
        if not os.path.isdir(self.base_path):
            raise NotADirectoryError(
                "The base path '%s' is not a directory." % key)
Esempio n. 3
0
    def __init__(self, key: str = None, **kwargs: Dict) -> None:
        super().__init__(key=key, **kwargs)

        if key:
            os.environ[self._CREDENTIALS_ENV_NAME] = key
        else:
            logger.debug(
                'No key provided, attempting to authenticate with Google Metadata API'
            )

        google_application_credentials = os.getenv(self._CREDENTIALS_ENV_NAME)
        if google_application_credentials and not os.path.isfile(
                google_application_credentials):
            raise CredentialsError(
                "Please set environment variable "
                "'GOOGLE_APPLICATION_CREDENTIALS' or provider file path "
                "to Google service account key json file.")

        self._client = storage.Client()
Esempio n. 4
0
 def validate_credentials(self) -> None:
     try:
         for _ in self.client.list_buckets():
             break
     except (InvalidAccessKeyId, SignatureDoesNotMatch) as err:
         raise CredentialsError(str(err))
Esempio n. 5
0
 def validate_credentials(self) -> None:
     try:
         for _ in self.client.list_buckets():
             break
     except GoogleAuthError as err:
         raise CredentialsError(str(err))
 def validate_credentials(self) -> None:
     try:
         for _ in self.service.list_containers():
             break
     except AzureHttpError as err:
         raise CredentialsError(str(err))
Esempio n. 7
0
 def validate_credentials(self) -> None:
     try:
         self.session.client("sts").get_caller_identity()
     except ClientError as err:
         raise CredentialsError(str(err))
Esempio n. 8
0
 def validate_credentials(self) -> None:
     if not os.access(self.base_path, os.W_OK):
         raise CredentialsError("[Errno 13] Permission denied: '{}'".format(
             self.base_path))
Esempio n. 9
0
 def validate_credentials(self) -> None:
     try:
         self.conn.auth_token
     except Unauthorized as err:
         raise CredentialsError(str(err))