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

Add support for Get Profile Status By ID in Cli and Api #5100

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cmd/cli/app/profile/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package status

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -29,11 +28,9 @@ func init() {
profile.ProfileCmd.AddCommand(profileStatusCmd)
// Flags
profileStatusCmd.PersistentFlags().StringP("name", "n", "", "Profile name to get profile status for")
profileStatusCmd.PersistentFlags().StringP("id", "i", "", "ID to get profile status for")
profileStatusCmd.PersistentFlags().StringP("output", "o", app.Table,
fmt.Sprintf("Output format (one of %s)", strings.Join(app.SupportedOutputFormats(), ",")))
// Required
if err := profileStatusCmd.MarkPersistentFlagRequired("name"); err != nil {
profileStatusCmd.Printf("Error marking flag required: %s", err)
os.Exit(1)
}
profileStatusCmd.MarkFlagsOneRequired("id", "name")
}
60 changes: 52 additions & 8 deletions cmd/cli/app/profile/status/status_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func getCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.

project := viper.GetString("project")
profileName := viper.GetString("name")
profileId := viper.GetString("id")
entityId := viper.GetString("entity")
entityType := viper.GetString("entity-type")
format := viper.GetString("output")
Expand All @@ -42,14 +43,7 @@ func getCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.
return cli.MessageAndError(fmt.Sprintf("Output format %s not supported", format), fmt.Errorf("invalid argument"))
}

resp, err := client.GetProfileStatusByName(ctx, &minderv1.GetProfileStatusByNameRequest{
Context: &minderv1.Context{Project: &project},
Name: profileName,
Entity: &minderv1.EntityTypedId{
Id: entityId,
Type: minderv1.EntityFromString(entityType),
},
})
resp, err := getProfileStatus(ctx, client, project, profileId, profileName, entityId, entityType)
if err != nil {
return cli.MessageAndError("Error getting profile status", err)
}
Expand All @@ -76,6 +70,56 @@ func getCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.
return nil
}

func getProfileStatus(
ctx context.Context,
client minderv1.ProfileServiceClient,
project, profileId, profileName, entityId, entityType string,
) (*minderv1.GetProfileStatusResponse, error) {
var resp *minderv1.GetProfileStatusResponse

if profileId != "" {
idResp, err := client.GetProfileStatusById(ctx, &minderv1.GetProfileStatusByIdRequest{
Context: &minderv1.Context{Project: &project},
Id: profileId,
Entity: &minderv1.EntityTypedId{
Id: entityId,
Type: minderv1.EntityFromString(entityType),
},
})
if err != nil {
return nil, err
}

// Convert to the common response type
resp = &minderv1.GetProfileStatusResponse{
ProfileStatus: idResp.ProfileStatus,
RuleEvaluationStatus: idResp.RuleEvaluationStatus,
}
} else if profileName != "" {
nameResp, err := client.GetProfileStatusByName(ctx, &minderv1.GetProfileStatusByNameRequest{
Context: &minderv1.Context{Project: &project},
Name: profileName,
Entity: &minderv1.EntityTypedId{
Id: entityId,
Type: minderv1.EntityFromString(entityType),
},
})
if err != nil {
return nil, err
}

// Convert to the common response type
resp = &minderv1.GetProfileStatusResponse{
ProfileStatus: nameResp.ProfileStatus,
RuleEvaluationStatus: nameResp.RuleEvaluationStatus,
}
} else {
return nil, cli.MessageAndError("Error getting profile status", fmt.Errorf("profile id or profile name required"))
}
eleftherias marked this conversation as resolved.
Show resolved Hide resolved

return resp, nil
}

func init() {
profileStatusCmd.AddCommand(getCmd)
// Flags
Expand Down
42 changes: 42 additions & 0 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading