public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonKeyManagementServiceConfig config = new AmazonKeyManagementServiceConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonKeyManagementServiceClient client = new AmazonKeyManagementServiceClient(creds, config);

            ListKeysResponse resp = new ListKeysResponse();

            do
            {
                ListKeysRequest req = new ListKeysRequest
                {
                    Marker = resp.NextMarker
                    ,
                    Limit = maxItems
                };

                resp = client.ListKeys(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Keys)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextMarker));
        }
示例#2
0
        internal ListKeysResponse ListKeys(ListKeysRequest request)
        {
            var marshaller   = new ListKeysRequestMarshaller();
            var unmarshaller = ListKeysResponseUnmarshaller.Instance;

            return(Invoke <ListKeysRequest, ListKeysResponse>(request, marshaller, unmarshaller));
        }
示例#3
0
        /// <summary>
        /// Returns an enumerator that iterates through all application keys associated with an account.
        /// </summary>
        /// <param name="request">The <see cref="ListKeysRequest"/> to send.</param>
        /// <param name="cacheTTL">An absolute cache expiration time to live (TTL) relative to now.</param>
        /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
        /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
        async Task <IEnumerable <KeyItem> > IStorageKeys.GetEnumerableAsync
            (ListKeysRequest request, TimeSpan cacheTTL)
        {
            var enumerable = new KeyEnumerable(_client, _logger, request, cacheTTL, _cancellationToken) as IEnumerable <KeyItem>;

            return(await Task.FromResult(enumerable).ConfigureAwait(false));
        }
示例#4
0
        /// <summary>
        /// Gets all keys associated with an account in alphabetical order by key name.
        /// </summary>
        /// <param name="request">The <see cref="ListBucketsRequest"/> to send.</param>
        /// <param name="cacheTTL">An absolute cache expiration time to live (TTL) relative to now.</param>
        /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
        /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
        async Task <IEnumerable <KeyItem> > IStorageKeys.GetAsync
            (ListKeysRequest request, TimeSpan cacheTTL)
        {
            var enumerable = await Keys.GetEnumerableAsync(request, cacheTTL);

            return(enumerable.OrderBy(x => x.KeyName).ToList());
        }
示例#5
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListKeysRequest request;

            try
            {
                request = new ListKeysRequest
                {
                    CompartmentId = CompartmentId,
                    Limit         = Limit,
                    Page          = Page,
                    OpcRequestId  = OpcRequestId,
                    SortBy        = SortBy,
                    SortOrder     = SortOrder
                };
                IEnumerable <ListKeysResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
示例#6
0
        /// <summary>
        /// Initiates the asynchronous execution of the ListKeys operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the ListKeys operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <ListKeysResponse> ListKeysAsync(ListKeysRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new ListKeysRequestMarshaller();
            var unmarshaller = ListKeysResponseUnmarshaller.Instance;

            return(InvokeAsync <ListKeysRequest, ListKeysResponse>(request, marshaller,
                                                                   unmarshaller, cancellationToken));
        }
示例#7
0
        public async Task GetEnumerableAsync()
        {
            var request    = new ListKeysRequest(Storage.AccountId);
            var enumerable = await Storage.Keys.GetEnumerableAsync(request);

            Assert.Equal(typeof(KeyEnumerable), enumerable.GetType());
            Assert.True(enumerable.ToList().Count() >= 1, "The actual count was less than one");
        }
示例#8
0
        /// <summary>
        /// 查询密钥列表
        /// </summary>
        public async Task <ListKeysResponse> ListKeysAsync(ListKeysRequest listKeysRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("version_id", listKeysRequest.VersionId.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/list-keys", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", listKeysRequest);
            HttpResponseMessage response = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <ListKeysResponse>(response));
        }
