Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(IAM Policy Management): re-gen service after recent API changes,… #259

Merged
merged 15 commits into from
Aug 9, 2023

Conversation

vivekj3
Copy link
Member

@vivekj3 vivekj3 commented May 19, 2023

PR summary

Added feature support for Enterprise IAM work, policy templates and get template assignments.

Issue: https://github.ibm.com/IAM/AM-issues/issues/1086

PR Checklist

Please make sure that your PR fulfills the following requirements:

  • The commit message follows the Angular Commit Message Guidelines.
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Current vs new behavior

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

API defintion:
Staging
Prod

Test information:

Unit Tests:

image

Example Tests:

image

Integration Tests:

image

… Tests added for Policy Template

Signed-off-by: Vivek.Jain3 <[email protected]>
@CLAassistant
Copy link

CLAassistant commented May 19, 2023

CLA assistant check
All committers have signed the CLA.

testPolicyTemplateETag string = ""
testPolicyTemplateVersion string = ""
// change testPolicyAssignmentId id after prod account setup
testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a flow like:

  1. list policy assignments 2. Store an assignment id, 3. use stored id to call get assignment by id?
    I think it is okay to hardcode an ID here, but I'm not sure if it matters whether it is production or test environment. These tests are for us to run locally and we can give production credentials in the iam_policy_management.env when we test locally to verify works in production.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is better to use assignment id from list policy assignments, as same assignment id will not be available in different accounts so even if we hardcode it will restricted to use same account.

Thanks i'll update

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your reasoning sounds good. We can try to make sure we create an assignment in the account we use for testing, but luckily there are some we can refer to currently.
Thanks for making that change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might not understand 100% of this discussion, but it sounds like you need to use an id of a pre-existing account that your tests rely on. The int tests and examples for this service already retrieve the "TEST_ACCOUNT_ID" config property from the .env file during startup. It is stored in the testAccountID variable in the integration tests and in exampleAccountID in the examples code.
It's way better to retrieve this value from the .env file than to keep having to update the hard-coded id within the actual source code.

examplePolicyTemplateETag string
examplePolicyTemplateVersion string
// change testPolicyAssignmentId id after prod account setup
testPolicyAssignmentId = "442c6fc4-2f74-41b2-bf4d-98342614cd22"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment.

Copy link
Contributor

@swcolley swcolley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my perspective :D

@vivekj3 vivekj3 marked this pull request as ready for review May 29, 2023 08:51
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some improvements that can be made in the integration tests and examples. I'd like to encourage you to update the API definition to define links where there are inter-operation dependencies. This will then let you avoid the manual changes to store off specific values and then use those values in downstream operations.
The tests and examples code are functional as they are, but the change I'm suggesting will make for easier maintenance in the future.
Let's discuss before we merge...

Expect(response.StatusCode).To(Equal(201))
Expect(policyTemplate).ToNot(BeNil())

examplePolicyTemplateID = *policyTemplate.ID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you define the appropriate link objects in your API definition, the SDK generator will generate code like this to store off a value such as the policyTemplate.ID value, then generate code in the test of the consuming operation to use the stored value to initialize an operation parameter.
Take a look at the SDK squad's mock service that we use for various types of testing:
https://github.ibm.com/CloudEngineering/openapi-sdkgen/blob/main/src/test/resources/ansiform-service.yaml
and the associated Go code in the resulting Go SDK:
https://github.ibm.com/CloudEngineering/ansiform-go-sdk/tree/main/ansiformmockv1

Note that the integration tests and examples code were generated for this service with no required manual post-gen changes. This is due to the fact that example values and links are defined throughout the API definition.

Expect(policyTemplate.Name).ToNot(BeNil())
Expect(policyTemplate.Policy).ToNot(BeNil())

examplePolicyTemplateETag = response.GetHeaders().Get("ETag")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use a link to store off ETag values and then use the value to initialize an "IfMatch" header param in downstream operations.

Expect(policyTemplate.Policy.Type).To(Equal(core.StringPtr("access")))
Expect(policyTemplate.AccountID).To(Equal(core.StringPtr(testAccountID)))

testPolicyTemplateID = *policyTemplate.ID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments here re: links/examples as in the examples code above.

})
It(`ListPolicyTemplates(listPolicyTemplatesOptions *ListPolicyTemplatesOptions)`, func() {
listPolicyTemplatesOptions := &iampolicymanagementv1.ListPolicyTemplatesOptions{
AccountID: core.StringPtr(testAccountID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AccountID: core.StringPtr(testAccountID),
AccountID: &testAccountID,

The core.StringPtr() function is only needed when using a string literal. For a variable, we can just use the & operator directly.

@padamstx padamstx self-assigned this Jun 21, 2023
@padamstx padamstx merged commit 2837a98 into IBM:main Aug 9, 2023
ibm-devx-sdk pushed a commit that referenced this pull request Aug 9, 2023
# [0.43.0](v0.42.1...v0.43.0) (2023-08-09)

### Features

* **IAM Policy Management:** re-gen service after recent API changes,… ([#259](#259)) ([2837a98](2837a98))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 0.43.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants