-
Notifications
You must be signed in to change notification settings - Fork 41
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.
proto/minder/v1/minder.proto
Outdated
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.
Hey @navnitms, happy new year! |
Hey @eleftherias , Sorry for the delay |
No problem @navnitms and thank you for your work so far. Feel free to reach out if you have any questions. |
Hey @eleftherias, Thanks for the support, |
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 updates! I've left one comment inline.
There is also a change that needs to be made to the validators. Currently, the validator still requires a profile name. We should update it to require either a name or an ID:
minder/pkg/api/protobuf/go/minder/v1/validators.go
Lines 460 to 471 in a02f754
func (p *Profile) Validate() error { | |
if p.getTypeWithDefault() != ProfileType { | |
return fmt.Errorf("%w: profile type is invalid: %s. Did you parse the wrong file?", | |
ErrValidationFailed, p.Type) | |
} | |
if p.getVersionWithDefault() != ProfileTypeVersion { | |
return fmt.Errorf("%w: profile version is invalid: %s", ErrValidationFailed, p.Version) | |
} | |
if p.GetName() == "" { | |
return fmt.Errorf("%w: profile name cannot be empty", ErrValidationFailed) | |
} |
logger.BusinessRecord(ctx).Project = entityCtx.Project.ID | ||
logger.BusinessRecord(ctx).Profile = logger.Profile{Name: profileName, ID: profileID} | ||
|
||
return &minderv1.GetProfileStatusResponse{ |
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 can return minderv1.GetProfileStatusByNameResponse
and then we can remove GetProfileStatusResponse
from the proto file.
logger.BusinessRecord(ctx).Project = entityCtx.Project.ID | ||
logger.BusinessRecord(ctx).Profile = logger.Profile{Name: profileName, ID: profileID} | ||
|
||
return &minderv1.GetProfileStatusResponse{ |
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.
Similar to the the comment above, This can return minderv1.GetProfileStatusByIdResponse
so we can remove GetProfileStatusResponse
from the proto file.
Hi @eleftherias
I have some concerns about this proposed change. Additionally, I noticed that the check for whether profileId or profileName is passed is happening in the minder/cmd/cli/app/profile/get.go Apologies for the multiple iterations of review required for this PR. |
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: