def Run(self, args): """Revoke credentials and update active account.""" accounts = args.accounts or [] if type(accounts) is str: accounts = [accounts] available_accounts = c_store.AvailableAccounts() unknown_accounts = set(accounts) - set(available_accounts) if unknown_accounts: raise c_exc.UnknownArgumentException( 'accounts', ' '.join(unknown_accounts)) if args.all: accounts = available_accounts active_account = properties.VALUES.core.account.Get() if not accounts and active_account: accounts = [active_account] if not accounts: raise c_exc.InvalidArgumentException( 'accounts', 'No credentials available to revoke.') for account in accounts: if active_account == account: properties.PersistProperty(properties.VALUES.core.account, None) if not c_store.Revoke(account): log.warning( '[{}] already inactive (previously revoked?)'.format(account)) return accounts
def Run(self, args): """Revoke credentials and update active account.""" accounts = args.accounts or [] if isinstance(accounts, str): accounts = [accounts] available_accounts = c_store.AvailableAccounts() unknown_accounts = set(accounts) - set(available_accounts) if unknown_accounts: raise c_exc.UnknownArgumentException('accounts', ' '.join(unknown_accounts)) if args.all: accounts = available_accounts active_account = properties.VALUES.core.account.Get() if not accounts and active_account: accounts = [active_account] if not accounts: raise c_exc.InvalidArgumentException( 'accounts', 'No credentials available to revoke.') for account in accounts: if active_account == account: properties.PersistProperty(properties.VALUES.core.account, None) if not c_store.Revoke(account, use_google_auth=not args.use_oauth2client): if account.endswith('.gserviceaccount.com'): log.warning( '[{}] appears to be a service account. Service account tokens ' 'cannot be revoked, but they will expire automatically. To ' 'prevent use of the service account token earlier than the ' 'expiration, revoke the parent service account or service ' 'account key.'.format(account)) else: log.warning( '[{}] already inactive (previously revoked?)'.format( account)) return accounts
def Run(self, args): """Revoke credentials and update active account.""" accounts = args.accounts or [] if isinstance(accounts, str): accounts = [accounts] available_accounts = c_store.AvailableAccounts() unknown_accounts = set(accounts) - set(available_accounts) if unknown_accounts: raise c_exc.UnknownArgumentException( 'accounts', ' '.join(unknown_accounts)) if args.all: accounts = available_accounts active_account = properties.VALUES.core.account.Get() if not accounts and active_account: accounts = [active_account] if not accounts: raise c_exc.InvalidArgumentException( 'accounts', 'No credentials available to revoke.') for account in accounts: if active_account == account: properties.PersistProperty(properties.VALUES.core.account, None) # External account and external account user credentials cannot be # revoked. # Detect these type of credentials to show a more user friendly message # on revocation calls. # Note that impersonated external account credentials will appear like # service accounts. These will end with gserviceaccount.com and will be # handled the same way service account credentials are handled. try: creds = c_store.Load( account, prevent_refresh=True, use_google_auth=True) except creds_exceptions.Error: # Ignore all errors. These will be properly handled in the subsequent # Revoke call. creds = None if not c_store.Revoke(account): if account.endswith('.gserviceaccount.com'): log.warning( '[{}] appears to be a service account. Service account tokens ' 'cannot be revoked, but they will expire automatically. To ' 'prevent use of the service account token earlier than the ' 'expiration, delete or disable the parent service account.' .format(account)) elif c_creds.IsExternalAccountCredentials(creds): log.warning( '[{}] appears to be an external account. External account ' 'tokens cannot be revoked, but they will expire automatically.' .format(account)) elif c_creds.IsExternalAccountUserCredentials(creds): log.warning( '[{}] appears to be an external account user. External account ' 'user tokens cannot be revoked, but they will expire ' 'automatically.'.format(account)) else: log.warning( '[{}] already inactive (previously revoked?)'.format(account)) return accounts