Skip to content

Commit

Permalink
fix(IAM Identity): update service after recent API changes (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Byrne <[email protected]>
  • Loading branch information
padamstx and Daniel Byrne authored Mar 11, 2021
1 parent dc35878 commit 0b475a2
Show file tree
Hide file tree
Showing 57 changed files with 1,241 additions and 79 deletions.
14 changes: 2 additions & 12 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json|^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-02-24T21:17:07Z",
"generated_at": "2021-03-11T14:50:00Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -249,19 +249,9 @@
"type": "Hex High Entropy String",
"verified_result": null
}
],
"modules/user-management/src/test/java/com/ibm/cloud/platform_services/user_management/v1/UserManagementIT.java": [
{
"hashed_secret": "2fd0f58e94ad6ad73205d72f2bd0daa099b62500",
"is_secret": false,
"is_verified": false,
"line_number": 67,
"type": "Hex High Entropy String",
"verified_result": null
}
]
},
"version": "0.13.1+ibm.29.dss",
"version": "0.13.1+ibm.31.dss",
"word_list": {
"file": null,
"hash": null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020.
* (C) Copyright IBM Corp. 2020, 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -18,12 +18,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ibm.cloud.platform_services.iam_identity.v1.model.AccountSettingsResponse;
import com.ibm.cloud.platform_services.iam_identity.v1.model.ApiKey;
import com.ibm.cloud.platform_services.iam_identity.v1.model.ApiKeyList;
import com.ibm.cloud.platform_services.iam_identity.v1.model.CreateApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.CreateServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.DeleteApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.DeleteServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetAccountSettingsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetApiKeysDetailsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetServiceIdOptions;
Expand All @@ -35,6 +37,7 @@
import com.ibm.cloud.platform_services.iam_identity.v1.model.ServiceIdList;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UnlockApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UnlockServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateAccountSettingsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateServiceIdOptions;
import com.ibm.cloud.sdk.core.http.Response;
Expand Down Expand Up @@ -76,6 +79,7 @@ protected IamIdentityExamples() {
private static String apikeyEtag;
private static String svcId;
private static String svcIdEtag;
private static String accountSettingsEtag;

static {
System.setProperty("IBM_CREDENTIALS_FILE", "../../iam_identity.env");
Expand Down Expand Up @@ -319,5 +323,44 @@ public static void main(String[] args) throws Exception {
logger.error(String.format("Service returned status code %s: %s\nError details: %s",
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}

try {
// begin-getAccountSettings
GetAccountSettingsOptions getAccountSettingsOptions = new GetAccountSettingsOptions.Builder()
.accountId(accountId)
.build();

Response<AccountSettingsResponse> response = service.getAccountSettings(getAccountSettingsOptions).execute();
AccountSettingsResponse accountSettingsResponse = response.getResult();

accountSettingsEtag = response.getHeaders().values("Etag").get(0);
System.out.println(accountSettingsResponse);
// end-getAccountSettings
} catch (ServiceResponseException e) {
logger.error(String.format("Service returned status code %s: %s\nError details: %s",
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}

try {
// begin-updateAccountSettings
UpdateAccountSettingsOptions updateAccountSettingsOptions = new UpdateAccountSettingsOptions.Builder()
.ifMatch(accountSettingsEtag)
.accountId(accountId)
.sessionExpirationInSeconds("86400")
.sessionInvalidationInSeconds("7200")
.restrictCreatePlatformApikey("NOT_RESTRICTED")
.restrictCreateServiceId("NOT_RESTRICTED")
.mfa("NONE")
.build();

Response<AccountSettingsResponse> response = service.updateAccountSettings(updateAccountSettingsOptions).execute();
AccountSettingsResponse accountSettingsResponse = response.getResult();

System.out.println(accountSettingsResponse);
// end-updateAccountSettings
} catch (ServiceResponseException e) {
logger.error(String.format("Service returned status code %s: %s\nError details: %s",
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2020.
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -12,19 +12,21 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-e6cfc86e-20210308-084627
*/

package com.ibm.cloud.platform_services.iam_identity.v1;

import com.google.gson.JsonObject;
import com.ibm.cloud.platform_services.common.SdkCommon;
import com.ibm.cloud.platform_services.iam_identity.v1.model.AccountSettingsResponse;
import com.ibm.cloud.platform_services.iam_identity.v1.model.ApiKey;
import com.ibm.cloud.platform_services.iam_identity.v1.model.ApiKeyList;
import com.ibm.cloud.platform_services.iam_identity.v1.model.CreateApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.CreateServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.DeleteApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.DeleteServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetAccountSettingsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetApiKeysDetailsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.GetServiceIdOptions;
Expand All @@ -36,6 +38,7 @@
import com.ibm.cloud.platform_services.iam_identity.v1.model.ServiceIdList;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UnlockApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UnlockServiceIdOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateAccountSettingsOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateApiKeyOptions;
import com.ibm.cloud.platform_services.iam_identity.v1.model.UpdateServiceIdOptions;
import com.ibm.cloud.sdk.core.http.RequestBuilder;
Expand All @@ -50,7 +53,7 @@
import java.util.Map.Entry;

/**
* The IAM Identity Service API allows for the management of Identities (Service IDs, ApiKeys).
* The IAM Identity Service API allows for the management of Account Settings and Identities (Service IDs, ApiKeys).
*
* @version v1
*/
Expand Down Expand Up @@ -622,4 +625,77 @@ public ServiceCall<Void> unlockServiceId(UnlockServiceIdOptions unlockServiceIdO
return createServiceCall(builder.build(), responseConverter);
}

/**
* Get account configurations.
*
* Returns the details of an account's configuration.
*
* @param getAccountSettingsOptions the {@link GetAccountSettingsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AccountSettingsResponse}
*/
public ServiceCall<AccountSettingsResponse> getAccountSettings(GetAccountSettingsOptions getAccountSettingsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getAccountSettingsOptions,
"getAccountSettingsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("account_id", getAccountSettingsOptions.accountId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/accounts/{account_id}/settings/identity", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("iam_identity", "v1", "getAccountSettings");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getAccountSettingsOptions.includeHistory() != null) {
builder.query("include_history", String.valueOf(getAccountSettingsOptions.includeHistory()));
}
ResponseConverter<AccountSettingsResponse> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AccountSettingsResponse>() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}

/**
* Update account configurations.
*
* Allows a user to configure settings on their account with regards to MFA, session lifetimes, access control for
* creating new identities, and enforcing IP restrictions on token creation.
*
* @param updateAccountSettingsOptions the {@link UpdateAccountSettingsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AccountSettingsResponse}
*/
public ServiceCall<AccountSettingsResponse> updateAccountSettings(UpdateAccountSettingsOptions updateAccountSettingsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateAccountSettingsOptions,
"updateAccountSettingsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("account_id", updateAccountSettingsOptions.accountId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/accounts/{account_id}/settings/identity", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("iam_identity", "v1", "updateAccountSettings");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.header("If-Match", updateAccountSettingsOptions.ifMatch());
final JsonObject contentJson = new JsonObject();
if (updateAccountSettingsOptions.restrictCreateServiceId() != null) {
contentJson.addProperty("restrict_create_service_id", updateAccountSettingsOptions.restrictCreateServiceId());
}
if (updateAccountSettingsOptions.restrictCreatePlatformApikey() != null) {
contentJson.addProperty("restrict_create_platform_apikey", updateAccountSettingsOptions.restrictCreatePlatformApikey());
}
if (updateAccountSettingsOptions.allowedIpAddresses() != null) {
contentJson.addProperty("allowed_ip_addresses", updateAccountSettingsOptions.allowedIpAddresses());
}
if (updateAccountSettingsOptions.mfa() != null) {
contentJson.addProperty("mfa", updateAccountSettingsOptions.mfa());
}
if (updateAccountSettingsOptions.sessionExpirationInSeconds() != null) {
contentJson.addProperty("session_expiration_in_seconds", updateAccountSettingsOptions.sessionExpirationInSeconds());
}
if (updateAccountSettingsOptions.sessionInvalidationInSeconds() != null) {
contentJson.addProperty("session_invalidation_in_seconds", updateAccountSettingsOptions.sessionInvalidationInSeconds());
}
builder.bodyJson(contentJson);
ResponseConverter<AccountSettingsResponse> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AccountSettingsResponse>() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}

}
Loading

0 comments on commit 0b475a2

Please sign in to comment.