/// <summary> /// Get API key details asynchronously. Returns currently used key for empty argument. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetApiKeyAsync(string)"/> method. /// <code> /// try /// { /// var key = awaut accountApi.GetApiKeyAsync(); /// return key; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> GetApiKeyAsync(string apiKeyId = null) { try { return(!string.IsNullOrEmpty(apiKeyId) ? ApiKey.Map(await DeveloperApi.GetApiKeyAsync(apiKeyId)) : ApiKey.Map(await DeveloperApi.GetMyApiKeyAsync())); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Get API key details. Returns currently used key for empty argument. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetApiKey(string)"/> method. /// <code> /// try /// { /// var key = accountApi.GetApiKey(); /// return key; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <returns><see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public ApiKey GetApiKey(string apiKeyId = null) { try { return(!string.IsNullOrEmpty(apiKeyId) ? ApiKey.Map(DeveloperApi.GetApiKey(apiKeyId)) : ApiKey.Map(DeveloperApi.GetMyApiKey())); } catch (iam.Client.ApiException e) { return(HandleNotFound <ApiKey, iam.Client.ApiException>(e)); } }
/// <summary> /// Update API key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.UpdateApiKeyAsync(string, ApiKey)"/> method. /// <code> /// try /// { /// var key = await accountApi.GetApiKeyAsync() /// key.Name = "updated api key"; /// var updatedApiKey = await accountApi.UpdateApiKeyAsync(key.Id, key); /// return updatedApiKey; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <param name="key"><see cref="ApiKey"/></param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> UpdateApiKeyAsync(string apiKeyId, ApiKey key) { try { var req = key.CreatePutRequest(); return(ApiKey.Map(await DeveloperApi.UpdateApiKeyAsync(apiKeyId, req))); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Create new Api key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.AddApiKeyAsync(ApiKey)"/> method. /// <code> /// try /// { /// var key = new ApiKey /// { /// Name = "example api key", /// }; /// var newKey = await accountApi.AddApiKeyAsync(key); /// return newKey; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="key"><see cref="ApiKey"/></param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> AddApiKeyAsync(ApiKey key) { try { var keyBody = key.CreatePostRequest(); return(ApiKey.Map(await DeveloperApi.CreateApiKeyAsync(keyBody))); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }