-
Notifications
You must be signed in to change notification settings - Fork 15
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
ROX-12151: cloud accounts endpoint #517
Conversation
return nil, fmt.Errorf("error getting cloud accounts: %w", err) | ||
} | ||
|
||
quotaCostList.Items().Each(func(qc *amsv1.QuotaCost) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will list all cloud accounts, right? We should filter here on the cloud accounts that are attached to our marketplace SKU, i.e. "quota_id": "cluster|rhinfra|rhacs|marketplace"
. Otherwise we'll also return cloud accounts that have purchased different products.
pkg/client/ocm/client.go
Outdated
@@ -600,3 +602,26 @@ func (c client) GetQuotaCostsForProduct(organizationID, resourceName, product st | |||
|
|||
return res, nil | |||
} | |||
|
|||
func (c *client) GetCustomerCloudAccounts(externalID string) ([]*amsv1.CloudAccount, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test for this function using the generated mocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean cloud_accounts_test.go
for the endpoint handler? There's no way to mock sdkClient.Connection
used in client.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yes. I think you could write a unit test with the cloud_accounts_test.mock
, and you could also take a look at https://github.com/stackrox/acs-fleet-manager/blob/main/internal/dinosaur/pkg/services/quota/ams_quota_service_test.go for how to mock the OCM client. With the latter you could test the SKU filter logic.
@@ -608,6 +608,37 @@ paths: | |||
security: | |||
- Bearer: [] | |||
summary: Returns the list of supported regions of the supported cloud provider | |||
/api/rhacs/v1/cloud_accounts: | |||
get: | |||
operationId: getCloudAccounts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The endpoint looks good to me. The only thing I'm wondering about is this operationId
. @stehessel mentioned in his comment how to access the organization.id
using ocm
command. Is operationId
supposed to be that? Also, accessing that id using the ocm command is helpful, but I can't do that through the browser so I'll need to find another way to do that. If you or @stehessel might know how that's possible, let me know. I am searching through https://api.openshift.com/ to see if there might be some API endpoint that might give me that information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is /api/accounts_mgmt/v1/organizations
the API i'm looking for? Looks like that gives me a list of organizations (there seems to be just one though). I see fields like id
and external_id
which seem relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sachaudh organization.id
will be extracted by fleet-manager
from AMS using orgId
provided in the Bearer token. The endpoint doesn't take any parameters.
operationId
is swagger parameter that is used to uniquely identify the operation within the API spec:
https://swagger.io/docs/specification/paths-and-operations/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then I think that's fine with me. Thanks for adding the endpoint @ivan-degtiarenko 👍🏼
|
||
func (c *client) GetCustomerCloudAccounts(externalID string, quotaIDs []string) ([]*amsv1.CloudAccount, error) { | ||
var res []*amsv1.CloudAccount | ||
organizationClient := c.connection.AccountsMgmt().V1().Organizations() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already GetQuotaCostsForProduct
- seems like it's what we want, it's only missing a fetchCloudAccounts=true
flag. Maybe we could reuse this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really - GetQuotaCostsForProduct
does filtration by resourceName
and product
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle that is what we also want. But I think you are right, we would want to filter for billing_model==marketplace
as well. Easier to go the quota_id
route then.
JwtCAFile = "test/support/jwt_ca.pem" | ||
) | ||
|
||
func TestGetSuccess(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to test GetCustomerCloudAccounts
as well, in particular testing that the filtering by resource id works. I think this is possible by mocking the other OCM client methods like QuotaCost
(or GetQuotaCostsForProduct
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetQuotaCostsForProduct
can't be reused for the reasons mentioned above. I'm not sure how one can mock QuotaCost
method on the organizationClient - it is created by Connection
:
https://github.com/stackrox/acs-fleet-manager/blob/ivan%2FROX-12151-aws-accounts-endpoint/pkg/client/ocm/client.go#L608-L608
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yes that is impractical, I thought I saw it in the method list of the client, but you are right it's not. That would leave us with mocks on http level, which maybe are supported via the "mock modes" (https://github.com/stackrox/acs-fleet-manager/blob/ivan/ROX-12151-aws-accounts-endpoint/pkg/client/ocm/config.go#L12). But probably a lot of effort for a simple feature...
func (h *cloudAccountsHandler) Get(w http.ResponseWriter, r *http.Request) { | ||
cfg := &handlers.HandlerConfig{ | ||
Action: func() (i interface{}, serviceError *errors.ServiceError) { | ||
ctx := r.Context() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you extract inside of this function (func() (i interface{}, serviceError *errors.ServiceError) { ... }
, you could test it separately from the http related parts of Get
. This would save you some http setup in the cloud_accounts_test.go
.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ivan-degtiarenko, stehessel The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
886031e
to
a5c79f5
Compare
New changes are detected. LGTM label has been removed. |
Description
Introduces the call to AMS client as well as new endpoint. The organization ID is taken from the caller's claims.
Checklist (Definition of Done)
Test manual
ROX-12345: ...
Test manual
TODO: Add manual testing efforts
./fleet-manager serve --ocm-base-url=https://api.openshift.com --ocm-client-id-file=secrets/ocm-service.clientId --ocm-client-secret-file=secrets/ocm-service.clientSecret
GET http://localhost:8000/api/rhacs/v1/cloud_accounts
withrhacs-test-customer
Bearer token