示例#9
0
        /// <summary>
        /// 列出账号下面状态为Enabled, Disabled 和 PendingImport 的CMK KeyId 列表
        /// </summary>
        /// <param name="req"><see cref="ListKeysRequest"/></param>
        /// <returns><see cref="ListKeysResponse"/></returns>
        public ListKeysResponse ListKeysSync(ListKeysRequest req)
        {
            JsonResponseModel <ListKeysResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "ListKeys");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <ListKeysResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
 /// <summary>
 /// Creates a new enumerable which will iterate over the responses received from the ListKeys operation. This enumerable
 /// will fetch more data from the server as needed.
 /// </summary>
 /// <param name="request">The request object containing the details to send</param>
 /// <param name="retryConfiguration">The configuration for retrying, may be null</param>
 /// <param name="cancellationToken">The cancellation token object</param>
 /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns>
 public IEnumerable <ListKeysResponse> ListKeysResponseEnumerator(ListKeysRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
 {
     return(new Common.Utils.ResponseEnumerable <ListKeysRequest, ListKeysResponse>(
                response => response.OpcNextPage,
                input =>
     {
         if (!string.IsNullOrEmpty(input))
         {
             request.Page = input;
         }
         return request;
     },
                request => client.ListKeys(request, retryConfiguration, cancellationToken)
                ));
 }
示例#11
0
        /// <summary>Snippet for ListKeysAsync</summary>
        public async Task ListKeysRequestObjectAsync()
        {
            // Snippet: ListKeysAsync(ListKeysRequest, CallSettings)
            // Create client
            RecaptchaEnterpriseServiceClient recaptchaEnterpriseServiceClient = await RecaptchaEnterpriseServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListKeysRequest request = new ListKeysRequest
            {
                ParentAsProjectName = ProjectName.FromProject("[PROJECT]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListKeysResponse, Key> response = recaptchaEnterpriseServiceClient.ListKeysAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Key item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListKeysResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Key item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int        pageSize   = 10;
            Page <Key> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Key item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
示例#12
0
        private static async Task ListKeys(KmsManagementClient kmsManagementClient, string compartmentId)
        {
            logger.Info("List Keys");

            ListKeysRequest listKeysRequest = new ListKeysRequest
            {
                CompartmentId = compartmentId
            };
            ListKeysResponse listKeysResponse = await kmsManagementClient.ListKeys(listKeysRequest);

            logger.Info("Retrieved keys");
            foreach (var key in listKeysResponse.Items)
            {
                logger.Info($"Key: {key.DisplayName}");
            }
        }
示例#13
0
        public static string GetKeyByKeyStatus(KmsClient kmsClient, string status)
        {
            var request = new ListKeysRequest
            {
                VersionId = "v1.0",
                Body      = new ListKeysRequestBody
                {
                    KeyState = status
                }
            };

            try
            {
                var resp = kmsClient.ListKeys(request);
                if (resp.Keys.Count != 0)
                {
                    return(resp.Keys[0]);
                }

                var req = new CreateKeyRequest
                {
                    VersionId = "v1.0",
                    Body      = new CreateKeyRequestBody()
                    {
                        KeyAlias = "0000"
                    }
                };
                var createKeyResponse = kmsClient.CreateKey(req);
                return(createKeyResponse.KeyInfo.KeyId);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }

            return(null);
        }
示例#14
0
        public static async Task Main()
        {
            var client   = new AmazonKeyManagementServiceClient();
            var request  = new ListKeysRequest();
            var response = new ListKeysResponse();

            do
            {
                response = await client.ListKeysAsync(request);

                response.Keys.ForEach(key =>
                {
                    Console.WriteLine($"ID: {key.KeyId}, {key.KeyArn}");
                });

                // Set the Marker property when response.Truncated is true
                // in order to get the next keys.
                request.Marker = response.NextMarker;
            }while (response.Truncated);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListKeysRequest request;

            try
            {
                request = new ListKeysRequest
                {
                    CompartmentId  = CompartmentId,
                    Limit          = Limit,
                    Page           = Page,
                    OpcRequestId   = OpcRequestId,
                    SortBy         = SortBy,
                    SortOrder      = SortOrder,
                    ProtectionMode = ProtectionMode,
                    Algorithm      = Algorithm,
                    Length         = Length,
                    CurveId        = CurveId
                };
                IEnumerable <ListKeysResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
示例#16
0
 /// <summary>
 /// List application keys associated with an account.
 /// </summary>
 /// <param name="request">The <see cref="ListKeysRequest"/> to send.</param>
 /// <param name="cacheTTL">An absolute cache expiration time to live (TTL) relative to now.</param>
 /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
 /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
 async Task <IApiResults <ListKeysResponse> > IStorageKeys.ListAsync
     (ListKeysRequest request, TimeSpan cacheTTL)
 {
     return(await _client.ListKeysAsync(request, cacheTTL, _cancellationToken));
 }
示例#17
0
        /// <summary>
        /// List application keys associated with an account.
        /// </summary>
        /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
        /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
        async Task <IApiResults <ListKeysResponse> > IStorageKeys.ListAsync()
        {
            var request = new ListKeysRequest(AccountId);

            return(await _client.ListKeysAsync(request, _cancellationToken));
        }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyEnumerable"/> class.
 /// </summary>
 public KeyEnumerable(IApiClient client, ILogger logger, ListKeysRequest request, TimeSpan cacheTTL, CancellationToken cancellationToken)
     : base(client, logger, cacheTTL, cancellationToken)
 {
     _request = request;
 }
示例#19
0
        /// <summary>
        /// Gets all keys associated with an account in alphabetical order by key name.
        /// </summary>
        /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception>
        /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception>
        async Task <IEnumerable <KeyItem> > IStorageKeys.GetAsync()
        {
            var request = new ListKeysRequest(AccountId);

            return(await Keys.GetAsync(request));
        }