-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add support for Get Profile Status By ID in Cli and Api #5100
base: main
Are you sure you want to change the base?
Conversation
Fixed the issue where retrieving profile status by ID was not possible due to the missing CLI flag. Also added a function to get profile status by ID and project.
Reduced Complexity From 23 to 12
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.
Thank you for your contribution @navnitms!
I've left a few comments inline.
proto/minder/v1/minder.proto
Outdated
@@ -606,6 +606,17 @@ service ProfileService { | |||
}; | |||
} | |||
|
|||
rpc GetProfileStatusById (GetProfileStatusByIdRequest) returns (GetProfileStatusByIdResponse) { | |||
option (google.api.http) = { | |||
get: "/api/v1/profile/id/{id=**}/status" |
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.
Following the convention set by the other API endpoints, this should be
get: "/api/v1/profile/id/{id=**}/status" | |
get: "/api/v1/profile/{id}/status" |
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.
Have updated the api , to follow the convention
var getProfileErr error | ||
|
||
switch id := profileIdentifier.(type) { | ||
case string: |
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.
I worry that the switch statement here is fragile and makes it harder to follow the codepath.
Do you see a way to call GetProfileStatusByNameAndProjectParams
or GetProfileStatusByIdAndProjectParams
respectively in their corresponding top level functions and then pass the results to the helper?
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.
Have refactored the code , to make the flow more simple to follow
@eleftherias Thanks for the review |
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.
Thanks for the quick updates @navnitms!
I've left a few more comments inline.
bool all = 4; | ||
|
||
// rule is the type of the rule. Deprecated in favor of rule_type | ||
string rule = 5 [deprecated=true]; |
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.
Since this is a new API, we shouldn't add deprecated fields
if selector != nil || isAllRequested(ctx) { | ||
dbRuleEvaluationStatuses, err := s.store.ListRuleEvaluationsByProfileId(ctx, db.ListRuleEvaluationsByProfileIdParams{ | ||
ProfileID: profileID, | ||
EntityID: *selector, |
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.
selector
could be nil here which would result in a panic
err error) { | ||
|
||
switch ps := dbProfileStatus.(type) { | ||
case db.GetProfileStatusByNameAndProjectRow: |
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 isn't much benefit in having a common helper function if it has switch statements which separate the code paths.
In this case, we can change the signature of processProfileStatus
to processProfileStatus(ctx context.Context, profileName string, profileID uuid.UUID, lastUpdated *timestamppb.Timestamp, profileStatus string)
and then just pass the fields that we need:
resp, err := s.processProfileStatus(
ctx,
dbProfileStatus.Name,
dbProfileStatus.ID,
timestamppb.New(dbProfileStatus.LastUpdated),
string(dbProfileStatus.ProfileStatus),
)
var ruleName *sql.NullString | ||
|
||
switch r := req.(type) { | ||
case *minderv1.GetProfileStatusByNameRequest: |
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.
Once we remove rule
from the GetProfileStatusByIdRequest
then the logic will be different between getting the status by name and ID.
It would make sense to have 2 separate helpers instead of a common helper with switch statements.
Summary
Added support to get profile status by Profile Id in CLI
Reformatted GetProfileStatusByNameAndProject code to accommodate GetProfileStatusByIdAndProject
Reformatted GetProfileStatusByNameAndProject to reduce complexity to a permissible level (<15)
Fixes (#4999 )
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: