Пример #1
0
    def Run(self, args):
        parent = asset_utils.GetParentName(args.organization, args.project,
                                           args.folder)
        client = client_util.AssetExportClient(parent)
        operation = client.Export(args)

        log.ExportResource(parent, is_async=True, kind='root asset')
        log.status.Print(
            'Use [{} {}] to check the status of the operation.'.format(
                OPERATION_DESCRIBE_COMMAND, operation.name))
    def Run(self, args):
        parent = asset_utils.GetParentName(args.organization, args.project,
                                           args.folder)
        client = client_util.AssetExportClient(parent)
        operation = client.Export(args)

        prefix = self.ReleaseTrack().prefix
        if prefix:
            operation_describe_command = 'gcloud {} asset operations describe'.format(
                prefix)
        else:
            operation_describe_command = 'gcloud asset operations describe'
        log.ExportResource(parent, is_async=True, kind='root asset')
        log.status.Print(
            'Use [{} {}] to check the status of the operation.'.format(
                operation_describe_command, operation.name))
Пример #3
0
def MakeGetAssetsHistoryHttpRequests(args, api_version=DEFAULT_API_VERSION):
    """Manually make the get assets history request."""
    http_client = http.Http()
    query_params = [('assetNames', asset_name)
                    for asset_name in args.asset_names or []]
    query_params.extend([
        ('contentType', ContentTypeTranslation(args.content_type)),
        ('readTimeWindow.startTime', times.FormatDateTime(args.start_time))
    ])
    if args.IsSpecified('end_time'):
        query_params.extend([('readTimeWindow.endTime',
                              times.FormatDateTime(args.end_time))])
    parent = asset_utils.GetParentName(args.organization, args.project)
    url_base = '{0}/{1}/{2}:{3}'.format(BASE_URL, api_version, parent,
                                        'batchGetAssetsHistory')
    url_query = six.moves.urllib.parse.urlencode(query_params)
    url = '?'.join([url_base, url_query])
    response, raw_content = http_client.request(uri=url, headers=_HEADERS)

    content = core_encoding.Decode(raw_content)

    if response['status'] != '200':
        http_error = api_exceptions.HttpError(response, content, url)
        raise exceptions.HttpException(http_error)

    response_message_class = GetMessages(
        api_version).BatchGetAssetsHistoryResponse
    try:
        history_response = encoding.JsonToMessage(response_message_class,
                                                  content)
    except ValueError as e:
        err_msg = ('Failed receiving proper response from server, cannot'
                   'parse received assets. Error details: ' + str(e))
        raise MessageDecodeError(err_msg)

    for asset in history_response.assets:
        yield asset