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(HMS-2248): Add token support for list template #668

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

adiabramovitch
Copy link
Member

@adiabramovitch adiabramovitch commented Sep 7, 2023

Depends on #625
This PR introduces pagination support for AWS and GCP by returning the received token when fetching the corresponding page. To validate the retrieval of AWS pages, the token needs to be escaped since it is in base64 format.

However, tests are currently missing, andI plan on adding those once will get some feedback. Additionally, tests are failing due to the initial commit missing limit and offset. I plan to stub them and proceed with adding the tests once this implementation is agreed upon.

Please let me know if you have any feedback or suggestions regarding this approach before proceeding with the test implementation.
For easy review just take a look at the changes made by the second commit, once the dependent PR will be merged i'll rebase.

@adiabramovitch adiabramovitch requested a review from a team as a code owner September 7, 2023 06:40
Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

I guess it replaces the closed PR. Looks god. IQE is still failing.

internal/routes/all_routes.go Show resolved Hide resolved
Copy link
Member

@avitova avitova left a comment

Choose a reason for hiding this comment

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

Just a few nits. I think we should either make it clear in the function documentation that it never returns *Metadata = nil, or make a safer return in the function with pointer in the parameter.
But you can decide I do not insist on those things.

if token == "" {
logger.Warn().Msg("token is empty, listing first page")
}
return context.WithValue(ctx, tokenCtxKey, token)
Copy link
Member

Choose a reason for hiding this comment

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

What are the consequences if we add the empty token to the context? Do we want to add the empty string to the context?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means that we are listing the first page and we add an empty token to the context

}
}
return &LaunchTemplateListResponse{Data: list}
return &LaunchTemplateListResponse{Data: list, Metadata: *meta}
Copy link
Member

Choose a reason for hiding this comment

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

We might want to check for nil before dereferencing, if that makes sense. For that case, we want to return an empty Metadata structure.

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 dont think it is needed, we are always returning a Metadata struct if you take a look here: NewTokenMetadata and NewOffsetMetadata
there is not a case we return nil from those functions.

Copy link
Member

@avitova avitova Sep 7, 2023

Choose a reason for hiding this comment

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

I understand. This was just an idea for better maintaining in the future.

The point is, if someone uses this function in the future, they do not have to know that it does not handle nil. Best functions are the ones of which implementation you do not have to know. 😆
If someone wanted to call the function in the future without NewListLaunchTemplateResponse Metadata parameter, they would have to create an empty one anyway and pass a pointer to such an empty Metadata structure. If this had been done in the codebase more times, it would create a duplication.
In a worse case, they would think that the function accepts a nil pointer. They would find out pretty quickly because of the panic, but yeah, that was just why I thought it might be handy.

Moreover, we pass results from other functions. I.e.: metadata := someFunctionWithPointerReturnValue.
And if someone changes that in the future, because we would want to use a nil pointer as a return value, this breaks as a consequence.

list := make([]*PubkeyResponse, len(pubkeys))
for i, pubkey := range pubkeys {
list[i] = NewPubkeyResponse(pubkey)
}
return &PubkeyListResponse{Data: list, Metadata: info.Metadata, Links: info.Links}
return &PubkeyListResponse{Data: list, Metadata: *meta}
Copy link
Member

Choose a reason for hiding this comment

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

same comment

list := make([]*GenericReservationResponse, len(reservations))
for i, reservation := range reservations {
list[i] = reservationResponseMapper(reservation)
}
return &GenericReservationListResponse{Data: list, Metadata: info.Metadata, Links: info.Links}
return &GenericReservationListResponse{Data: list, Metadata: *meta}
Copy link
Member

Choose a reason for hiding this comment

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

same comment

@@ -42,7 +41,7 @@ func NewListSourcesResponse(sourceList []*clients.Source, info *page.Info) rende
Status: source.Status,
}
}
return &SourceListResponse{Data: list, Metadata: info.Metadata, Links: info.Links}
return &SourceListResponse{Data: list, Metadata: *meta}
Copy link
Member

Choose a reason for hiding this comment

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

and here

internal/page/page.go Outdated Show resolved Hide resolved
@akhil-jha
Copy link
Member

/retest

@ezr-ondrej
Copy link
Member

@avitova I guess it's up to your final ack now :)

Copy link
Member

@avitova avitova left a comment

Choose a reason for hiding this comment

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

Nice work!:) TY

@ezr-ondrej ezr-ondrej merged commit e067a69 into RHEnVision:main Sep 7, 2023
6 checks passed
@ezr-ondrej
Copy link
Member

TY all! 🎉

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

Successfully merging this pull request may close these issues.

5 participants