mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-06 04:21:15 +00:00
PLTCONN-4069: Refactoring
This commit is contained in:
@@ -17,7 +17,7 @@ var accountCreateChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:account:create",
|
"std:account:create",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
input := map[string]interface{}{}
|
input := map[string]interface{}{}
|
||||||
_, _, err := cc.AccountCreate(ctx, nil, input, nil)
|
_, _, err := cc.AccountCreate(ctx, nil, input, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -34,7 +34,7 @@ var accountCreateChecks = []Check{
|
|||||||
"std:account:read",
|
"std:account:read",
|
||||||
"std:account:delete",
|
"std:account:delete",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
input := map[string]interface{}{}
|
input := map[string]interface{}{}
|
||||||
for _, field := range spec.AccountCreateTemplate.Fields {
|
for _, field := range spec.AccountCreateTemplate.Fields {
|
||||||
if field.Required {
|
if field.Required {
|
||||||
@@ -80,7 +80,7 @@ var accountCreateChecks = []Check{
|
|||||||
"std:account:read",
|
"std:account:read",
|
||||||
"std:account:delete",
|
"std:account:delete",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
input := map[string]interface{}{}
|
input := map[string]interface{}{}
|
||||||
for _, field := range spec.AccountCreateTemplate.Fields {
|
for _, field := range spec.AccountCreateTemplate.Fields {
|
||||||
input[getFieldName(field)] = genCreateField(field)
|
input[getFieldName(field)] = genCreateField(field)
|
||||||
@@ -125,7 +125,7 @@ var accountCreateChecks = []Check{
|
|||||||
"std:account:delete",
|
"std:account:delete",
|
||||||
"std:account:list",
|
"std:account:list",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
accountsPreCreate, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
accountsPreCreate, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.err(err)
|
res.err(err)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package connvalidate
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/kr/pretty"
|
"github.com/kr/pretty"
|
||||||
@@ -19,15 +20,23 @@ var accountReadChecks = []Check{
|
|||||||
"std:account:read",
|
"std:account:read",
|
||||||
"std:account:list",
|
"std:account:list",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
accounts, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
accounts, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.err(err)
|
res.err(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count := 0
|
if len(accounts) == 0 {
|
||||||
|
res.warnf("no entitlements")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rand.Shuffle(len(accounts), func(i, j int) {
|
||||||
|
accounts[i], accounts[j] = accounts[j], accounts[i]
|
||||||
|
})
|
||||||
|
count := int64(0)
|
||||||
for _, account := range accounts {
|
for _, account := range accounts {
|
||||||
if readLimit && count > accountReadLimit {
|
if count > readLimit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
acct, _, err := cc.AccountRead(ctx, account.ID(), account.UniqueID(), nil)
|
acct, _, err := cc.AccountRead(ctx, account.ID(), account.UniqueID(), nil)
|
||||||
@@ -59,7 +68,7 @@ var accountReadChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:account:read",
|
"std:account:read",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
_, _, err := cc.AccountRead(ctx, "__sailpoint__not__found__", "", nil)
|
_, _, err := cc.AccountRead(ctx, "__sailpoint__not__found__", "", nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res.errf("expected error for non-existant identity")
|
res.errf("expected error for non-existant identity")
|
||||||
@@ -73,7 +82,7 @@ var accountReadChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:account:list",
|
"std:account:list",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
additionalAttributes := map[string]string{}
|
additionalAttributes := map[string]string{}
|
||||||
|
|
||||||
attrsByName := map[string]connclient.AccountSchemaAttribute{}
|
attrsByName := map[string]connclient.AccountSchemaAttribute{}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var accountUpdateChecks = []Check{
|
|||||||
"std:account:list",
|
"std:account:list",
|
||||||
"std:account:update",
|
"std:account:update",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
accounts, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
accounts, _, _, err := cc.AccountList(ctx, nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.err(err)
|
res.err(err)
|
||||||
@@ -72,7 +72,7 @@ var accountUpdateChecks = []Check{
|
|||||||
"std:account:update",
|
"std:account:update",
|
||||||
"std:account:delete",
|
"std:account:delete",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
entitlementAttr := entitlementAttr(spec)
|
entitlementAttr := entitlementAttr(spec)
|
||||||
if entitlementAttr == "" {
|
if entitlementAttr == "" {
|
||||||
res.warnf("no entitlement attribute")
|
res.warnf("no entitlement attribute")
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type Check struct {
|
|||||||
|
|
||||||
// IsDataModifier determines a checking that will modify connectors data after applying
|
// IsDataModifier determines a checking that will modify connectors data after applying
|
||||||
IsDataModifier bool
|
IsDataModifier bool
|
||||||
Run func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool)
|
Run func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64)
|
||||||
// RequiredCommands represents a list of commands that use for this check
|
// RequiredCommands represents a list of commands that use for this check
|
||||||
RequiredCommands []string
|
RequiredCommands []string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package connvalidate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
"github.com/kr/pretty"
|
"github.com/kr/pretty"
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ var entitlementReadChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:entitlement:read",
|
"std:entitlement:read",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
_, _, err := cc.EntitlementRead(ctx, "__sailpoint__not__found__", "", "group", nil)
|
_, _, err := cc.EntitlementRead(ctx, "__sailpoint__not__found__", "", "group", nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res.errf("expected error for non-existant entitlement")
|
res.errf("expected error for non-existant entitlement")
|
||||||
@@ -32,7 +33,7 @@ var entitlementReadChecks = []Check{
|
|||||||
"std:entitlement:read",
|
"std:entitlement:read",
|
||||||
"std:entitlement:list",
|
"std:entitlement:list",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
entitlements, _, _, err := cc.EntitlementList(ctx, "group", nil, nil, nil)
|
entitlements, _, _, err := cc.EntitlementList(ctx, "group", nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.err(err)
|
res.err(err)
|
||||||
@@ -43,9 +44,14 @@ var entitlementReadChecks = []Check{
|
|||||||
res.warnf("no entitlements")
|
res.warnf("no entitlements")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
count := 0
|
|
||||||
|
rand.Shuffle(len(entitlements), func(i, j int) {
|
||||||
|
entitlements[i], entitlements[j] = entitlements[j], entitlements[i]
|
||||||
|
})
|
||||||
|
|
||||||
|
count := int64(0)
|
||||||
for _, e := range entitlements {
|
for _, e := range entitlements {
|
||||||
if readLimit && count > accountReadLimit {
|
if count > readLimit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
eRead, _, err := cc.EntitlementRead(ctx, e.ID(), e.UniqueID(), "group", nil)
|
eRead, _, err := cc.EntitlementRead(ctx, e.ID(), e.UniqueID(), "group", nil)
|
||||||
@@ -73,7 +79,7 @@ var entitlementReadChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:entitlement:list",
|
"std:entitlement:list",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
additionalAttributes := map[string]string{}
|
additionalAttributes := map[string]string{}
|
||||||
|
|
||||||
attrsByName := map[string]connclient.EntitlementSchemaAttribute{}
|
attrsByName := map[string]connclient.EntitlementSchemaAttribute{}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ var testConnChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:test-connection",
|
"std:test-connection",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
err := cc.TestConnectionWithConfig(ctx, json.RawMessage("{}"))
|
err := cc.TestConnectionWithConfig(ctx, json.RawMessage("{}"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res.errf("expected test-connection failure for empty config")
|
res.errf("expected test-connection failure for empty config")
|
||||||
@@ -29,7 +29,7 @@ var testConnChecks = []Check{
|
|||||||
RequiredCommands: []string{
|
RequiredCommands: []string{
|
||||||
"std:test-connection",
|
"std:test-connection",
|
||||||
},
|
},
|
||||||
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit bool) {
|
Run: func(ctx context.Context, spec *connclient.ConnSpec, cc *connclient.ConnClient, res *CheckResult, readLimit int64) {
|
||||||
_, err := cc.TestConnection(ctx)
|
_, err := cc.TestConnection(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.err(err)
|
res.err(err)
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import (
|
|||||||
connclient "github.com/sailpoint-oss/sailpoint-cli/cmd/connector/client"
|
connclient "github.com/sailpoint-oss/sailpoint-cli/cmd/connector/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
accountReadLimit = 8
|
|
||||||
)
|
|
||||||
|
|
||||||
// entitlementAttr returns the attribute for entitlements
|
// entitlementAttr returns the attribute for entitlements
|
||||||
func entitlementAttr(spec *connclient.ConnSpec) string {
|
func entitlementAttr(spec *connclient.ConnSpec) string {
|
||||||
for _, attr := range spec.AccountSchema.Attributes {
|
for _, attr := range spec.AccountSchema.Attributes {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ type Config struct {
|
|||||||
|
|
||||||
// ReadLimit specifies whether to limit the number of account read
|
// ReadLimit specifies whether to limit the number of account read
|
||||||
// If ReadLimit set 'true', check for account and entitlement read will only read 8 accounts
|
// If ReadLimit set 'true', check for account and entitlement read will only read 8 accounts
|
||||||
ReadLimit bool
|
ReadLimit int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewValidator creates a new validator with provided config and ConnClient
|
// NewValidator creates a new validator with provided config and ConnClient
|
||||||
|
|||||||
Reference in New Issue
Block a user