Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove org field and make req ctx fields optional #1831

Merged
merged 2 commits into from
Dec 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion cmd/cli/app/profile/profile_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ minder control plane.`,

_, err = client.DeleteProfile(ctx, &pb.DeleteProfileRequest{
Context: &pb.Context{
Provider: provider,
Provider: &provider,
},
Id: id,
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/profile/profile_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ minder control plane.`,
id := viper.GetString("id")
profile, err := client.GetProfileById(ctx, &pb.GetProfileByIdRequest{
Context: &pb.Context{
Provider: provider,
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/profile/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ minder control plane for an specific project.`,

resp, err := client.ListProfiles(ctx, &pb.ListProfilesRequest{
Context: &pb.Context{
Provider: provider,
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/profile/table_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func renderRuleTable(
row := []string{
*p.Id,
p.Name,
p.Context.Provider,
*p.Context.Provider,
entType.String(),
rule.Type,
params,
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/profile_status/profile_status_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ minder control plane for an specific provider/project or profile id, entity type

req := &minderv1.GetProfileStatusByNameRequest{
Context: &minderv1.Context{
Provider: provider,
Provider: &provider,
},
Name: profileName,
Entity: &minderv1.GetProfileStatusByNameRequest_EntityTypedId{
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/profile_status/profile_status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ minder control plane for an specific provider/project or profile id.`,

req := &pb.GetProfileStatusByNameRequest{
Context: &pb.Context{
Provider: provider,
Provider: &provider,
},
Name: profileName,
All: all,
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/app/quickstart/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var cmd = &cobra.Command{
}

if provider != "" {
rt.Context.Provider = provider
rt.Context.Provider = &provider
}

// Create the rule type in minder (new context, so we don't time out)
Expand Down Expand Up @@ -273,7 +273,7 @@ var cmd = &cobra.Command{
}

if provider != "" {
p.Context.Provider = provider
p.Context.Provider = &provider
}

// Create the profile in minder (new context, so we don't time out)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var repo_listCmd = &cobra.Command{
row := table.Row{
*v.Id,
*v.Context.Project,
v.Context.Provider,
*v.Context.Provider,
fmt.Sprintf("%d", v.GetRepoId()),
v.GetOwner(),
v.GetName(),
Expand Down
6 changes: 4 additions & 2 deletions cmd/cli/app/ruletype/rule_type_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ minder control plane.`,
rulesToDelete := []*minderv1.RuleType{}
if !deleteAll {
// Fetch the rule type from the DB, so we can get its name
provider := viper.GetString("provider")
rtype, err := client.GetRuleTypeById(ctx, &minderv1.GetRuleTypeByIdRequest{
Context: &minderv1.Context{
Provider: viper.GetString("provider"),
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand All @@ -95,9 +96,10 @@ minder control plane.`,
rulesToDelete = append(rulesToDelete, rtype.RuleType)
} else {
// List all rule types
provider := viper.GetString("provider")
resp, err := client.ListRuleTypes(ctx, &minderv1.ListRuleTypesRequest{
Context: &minderv1.Context{
Provider: viper.GetString("provider"),
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/ruletype/rule_type_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ minder control plane.`,

rtype, err := client.GetRuleTypeById(ctx, &minderv1.GetRuleTypeByIdRequest{
Context: &minderv1.Context{
Provider: provider,
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/ruletype/rule_type_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ minder control plane for an specific project.`,

resp, err := client.ListRuleTypes(ctx, &minderv1.ListRuleTypesRequest{
Context: &minderv1.Context{
Provider: provider,
Provider: &provider,
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/ruletype/table_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func renderRuleTypeTable(
table *tablewriter.Table,
) {
row := []string{
rt.Context.Provider,
*rt.Context.Provider,
*rt.Context.Project,
*rt.Id,
rt.Name,
Expand Down
3 changes: 2 additions & 1 deletion cmd/dev/app/rule_type/rttst.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ func testCmdRun(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("error reading rule type from file: %w", err)
}

provider := "test"
rootProject := "00000000-0000-0000-0000-000000000002"
rt.Context = &minderv1.Context{
Provider: "test",
Provider: &provider,
Project: &rootProject,
}

Expand Down
20 changes: 3 additions & 17 deletions docs/docs/ref/proto.md

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

6 changes: 3 additions & 3 deletions internal/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *Server) ListRepositories(ctx context.Context,
Id: &id,
Context: &pb.Context{
Project: &projID,
Provider: repo.Provider,
Provider: &repo.Provider,
},
Owner: repo.RepoOwner,
Name: repo.RepoName,
Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *Server) GetRepositoryById(ctx context.Context,
Id: &id,
Context: &pb.Context{
Project: &projID,
Provider: repo.Provider,
Provider: &repo.Provider,
},
Owner: repo.RepoOwner,
Name: repo.RepoName,
Expand Down Expand Up @@ -300,7 +300,7 @@ func (s *Server) GetRepositoryByName(ctx context.Context,
Id: &id,
Context: &pb.Context{
Project: &projID,
Provider: repo.Provider,
Provider: &repo.Provider,
},
Owner: repo.RepoOwner,
Name: repo.RepoName,
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/handlers_ruletype.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (s *Server) DeleteRuleType(
return nil, status.Errorf(codes.Unknown, "failed to get provider: %s", err)
}

in.Context.Provider = prov.Name
in.Context.Provider = &prov.Name

ctx, err = s.authAndContextValidation(ctx, in.GetContext())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func GetContextFromInput(ctx context.Context, in *pb.Context, q db.Querier) (*En
}

prov, err := q.GetProviderByName(ctx, db.GetProviderByNameParams{
Name: in.Provider,
Name: *in.Provider,
ProjectID: project.ID,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func MergeDatabaseListIntoProfiles(ppl []db.ListProfilesByProjectIDRow, ectx *En
Id: &profileID,
Name: p.Name,
Context: &pb.Context{
Provider: ectx.Provider.Name,
Provider: &ectx.Provider.Name,
Project: &ectx.Project.Name,
},
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func MergeDatabaseGetIntoProfiles(ppl []db.GetProfileByProjectAndIDRow, ectx *En
Id: &profileID,
Name: p.Name,
Context: &pb.Context{
Provider: ectx.Provider.Name,
Provider: &ectx.Provider.Name,
Project: &ectx.Project.Name,
},
}
Expand Down
11 changes: 4 additions & 7 deletions internal/engine/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

var (
defaultOrg = "ACME"
defaultProvider = "github"
)

func compareProfiles(t *testing.T, a *minderv1.Profile, b *minderv1.Profile) {
Expand Down Expand Up @@ -144,8 +144,7 @@ artifact:
want: &minderv1.Profile{
Name: "acme-github-profile",
Context: &minderv1.Context{
Organization: &defaultOrg,
Provider: "github",
Provider: &defaultProvider,
},
Repository: []*minderv1.Profile_Rule{
{
Expand Down Expand Up @@ -228,8 +227,7 @@ repository:
want: &minderv1.Profile{
Name: "acme-github-profile",
Context: &minderv1.Context{
Organization: &defaultOrg,
Provider: "github",
Provider: &defaultProvider,
},
Repository: []*minderv1.Profile_Rule{
{
Expand Down Expand Up @@ -342,8 +340,7 @@ func TestGetRulesForEntity(t *testing.T) {
pol := &minderv1.Profile{
Name: "acme-github-profile",
Context: &minderv1.Context{
Organization: &defaultOrg,
Provider: "github",
Provider: &defaultProvider,
},
Repository: []*minderv1.Profile_Rule{
{
Expand Down
15 changes: 5 additions & 10 deletions internal/engine/rule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func NewRuleTypeEngine(
rte := &RuleTypeEngine{
Meta: RuleMeta{
Name: rt.Name,
Provider: rt.Context.Provider,
Provider: *rt.Context.Provider,
},
rval: rval,
rdi: rdi,
Expand All @@ -214,17 +214,11 @@ func NewRuleTypeEngine(
ingestCache: ingestcache.NewNoopCache(),
}

// Set organization if it exists
if rt.Context.Organization != nil && *rt.Context.Organization != "" {
// We need to clone the string because the pointer is to a string literal,
// and we don't want to modify that
org := strings.Clone(*rt.Context.Organization)
rte.Meta.Organization = &org
} else if rt.Context.Project != nil && *rt.Context.Project != "" {
if rt.Context.Project != nil && *rt.Context.Project != "" {
prj := strings.Clone(*rt.Context.Project)
rte.Meta.Project = &prj
} else {
return nil, fmt.Errorf("rule type context must have an organization or project")
return nil, fmt.Errorf("rule type context must have a project")
}

return rte, nil
Expand Down Expand Up @@ -304,12 +298,13 @@ func RuleTypePBFromDB(rt *db.RuleType, ectx *EntityContext) (*minderv1.RuleType,
}

id := rt.ID.String()
name := ectx.GetProvider().Name

return &minderv1.RuleType{
Id: &id,
Name: rt.Name,
Context: &minderv1.Context{
Provider: ectx.GetProvider().Name,
Provider: &name,
Project: &gname,
},
Description: rt.Description,
Expand Down
Loading
Loading