Skip to content

Commit

Permalink
Changed policies to use search instead of list to enable exclusion of…
Browse files Browse the repository at this point in the history
… delete policies (#97)

* Changed method to search
  • Loading branch information
notanthony authored Apr 5, 2024
1 parent c2a2f82 commit 0f49af7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
48 changes: 24 additions & 24 deletions cmd/cone/task_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package main
import "github.com/spf13/cobra"

const (
accessReviewIdsFlag = "access-review-id"
appEntitlementIdsFlag = "app-entitlement-id"
appResourceIdsFlag = "app-resource-id"
appResourceTypeIdsFlag = "app-resource-type-id"
appUserSubjectIdsFlag = "app-user-subject-id"
userSubjectIdsFlag = "user-subject-id"
appIdsFlag = "app-id"
assigneeIdsFlag = "assignee-id"
accessReviewIDsFlag = "access-review-id"
appEntitlementIDsFlag = "app-entitlement-id"
appResourceIDsFlag = "app-resource-id"
appResourceTypeIDsFlag = "app-resource-type-id"
appUserSubjectIDsFlag = "app-user-subject-id"
userSubjectIDsFlag = "user-subject-id"
appIDsFlag = "app-id"
assigneeIDsFlag = "assignee-id"
stateFlag = "state"
taskTypeFlag = "task-type"
includeDeletedFlag = "include-deleted"
Expand All @@ -20,29 +20,29 @@ const (
func addCommentFlag(cmd *cobra.Command) {
cmd.Flags().String(commentFlag, "", "Comment to add to the task when performing an action")
}
func addAccessReviewIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(accessReviewIdsFlag, nil, "Filter tasks by access review id(s) (access review campaign this task belongs to)")
func addAccessReviewIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(accessReviewIDsFlag, nil, "Filter tasks by access review id(s) (access review campaign this task belongs to)")
}
func addAppEntitlementIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appEntitlementIdsFlag, nil, "Filter tasks by app entitlement id(s) (target app entitlement of the ticket)")
func addAppEntitlementIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appEntitlementIDsFlag, nil, "Filter tasks by app entitlement id(s) (target app entitlement of the ticket)")
}
func addAppResourceIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appResourceIdsFlag, nil, "Filter tasks by app resource id(s) (target resource of the ticket)")
func addAppResourceIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appResourceIDsFlag, nil, "Filter tasks by app resource id(s) (target resource of the ticket)")
}
func addAppResourceTypeIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appResourceTypeIdsFlag, nil, "Filter tasks by app resource type id(s) (target resource type of the task)")
func addAppResourceTypeIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appResourceTypeIDsFlag, nil, "Filter tasks by app resource type id(s) (target resource type of the task)")
}
func addAppUserSubjectIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appUserSubjectIdsFlag, nil, "Filter tasks by app user subject id(s) (target of the task)")
func addAppUserSubjectIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appUserSubjectIDsFlag, nil, "Filter tasks by app user subject id(s) (target of the task)")
}
func addUserSubjectIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(userSubjectIdsFlag, nil, "Filter tasks by user subject id(s) (c1 user target of the task)")
func addUserSubjectIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(userSubjectIDsFlag, nil, "Filter tasks by user subject id(s) (c1 user target of the task)")
}
func addAppApplicationIdsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appIdsFlag, nil, "Filter tasks by app application id(s) (target application of the task)")
func addAppApplicationIDsFlag(cmd *cobra.Command) {
cmd.Flags().StringSlice(appIDsFlag, nil, "Filter tasks by app application id(s) (target application of the task)")
}
func addAssigneesIds(cmd *cobra.Command) {
cmd.Flags().StringSlice(assigneeIdsFlag, nil, "Filter tasks by who is currently assigned to them")
func addAssigneesIDs(cmd *cobra.Command) {
cmd.Flags().StringSlice(assigneeIDsFlag, nil, "Filter tasks by who is currently assigned to them")
}

func addQueryTaskFlag(cmd *cobra.Command) {
Expand Down
32 changes: 16 additions & 16 deletions cmd/cone/task_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func searchTasksCmd() *cobra.Command {
RunE: searchTasksRun,
}

addAccessReviewIdsFlag(cmd)
addAppEntitlementIdsFlag(cmd)
addAppResourceIdsFlag(cmd)
addAppResourceTypeIdsFlag(cmd)
addAppUserSubjectIdsFlag(cmd)
addUserSubjectIdsFlag(cmd)
addAppApplicationIdsFlag(cmd)
addAssigneesIds(cmd)
addAccessReviewIDsFlag(cmd)
addAppEntitlementIDsFlag(cmd)
addAppResourceIDsFlag(cmd)
addAppResourceTypeIDsFlag(cmd)
addAppUserSubjectIDsFlag(cmd)
addUserSubjectIDsFlag(cmd)
addAppApplicationIDsFlag(cmd)
addAssigneesIDs(cmd)
addQueryTaskFlag(cmd)
addTaskStatesFlag(cmd)
addTaskTypesFlag(cmd)
Expand Down Expand Up @@ -80,18 +80,18 @@ func searchTasksRun(cmd *cobra.Command, args []string) error {
}

taskResp, err := c.SearchTasks(ctx, shared.TaskSearchRequestInput{
AccessReviewIds: v.GetStringSlice(accessReviewIdsFlag),
AppEntitlementIds: v.GetStringSlice(appEntitlementIdsFlag),
AppResourceIds: v.GetStringSlice(appResourceIdsFlag),
AppResourceTypeIds: v.GetStringSlice(appResourceTypeIdsFlag),
AppUserSubjectIds: v.GetStringSlice(appUserSubjectIdsFlag),
ApplicationIds: v.GetStringSlice(appIdsFlag),
AssigneesInIds: v.GetStringSlice(assigneeIdsFlag),
AccessReviewIds: v.GetStringSlice(accessReviewIDsFlag),
AppEntitlementIds: v.GetStringSlice(appEntitlementIDsFlag),
AppResourceIds: v.GetStringSlice(appResourceIDsFlag),
AppResourceTypeIds: v.GetStringSlice(appResourceTypeIDsFlag),
AppUserSubjectIds: v.GetStringSlice(appUserSubjectIDsFlag),
ApplicationIds: v.GetStringSlice(appIDsFlag),
AssigneesInIds: v.GetStringSlice(assigneeIDsFlag),
IncludeDeleted: includeDeleted,
Query: query,
TaskStates: state,
TaskTypes: taskTypes,
SubjectIds: v.GetStringSlice(userSubjectIdsFlag),
SubjectIds: v.GetStringSlice(userSubjectIDsFlag),
})
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions pkg/client/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"

"github.com/conductorone/conductorone-sdk-go/pkg/models/operations"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
)

Expand All @@ -12,9 +11,9 @@ func (c *client) ListPolicies(ctx context.Context) ([]shared.Policy, error) {
pageSize := float64(100)
pageToken := ""
for {
resp, err := c.sdk.Policies.List(ctx, operations.C1APIPolicyV1PoliciesListRequest{
PageToken: &pageToken,
resp, err := c.sdk.PolicySearch.Search(ctx, &shared.SearchPoliciesRequest{
PageSize: &pageSize,
PageToken: &pageToken,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 0f49af7

Please sign in to comment.