Ejemplo n.º 1
0
    def Run(self, args):
        """Run 'service-management convert-config'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The response from the ConvertConfig API call.

    Raises:
      IOError: An IOError is returned if the input file cannot be read, or
          the output file cannot be written to.
    """
        log.warn('This command is deprecated and will be removed soon.')

        messages = services_util.GetMessagesModule()
        client = services_util.GetClientInstance()

        # TODO(b/36057355): Add support for swagger file references later
        # This requires the API to support multiple files first. b/23353397
        try:
            with open(args.open_api_file) as f:
                open_api_spec = messages.OpenApiSpec(openApiFiles=[
                    messages.ConfigFile(filePath=os.path.basename(
                        args.open_api_file),
                                        contents=f.read())
                ])
        except IOError:
            raise calliope_exceptions.NewErrorFromCurrentException(
                exceptions.FileOpenError,
                'Cannot open {f} file'.format(f=args.open_api_file))

        request = messages.ConvertConfigRequest(openApiSpec=open_api_spec)

        converted_config = client.v1.ConvertConfig(request)
        diagnostics = converted_config.diagnostics
        if diagnostics:
            kind = messages.Diagnostic.KindValueValuesEnum
            for diagnostic in diagnostics:
                logger = log.error if diagnostic.kind == kind.ERROR else log.warning
                logger('{l}: {m}'.format(l=diagnostic.location,
                                         m=diagnostic.message))

        service = converted_config.serviceConfig
        if service:
            if args.output_file:
                try:
                    with open(args.output_file, 'w') as out:
                        out.write(encoding.MessageToJson(service))
                except IOError:
                    raise calliope_exceptions.NewErrorFromCurrentException(
                        exceptions.FileOpenError,
                        'Cannot open output file \'{f}\''.format(
                            f=args.output_file))
            else:
                return service
Ejemplo n.º 2
0
def GetForAccount(account=None):
    """Returns refresh token for given account.

  Args:
    account: str, usually email like string,
        if not provided current account is used.

  Returns:
    str: refresh token

  Raises:
    UnsupportedCredentialsType: if credentials are not user credentials.
  """

    try:
        creds = c_store.Load(account)
    except client.Error:
        raise calliope_exceptions.NewErrorFromCurrentException(
            LoadingCredentialsError)

    refresh_token = getattr(creds, 'refresh_token', None)

    if refresh_token is None:
        raise UnsupportedCredentialsType(
            'Credentials for account {0} do not support refresh tokens.'.
            format(account))

    return refresh_token
Ejemplo n.º 3
0
def GetForAccount(account=None):
    """Returns refresh token for given account.

  Args:
    account: str, usually email like string,
        if not provided current account is used.

  Returns:
    str: refresh token

  Raises:
    UnsupportedCredentialsType: if credentials are not user credentials.
  """

    use_google_auth = (
        not properties.VALUES.auth.disable_load_google_auth.GetBool())
    try:
        creds = c_store.Load(account, use_google_auth=use_google_auth)
    except (client.Error, google_auth_exceptions.GoogleAuthError):
        raise calliope_exceptions.NewErrorFromCurrentException(
            LoadingCredentialsError)

    refresh_token = getattr(creds, 'refresh_token', None)

    if refresh_token is None:
        raise UnsupportedCredentialsType(
            'Credentials for account {0} do not support refresh tokens.'.
            format(account))

    return refresh_token