Skip to content

Commit

Permalink
feat(IAM Policy Management): re-gen service after fix the template me…
Browse files Browse the repository at this point in the history
…tadata as part of policies (#213)

Signed-off-by: Rajesh K Pirati <[email protected]>
  • Loading branch information
Rajesh-Pirati authored Sep 25, 2023
1 parent eda33bf commit 4984f85
Show file tree
Hide file tree
Showing 32 changed files with 903 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ListV2PoliciesOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2Policy;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicySubjectAttribute;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicyTemplateMetaData;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicyResourceAttribute;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicyResourceTag;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.RuleAttribute;
Expand All @@ -52,8 +53,11 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ReplaceV2PolicyOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.Roles;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyAssignment;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyAssignmentResourcePolicy;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyAssignmentResources;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplate;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateMetaData;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateVersionsCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.TemplatePolicy;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.CreatePolicyTemplateOptions;
Expand All @@ -65,6 +69,7 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.DeletePolicyTemplateVersionOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.GetPolicyTemplateVersionOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ListPolicyTemplateVersionsOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.AssignmentResourceCreated;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.CommitPolicyTemplateOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateAssignmentCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.GetPolicyAssignmentOptions;
Expand Down Expand Up @@ -112,6 +117,7 @@ protected IamPolicyManagementExamples() { }
private static String exampleTemplateEtag = null;
private static String exampleTemplateVersion = null;
private static String exampleAssignmentId = null;
private static String exampleAssignmentPolicyId = null;

static {
System.setProperty("IBM_CREDENTIALS_FILE", "../../iam_policy_management.env");
Expand Down Expand Up @@ -196,8 +202,8 @@ public static void main(String[] args) throws Exception {
.policyId(examplePolicyId)
.build();

Response<Policy> response = service.getPolicy(options).execute();
Policy policy = response.getResult();
Response<PolicyTemplateMetaData> response = service.getPolicy(options).execute();
PolicyTemplateMetaData policy = response.getResult();

System.out.println(policy);

Expand Down Expand Up @@ -441,8 +447,8 @@ public static void main(String[] args) throws Exception {
.id(exampleV2PolicyId)
.build();

Response<V2Policy> response = service.getV2Policy(options).execute();
V2Policy policy = response.getResult();
Response<V2PolicyTemplateMetaData> response = service.getV2Policy(options).execute();
V2PolicyTemplateMetaData policy = response.getResult();

System.out.println(policy);

Expand Down Expand Up @@ -868,7 +874,7 @@ public static void main(String[] args) throws Exception {
System.out.println("listPolicyTemplateVersions() result:");
// begin-list_policy_template_versions
ListPolicyTemplateVersionsOptions listPolicyTemplateVersionsOptions = new ListPolicyTemplateVersionsOptions.Builder()
.policyTemplateId(exampleAccountId)
.policyTemplateId(exampleTemplateId)
.build();

Response<PolicyTemplateVersionsCollection> response = service.listPolicyTemplateVersions(listPolicyTemplateVersionsOptions).execute();
Expand Down Expand Up @@ -906,7 +912,6 @@ public static void main(String[] args) throws Exception {
CommitPolicyTemplateOptions commitPolicyTemplateOptions = new CommitPolicyTemplateOptions.Builder()
.policyTemplateId(exampleTemplateId)
.version(exampleTemplateVersion)
.ifMatch(exampleTemplateEtag)
.build();

Response<Void> response = service.commitPolicyTemplate(commitPolicyTemplateOptions).execute();
Expand Down Expand Up @@ -945,6 +950,10 @@ public static void main(String[] args) throws Exception {

Response<PolicyAssignment> response = service.getPolicyAssignment(getPolicyAssignmentOptions).execute();
PolicyAssignment policyAssignmentRecord = response.getResult();
PolicyAssignmentResources resource = policyAssignmentRecord.getResources().get(0);
PolicyAssignmentResourcePolicy policy = resource.getPolicy();
AssignmentResourceCreated resourceCreated = policy.getResourceCreated();
exampleAssignmentPolicyId = resourceCreated.getId();

System.out.println(policyAssignmentRecord);
// end-get_policy_assignment
Expand All @@ -953,6 +962,25 @@ public static void main(String[] args) throws Exception {
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}

try {
System.out.println("getTemplateMetaDataV2AccessPolicy() result:");
// begin-get_v2_policy

GetV2PolicyOptions options = new GetV2PolicyOptions.Builder()
.id(exampleAssignmentPolicyId)
.build();

Response<V2PolicyTemplateMetaData> response = service.getV2Policy(options).execute();
V2PolicyTemplateMetaData policy = response.getResult();

System.out.println(policy.getTemplate());

// end-get_v2_policy
} 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-delete_policy_template_version
DeletePolicyTemplateVersionOptions deletePolicyTemplateVersionOptions = new DeletePolicyTemplateVersionOptions.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.65.0-79fc0b8f-20230209-215651
* IBM OpenAPI SDK Code Generator Version: 3.79.0-2eb6af3d-20230905-174838
*/

package com.ibm.cloud.platform_services.iam_policy_management.v1;
Expand Down Expand Up @@ -49,6 +49,7 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplate;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateAssignmentCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateMetaData;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.PolicyTemplateVersionsCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ReplacePolicyOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ReplacePolicyTemplateOptions;
Expand All @@ -58,6 +59,7 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.UpdatePolicyStateOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2Policy;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicyCollection;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.V2PolicyTemplateMetaData;
import com.ibm.cloud.sdk.core.http.RequestBuilder;
import com.ibm.cloud.sdk.core.http.ResponseConverter;
import com.ibm.cloud.sdk.core.http.ServiceCall;
Expand Down Expand Up @@ -330,9 +332,9 @@ public ServiceCall<Policy> replacePolicy(ReplacePolicyOptions replacePolicyOptio
* Retrieve a policy by providing a policy ID.
*
* @param getPolicyOptions the {@link GetPolicyOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Policy}
* @return a {@link ServiceCall} with a result of type {@link PolicyTemplateMetaData}
*/
public ServiceCall<Policy> getPolicy(GetPolicyOptions getPolicyOptions) {
public ServiceCall<PolicyTemplateMetaData> getPolicy(GetPolicyOptions getPolicyOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getPolicyOptions,
"getPolicyOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
Expand All @@ -343,8 +345,8 @@ public ServiceCall<Policy> getPolicy(GetPolicyOptions getPolicyOptions) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Policy> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Policy>() { }.getType());
ResponseConverter<PolicyTemplateMetaData> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<PolicyTemplateMetaData>() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}

Expand Down Expand Up @@ -845,9 +847,9 @@ public ServiceCall<V2Policy> replaceV2Policy(ReplaceV2PolicyOptions replaceV2Pol
* Retrieve a policy by providing a policy ID.
*
* @param getV2PolicyOptions the {@link GetV2PolicyOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link V2Policy}
* @return a {@link ServiceCall} with a result of type {@link V2PolicyTemplateMetaData}
*/
public ServiceCall<V2Policy> getV2Policy(GetV2PolicyOptions getV2PolicyOptions) {
public ServiceCall<V2PolicyTemplateMetaData> getV2Policy(GetV2PolicyOptions getV2PolicyOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getV2PolicyOptions,
"getV2PolicyOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
Expand All @@ -861,8 +863,8 @@ public ServiceCall<V2Policy> getV2Policy(GetV2PolicyOptions getV2PolicyOptions)
if (getV2PolicyOptions.format() != null) {
builder.query("format", String.valueOf(getV2PolicyOptions.format()));
}
ResponseConverter<V2Policy> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<V2Policy>() { }.getType());
ResponseConverter<V2PolicyTemplateMetaData> responseConverter =
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<V2PolicyTemplateMetaData>() { }.getType());
return createServiceCall(builder.build(), responseConverter);
}

Expand Down Expand Up @@ -1026,6 +1028,9 @@ public ServiceCall<PolicyTemplate> createPolicyTemplateVersion(CreatePolicyTempl
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("policy", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createPolicyTemplateVersionOptions.policy()));
if (createPolicyTemplateVersionOptions.name() != null) {
contentJson.addProperty("name", createPolicyTemplateVersionOptions.name());
}
if (createPolicyTemplateVersionOptions.description() != null) {
contentJson.addProperty("description", createPolicyTemplateVersionOptions.description());
}
Expand Down Expand Up @@ -1085,6 +1090,9 @@ public ServiceCall<PolicyTemplate> replacePolicyTemplate(ReplacePolicyTemplateOp
builder.header("If-Match", replacePolicyTemplateOptions.ifMatch());
final JsonObject contentJson = new JsonObject();
contentJson.add("policy", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(replacePolicyTemplateOptions.policy()));
if (replacePolicyTemplateOptions.name() != null) {
contentJson.addProperty("name", replacePolicyTemplateOptions.name());
}
if (replacePolicyTemplateOptions.description() != null) {
contentJson.addProperty("description", replacePolicyTemplateOptions.description());
}
Expand Down Expand Up @@ -1167,7 +1175,6 @@ public ServiceCall<Void> commitPolicyTemplate(CommitPolicyTemplateOptions commit
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("If-Match", commitPolicyTemplateOptions.ifMatch());
ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
return createServiceCall(builder.build(), responseConverter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public class CommitPolicyTemplateOptions extends GenericModel {

protected String policyTemplateId;
protected String version;
protected String ifMatch;

/**
* Builder.
*/
public static class Builder {
private String policyTemplateId;
private String version;
private String ifMatch;

/**
* Instantiates a new Builder from an existing CommitPolicyTemplateOptions instance.
Expand All @@ -39,7 +37,6 @@ public static class Builder {
private Builder(CommitPolicyTemplateOptions commitPolicyTemplateOptions) {
this.policyTemplateId = commitPolicyTemplateOptions.policyTemplateId;
this.version = commitPolicyTemplateOptions.version;
this.ifMatch = commitPolicyTemplateOptions.ifMatch;
}

/**
Expand All @@ -53,12 +50,10 @@ public Builder() {
*
* @param policyTemplateId the policyTemplateId
* @param version the version
* @param ifMatch the ifMatch
*/
public Builder(String policyTemplateId, String version, String ifMatch) {
public Builder(String policyTemplateId, String version) {
this.policyTemplateId = policyTemplateId;
this.version = version;
this.ifMatch = ifMatch;
}

/**
Expand Down Expand Up @@ -91,17 +86,6 @@ public Builder version(String version) {
this.version = version;
return this;
}

/**
* Set the ifMatch.
*
* @param ifMatch the ifMatch
* @return the CommitPolicyTemplateOptions builder
*/
public Builder ifMatch(String ifMatch) {
this.ifMatch = ifMatch;
return this;
}
}

protected CommitPolicyTemplateOptions() { }
Expand All @@ -111,11 +95,8 @@ protected CommitPolicyTemplateOptions(Builder builder) {
"policyTemplateId cannot be empty");
com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.version,
"version cannot be empty");
com.ibm.cloud.sdk.core.util.Validator.notNull(builder.ifMatch,
"ifMatch cannot be null");
policyTemplateId = builder.policyTemplateId;
version = builder.version;
ifMatch = builder.ifMatch;
}

/**
Expand Down Expand Up @@ -148,18 +129,5 @@ public String policyTemplateId() {
public String version() {
return version;
}

/**
* Gets the ifMatch.
*
* The revision number for updating a policy template version and must match the ETag value of the existing policy
* template version. The Etag can be retrieved using the GET
* /v1/policy_templates/{policy_template_id}/versions/{version} API and looking at the ETag response header.
*
* @return the ifMatch
*/
public String ifMatch() {
return ifMatch;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class CreatePolicyTemplateVersionOptions extends GenericModel {

protected String policyTemplateId;
protected TemplatePolicy policy;
protected String name;
protected String description;
protected Boolean committed;

Expand All @@ -30,6 +31,7 @@ public class CreatePolicyTemplateVersionOptions extends GenericModel {
public static class Builder {
private String policyTemplateId;
private TemplatePolicy policy;
private String name;
private String description;
private Boolean committed;

Expand All @@ -41,6 +43,7 @@ public static class Builder {
private Builder(CreatePolicyTemplateVersionOptions createPolicyTemplateVersionOptions) {
this.policyTemplateId = createPolicyTemplateVersionOptions.policyTemplateId;
this.policy = createPolicyTemplateVersionOptions.policy;
this.name = createPolicyTemplateVersionOptions.name;
this.description = createPolicyTemplateVersionOptions.description;
this.committed = createPolicyTemplateVersionOptions.committed;
}
Expand Down Expand Up @@ -93,6 +96,17 @@ public Builder policy(TemplatePolicy policy) {
return this;
}

/**
* Set the name.
*
* @param name the name
* @return the CreatePolicyTemplateVersionOptions builder
*/
public Builder name(String name) {
this.name = name;
return this;
}

/**
* Set the description.
*
Expand Down Expand Up @@ -125,6 +139,7 @@ protected CreatePolicyTemplateVersionOptions(Builder builder) {
"policy cannot be null");
policyTemplateId = builder.policyTemplateId;
policy = builder.policy;
name = builder.name;
description = builder.description;
committed = builder.committed;
}
Expand Down Expand Up @@ -160,6 +175,18 @@ public TemplatePolicy policy() {
return policy;
}

/**
* Gets the name.
*
* Required field when creating a new template. Otherwise this field is optional. If the field is included it will
* change the name value for all existing versions of the template.
*
* @return the name
*/
public String name() {
return name;
}

/**
* Gets the description.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public interface State {
@SerializedName("last_modified_by_id")
protected String lastModifiedById;
protected String state;
protected TemplateMetadata template;

protected Policy() { }

Expand Down Expand Up @@ -184,16 +183,5 @@ public String getLastModifiedById() {
public String getState() {
return state;
}

/**
* Gets the template.
*
* Origin Template information.
*
* @return the template
*/
public TemplateMetadata getTemplate() {
return template;
}
}

Loading

0 comments on commit 4984f85

Please sign in to comment.