Exemplo n.º 1
0
 def __init__(self):
   self._private_key = base64.b64decode(
       _TEST_CONFIG['auth_data']['p12_service_account']['private_key'])
   self._account = _TEST_CONFIG['auth_data']['p12_service_account']['account']
   self._project = _TEST_CONFIG['property_overrides'].get('project', None)
   self._orig_account = None
   self._credentials = auth_service_account.CredentialsFromP12Key(
       self._private_key, self._account)
Exemplo n.º 2
0
    def Run(self, args):
        """Create service account credentials."""

        file_content, is_json = _IsJsonFile(args.key_file)
        if is_json:
            if _UseGoogleAuth():
                cred = auth_service_account.CredentialsFromAdcDictGoogleAuth(
                    file_content)
            else:
                # TODO(b/161992086): Remove the flow of activating via oauth2client once
                # this legacy auth lib is deprecated. Leave this option for now so that
                # the users are able to fall back to the old flow of if any issues
                # related to google-auth comes up. The users can do this by setting
                # property auth/disable_activate_service_account_google_auth to True.
                cred = auth_service_account.CredentialsFromAdcDict(
                    file_content)
            if args.password_file or args.prompt_for_password:
                raise c_exc.InvalidArgumentException(
                    '--password-file',
                    'A .json service account key does not require a password.')
            account = cred.service_account_email
            if args.account and args.account != account:
                raise c_exc.InvalidArgumentException(
                    'ACCOUNT',
                    'The given account name does not match the account name in the key '
                    'file.  This argument can be omitted when using .json keys.'
                )
        else:
            account = args.account
            if not account:
                raise c_exc.RequiredArgumentException(
                    'ACCOUNT', 'An account is required when using .p12 keys')
            password = None
            if args.password_file:
                try:
                    password = files.ReadFileContents(
                        args.password_file).strip()
                except files.Error as e:
                    raise c_exc.UnknownArgumentException('--password-file', e)
            elif args.prompt_for_password:
                password = console_io.PromptPassword('Password: '******'Activated service account credentials for: [{0}]'.format(account))
Exemplo n.º 3
0
    def Run(self, args):
        """Create service account credentials."""

        file_content, is_json = _IsJsonFile(args.key_file)
        if is_json:
            cred = auth_service_account.CredentialsFromAdcDictGoogleAuth(
                file_content)
            if args.password_file or args.prompt_for_password:
                raise c_exc.InvalidArgumentException(
                    '--password-file',
                    'A .json service account key does not require a password.')
            account = cred.service_account_email
            if args.account and args.account != account:
                raise c_exc.InvalidArgumentException(
                    'ACCOUNT',
                    'The given account name does not match the account name in the key '
                    'file.  This argument can be omitted when using .json keys.'
                )
        else:
            account = args.account
            if not account:
                raise c_exc.RequiredArgumentException(
                    'ACCOUNT', 'An account is required when using .p12 keys')
            password = None
            if args.password_file:
                try:
                    password = files.ReadFileContents(
                        args.password_file).strip()
                except files.Error as e:
                    raise c_exc.UnknownArgumentException('--password-file', e)
            elif args.prompt_for_password:
                password = console_io.PromptPassword('Password: '******'Activated service account credentials for: [{0}]'.format(account))