Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.TemplateRole;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.UpdateRoleAssignmentOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.ReplaceRoleTemplateOptions;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.RoleTemplateReferencesItem;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.TemplateControl;
import com.ibm.cloud.platform_services.iam_policy_management.v1.model.TemplateGrant;

import com.ibm.cloud.sdk.core.http.Response;
import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException;
Expand Down Expand Up @@ -197,6 +200,7 @@ protected IamPolicyManagementExamples() { }
private static String exampleRoleTemplateVersion = null;
private static String exampleRoleTemplateAssignmentId = null;
private static String exampleRoleTemplateAssignmentETag = null;
private static String exampleRolePolicyTemplateId = null;

static {
System.setProperty("IBM_CREDENTIALS_FILE", "../../iam_policy_management.env");
Expand Down Expand Up @@ -809,10 +813,10 @@ public static void main(String[] args) throws Exception {
Roles rolesModel = new Roles.Builder()
.roleId("crn:v1:bluemix:public:iam::::serviceRole:Writer")
.build();
Grant grantModel = new Grant.Builder()
TemplateGrant grantModel = new TemplateGrant.Builder()
.roles(java.util.Arrays.asList(rolesModel))
.build();
Control controlModel = new Control.Builder()
TemplateControl controlModel = new TemplateControl.Builder()
.grant(grantModel)
.build();
V2PolicySubjectAttribute subjectAttributeService = new V2PolicySubjectAttribute.Builder()
Expand Down Expand Up @@ -883,10 +887,10 @@ public static void main(String[] args) throws Exception {
Roles rolesModel = new Roles.Builder()
.roleId("crn:v1:bluemix:public:iam::::serviceRole:Reader")
.build();
Grant grantModel = new Grant.Builder()
TemplateGrant grantModel = new TemplateGrant.Builder()
.roles(java.util.Arrays.asList(rolesModel))
.build();
Control controlModel = new Control.Builder()
TemplateControl controlModel = new TemplateControl.Builder()
.grant(grantModel)
.build();
V2PolicySubjectAttribute subjectAttributeService = new V2PolicySubjectAttribute.Builder()
Expand Down Expand Up @@ -951,10 +955,10 @@ public static void main(String[] args) throws Exception {
Roles rolesModel = new Roles.Builder()
.roleId("crn:v1:bluemix:public:iam::::role:Viewer")
.build();
Grant grantModel = new Grant.Builder()
TemplateGrant grantModel = new TemplateGrant.Builder()
.roles(java.util.Arrays.asList(rolesModel))
.build();
Control controlModel = new Control.Builder()
TemplateControl controlModel = new TemplateControl.Builder()
.grant(grantModel)
.build();
V2PolicySubjectAttribute subjectAttributeService = new V2PolicySubjectAttribute.Builder()
Expand Down Expand Up @@ -1580,6 +1584,55 @@ public static void main(String[] args) throws Exception {
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}

try {
System.out.println("createRolePolicyTemplate() result:");
// begin-create_policy_template
V2PolicyResourceAttribute v2PolicyResourceAttributeModel = new V2PolicyResourceAttribute.Builder()
.key("serviceName")
.value("am-test-service")
.operator("stringEquals")
.build();
V2PolicyResource v2PolicyResourceModel = new V2PolicyResource.Builder()
.attributes(java.util.Arrays.asList(v2PolicyResourceAttributeModel))
.build();
Roles rolesModel = new Roles.Builder()
.roleId("crn:v1:bluemix:public:iam::::role:Viewer")
.build();
RoleTemplateReferencesItem roleTemplateReferencesModel = new RoleTemplateReferencesItem.Builder()
.id(exampleRoleTemplateId)
.version(exampleRoleTemplateVersion)
.build();
TemplateGrant grantModel = new TemplateGrant.Builder()
.roles(java.util.Arrays.asList(rolesModel))
.roleTemplateReferences(java.util.Arrays.asList(roleTemplateReferencesModel))
.build();
TemplateControl controlModel = new TemplateControl.Builder()
.grant(grantModel)
.build();
TemplatePolicy templatePolicyModel = new TemplatePolicy.Builder()
.type("access")
.resource(v2PolicyResourceModel)
.control(controlModel)
.build();
CreatePolicyTemplateOptions createPolicyTemplateOptions = new CreatePolicyTemplateOptions.Builder()
.name("SDKRolePTExamplesTest")
.accountId(exampleAccountId)
.policy(templatePolicyModel)
.build();

Response<PolicyTemplateLimitData> response = service.createPolicyTemplate(createPolicyTemplateOptions).execute();
PolicyTemplateLimitData policyTemplate = response.getResult();

exampleRolePolicyTemplateId = policyTemplate.getId();

System.out.println(policyTemplate);
// end-create_role_policy_template

} catch (ServiceResponseException e) {
logger.error(String.format("Service returned status code %s: %s%nError details: %s",
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
}

try {
System.out.println("getRoleTemplate() result:");
// begin-get_role_template
Expand All @@ -1603,9 +1656,7 @@ public static void main(String[] args) throws Exception {
System.out.println("replaceRoleTemplate() result:");
// begin-replace_role_template
TemplateRole templateRoleModel = new TemplateRole.Builder()
.name("SDKTestRoleTemplateRep")
.displayName("SDKTestRoleTemplateRep")
.serviceName("am-test-service")
.actions(java.util.Arrays.asList("am-test-service.test.create"))
.build();
ReplaceRoleTemplateOptions replaceRoleTemplateOptions = new ReplaceRoleTemplateOptions.Builder()
Expand Down Expand Up @@ -1651,9 +1702,7 @@ public static void main(String[] args) throws Exception {
System.out.println("createRoleTemplateVersion() result:");
// begin-create_role_template_version
TemplateRole templateRoleModel = new TemplateRole.Builder()
.name("SDKTestRoleVersion")
.displayName("SDKTestRoleVersionDisp")
.serviceName("am-test-service")
.description("am-test-service versioon customRole")
.actions(java.util.Arrays.asList("am-test-service.test.create"))
.build();
Expand Down Expand Up @@ -1833,6 +1882,21 @@ 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-delete_role_policy_template
DeletePolicyTemplateOptions deletePolicyTemplateOptions = new DeletePolicyTemplateOptions.Builder()
.policyTemplateId(exampleRolePolicyTemplateId)
.build();

Response<Void> response = service.deletePolicyTemplate(deletePolicyTemplateOptions).execute();
// end-delete_role_policy_template
System.out.printf("deleteRolePolicyTemplate() response status code: %d%n", response.getStatusCode());
} 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_role_template_version
DeleteRoleTemplateVersionOptions deleteRoleTemplateVersionOptions = new DeleteRoleTemplateVersionOptions.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2252,13 +2252,15 @@ public ServiceCall<RoleTemplate> createRoleTemplateVersion(CreateRoleTemplateVer
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("role", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createRoleTemplateVersionOptions.role()));
if (createRoleTemplateVersionOptions.name() != null) {
contentJson.addProperty("name", createRoleTemplateVersionOptions.name());
}
if (createRoleTemplateVersionOptions.description() != null) {
contentJson.addProperty("description", createRoleTemplateVersionOptions.description());
}
if (createRoleTemplateVersionOptions.role() != null) {
contentJson.add("role", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createRoleTemplateVersionOptions.role()));
}
if (createRoleTemplateVersionOptions.committed() != null) {
contentJson.addProperty("committed", createRoleTemplateVersionOptions.committed());
}
Expand Down Expand Up @@ -2323,13 +2325,15 @@ public ServiceCall<RoleTemplate> replaceRoleTemplate(ReplaceRoleTemplateOptions
builder.header("Accept", "application/json");
builder.header("If-Match", replaceRoleTemplateOptions.ifMatch());
final JsonObject contentJson = new JsonObject();
contentJson.add("role", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(replaceRoleTemplateOptions.role()));
if (replaceRoleTemplateOptions.name() != null) {
contentJson.addProperty("name", replaceRoleTemplateOptions.name());
}
if (replaceRoleTemplateOptions.description() != null) {
contentJson.addProperty("description", replaceRoleTemplateOptions.description());
}
if (replaceRoleTemplateOptions.role() != null) {
contentJson.add("role", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(replaceRoleTemplateOptions.role()));
}
if (replaceRoleTemplateOptions.committed() != null) {
contentJson.addProperty("committed", replaceRoleTemplateOptions.committed());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CreateRoleTemplateOptions extends GenericModel {
protected String accountId;
protected String description;
protected Boolean committed;
protected TemplateRole role;
protected RoleTemplatePrototypeRole role;
protected String acceptLanguage;

/**
Expand All @@ -35,7 +35,7 @@ public static class Builder {
private String accountId;
private String description;
private Boolean committed;
private TemplateRole role;
private RoleTemplatePrototypeRole role;
private String acceptLanguage;

/**
Expand Down Expand Up @@ -128,7 +128,7 @@ public Builder committed(Boolean committed) {
* @param role the role
* @return the CreateRoleTemplateOptions builder
*/
public Builder role(TemplateRole role) {
public Builder role(RoleTemplatePrototypeRole role) {
this.role = role;
return this;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public Boolean committed() {
*
* @return the role
*/
public TemplateRole role() {
public RoleTemplatePrototypeRole role() {
return role;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
public class CreateRoleTemplateVersionOptions extends GenericModel {

protected String roleTemplateId;
protected TemplateRole role;
protected String name;
protected String description;
protected TemplateRole role;
protected Boolean committed;

/**
* Builder.
*/
public static class Builder {
private String roleTemplateId;
private TemplateRole role;
private String name;
private String description;
private TemplateRole role;
private Boolean committed;

/**
Expand All @@ -43,9 +43,9 @@ public static class Builder {
*/
private Builder(CreateRoleTemplateVersionOptions createRoleTemplateVersionOptions) {
this.roleTemplateId = createRoleTemplateVersionOptions.roleTemplateId;
this.role = createRoleTemplateVersionOptions.role;
this.name = createRoleTemplateVersionOptions.name;
this.description = createRoleTemplateVersionOptions.description;
this.role = createRoleTemplateVersionOptions.role;
this.committed = createRoleTemplateVersionOptions.committed;
}

Expand All @@ -59,11 +59,9 @@ public Builder() {
* Instantiates a new builder with required properties.
*
* @param roleTemplateId the roleTemplateId
* @param role the role
*/
public Builder(String roleTemplateId, TemplateRole role) {
public Builder(String roleTemplateId) {
this.roleTemplateId = roleTemplateId;
this.role = role;
}

/**
Expand All @@ -86,17 +84,6 @@ public Builder roleTemplateId(String roleTemplateId) {
return this;
}

/**
* Set the role.
*
* @param role the role
* @return the CreateRoleTemplateVersionOptions builder
*/
public Builder role(TemplateRole role) {
this.role = role;
return this;
}

/**
* Set the name.
*
Expand All @@ -119,6 +106,17 @@ public Builder description(String description) {
return this;
}

/**
* Set the role.
*
* @param role the role
* @return the CreateRoleTemplateVersionOptions builder
*/
public Builder role(TemplateRole role) {
this.role = role;
return this;
}

/**
* Set the committed.
*
Expand All @@ -136,12 +134,10 @@ protected CreateRoleTemplateVersionOptions() { }
protected CreateRoleTemplateVersionOptions(Builder builder) {
com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.roleTemplateId,
"roleTemplateId cannot be empty");
com.ibm.cloud.sdk.core.util.Validator.notNull(builder.role,
"role cannot be null");
roleTemplateId = builder.roleTemplateId;
role = builder.role;
name = builder.name;
description = builder.description;
role = builder.role;
committed = builder.committed;
}

Expand All @@ -165,17 +161,6 @@ public String roleTemplateId() {
return roleTemplateId;
}

/**
* Gets the role.
*
* The role properties that are created in an action resource when the template is assigned.
*
* @return the role
*/
public TemplateRole role() {
return role;
}

/**
* Gets the name.
*
Expand All @@ -200,6 +185,17 @@ public String description() {
return description;
}

/**
* Gets the role.
*
* The role properties that are created in an action resource when the template is assigned.
*
* @return the role
*/
public TemplateRole role() {
return role;
}

/**
* Gets the committed.
*
Expand Down
Loading