Skip to content

Commit

Permalink
fix(core): GOOS, error message fixes (#378)
Browse files Browse the repository at this point in the history
Resolves #377 
Resolves #376 
Resolves #380
  • Loading branch information
jakedoublev authored Sep 12, 2024
1 parent f7d5a1c commit 623a82a
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 105 deletions.
16 changes: 8 additions & 8 deletions cmd/kas-grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func policy_assignKasGrant(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

nsID := c.Flags.GetOptionalString("namespace-id")
attrID := c.Flags.GetOptionalString("attribute-id")
valID := c.Flags.GetOptionalString("value-id")
kasID := c.Flags.GetRequiredString("kas-id")
nsID := c.Flags.GetOptionalID("namespace-id")
attrID := c.Flags.GetOptionalID("attribute-id")
valID := c.Flags.GetOptionalID("value-id")
kasID := c.Flags.GetRequiredID("kas-id")

count := 0
for _, v := range []string{nsID, attrID, valID} {
Expand Down Expand Up @@ -76,10 +76,10 @@ func policy_unassignKasGrant(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

nsID := c.Flags.GetOptionalString("namespace-id")
attrID := c.Flags.GetOptionalString("attribute-id")
valID := c.Flags.GetOptionalString("value-id")
kasID := c.Flags.GetRequiredString("kas-id")
nsID := c.Flags.GetOptionalID("namespace-id")
attrID := c.Flags.GetOptionalID("attribute-id")
valID := c.Flags.GetOptionalID("value-id")
kasID := c.Flags.GetRequiredID("kas-id")
force := c.Flags.GetOptionalBool("force")

count := 0
Expand Down
6 changes: 3 additions & 3 deletions cmd/kas-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func policy_getKeyAccessRegistry(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.FlagHelper.GetRequiredString("id")
id := c.FlagHelper.GetRequiredID("id")

kas, err := h.GetKasRegistryEntry(id)
if err != nil {
Expand Down Expand Up @@ -156,7 +156,7 @@ func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
uri := c.Flags.GetOptionalString("uri")
cachedJSON := c.Flags.GetOptionalString("public-keys")
remote := c.Flags.GetOptionalString("public-key-remote")
Expand Down Expand Up @@ -208,7 +208,7 @@ func policy_deleteKeyAccessRegistry(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
force := c.Flags.GetOptionalBool("force")

kas, err := h.GetKasRegistryEntry(id)
Expand Down
12 changes: 6 additions & 6 deletions cmd/policy-attributeNamespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func policy_getAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
if err != nil {
Expand Down Expand Up @@ -105,7 +105,7 @@ func policy_deactivateAttributeNamespace(cmd *cobra.Command, args []string) {
defer h.Close()

force := c.Flags.GetOptionalBool("force")
id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
if err != nil {
Expand Down Expand Up @@ -138,7 +138,7 @@ func policy_updateAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

ns, err := h.UpdateNamespace(
Expand Down Expand Up @@ -166,7 +166,7 @@ func policy_unsafeDeleteAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
if err != nil {
Expand Down Expand Up @@ -199,7 +199,7 @@ func policy_unsafeReactivateAttributeNamespace(cmd *cobra.Command, args []string
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
if err != nil {
Expand Down Expand Up @@ -233,7 +233,7 @@ func policy_unsafeUpdateAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
name := c.Flags.GetRequiredString("name")

ns, err := h.GetNamespace(id)
Expand Down
16 changes: 8 additions & 8 deletions cmd/policy-attributeValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func policy_createAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

attrId := c.FlagHelper.GetRequiredString("attribute-id")
attrId := c.FlagHelper.GetRequiredID("attribute-id")
value := c.FlagHelper.GetRequiredString("value")
metadataLabels = c.FlagHelper.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

Expand All @@ -39,7 +39,7 @@ func policy_getAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.FlagHelper.GetRequiredString("id")
id := c.FlagHelper.GetRequiredID("id")

v, err := h.GetAttributeValue(id)
if err != nil {
Expand All @@ -53,7 +53,7 @@ func policy_listAttributeValue(cmd *cobra.Command, args []string) {
c := cli.New(cmd, args)
h := NewHandler(c)
defer h.Close()
attrId := c.FlagHelper.GetRequiredString("attribute-id")
attrId := c.FlagHelper.GetRequiredID("attribute-id")
state := cli.GetState(cmd)
vals, err := h.ListAttributeValues(attrId, state)
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func policy_updateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

_, err := h.GetAttributeValue(id)
Expand All @@ -109,7 +109,7 @@ func policy_deactivateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

value, err := h.GetAttributeValue(id)
if err != nil {
Expand All @@ -131,7 +131,7 @@ func policy_unsafeReactivateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

v, err := h.GetAttributeValue(id)
if err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func policy_unsafeUpdateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
value := c.Flags.GetOptionalString("value")

v, err := h.GetAttributeValue(id)
Expand Down Expand Up @@ -194,7 +194,7 @@ func policy_unsafeDeleteAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

v, err := h.GetAttributeValue(id)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/policy-attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func policy_getAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

attr, err := h.GetAttribute(id)
if err != nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func policy_deactivateAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

attr, err := h.GetAttribute(id)
if err != nil {
Expand Down Expand Up @@ -166,7 +166,7 @@ func policy_updateAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

if a, err := h.UpdateAttribute(id, getMetadataMutable(metadataLabels), getMetadataUpdateBehavior()); err != nil {
Expand All @@ -189,7 +189,7 @@ func policy_unsafeReactivateAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

a, err := h.GetAttribute(id)
if err != nil {
Expand Down Expand Up @@ -221,7 +221,7 @@ func policy_unsafeUpdateAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
name := c.Flags.GetOptionalString("name")
rule := c.Flags.GetOptionalString("rule")
valuesOrder = c.Flags.GetStringSlice("values-order", valuesOrder, cli.FlagsStringSliceOptions{})
Expand Down Expand Up @@ -267,7 +267,7 @@ func policy_unsafeDeleteAttribute(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

a, err := h.GetAttribute(id)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/policy-resourceMappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func policy_createResourceMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

attrId := c.Flags.GetRequiredString("attribute-value-id")
attrId := c.Flags.GetRequiredID("attribute-value-id")
terms = c.Flags.GetStringSlice("terms", terms, cli.FlagsStringSliceOptions{
Min: 1,
})
Expand Down Expand Up @@ -49,7 +49,7 @@ func policy_getResourceMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

resourceMapping, err := h.GetResourceMapping(id)
if err != nil {
Expand Down Expand Up @@ -109,8 +109,8 @@ func policy_updateResourceMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
attrValueId := c.Flags.GetOptionalString("attribute-value-id")
id := c.Flags.GetRequiredID("id")
attrValueId := c.Flags.GetOptionalID("attribute-value-id")
terms = c.Flags.GetStringSlice("terms", terms, cli.FlagsStringSliceOptions{})
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

Expand All @@ -136,7 +136,7 @@ func policy_deleteResourceMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

cli.ConfirmAction(cli.ActionDelete, "resource-mapping", id, false)

Expand Down
6 changes: 3 additions & 3 deletions cmd/policy-subjectConditionSets.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func policy_getSubjectConditionSet(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

scs, err := h.GetSubjectConditionSet(id)
if err != nil {
Expand Down Expand Up @@ -179,7 +179,7 @@ func policy_updateSubjectConditionSet(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})
ssFlagJSON := c.Flags.GetOptionalString("subject-sets")
ssFileJSON := c.Flags.GetOptionalString("subject-sets-file-json")
Expand Down Expand Up @@ -247,7 +247,7 @@ func policy_deleteSubjectConditionSet(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

scs, err := h.GetSubjectConditionSet(id)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/policy-subject_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func policy_getSubjectMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

mapping, err := h.GetSubjectMapping(id)
if err != nil {
Expand Down Expand Up @@ -112,11 +112,11 @@ func policy_createSubjectMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

attrValueId := c.Flags.GetRequiredString("attribute-value-id")
attrValueId := c.Flags.GetRequiredID("attribute-value-id")
actionsStandard = c.Flags.GetStringSlice("action-standard", actionsStandard, cli.FlagsStringSliceOptions{Min: 0})
actionsCustom = c.Flags.GetStringSlice("action-custom", actionsCustom, cli.FlagsStringSliceOptions{Min: 0})
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})
existingSCSId := c.Flags.GetOptionalString("subject-condition-set-id")
existingSCSId := c.Flags.GetOptionalID("subject-condition-set-id")
// NOTE: labels within a new Subject Condition Set created on a SM creation are not supported
newScsJSON := c.Flags.GetOptionalString("subject-condition-set-new")

Expand Down Expand Up @@ -184,7 +184,7 @@ func policy_deleteSubjectMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")

sm, err := h.GetSubjectMapping(id)
if err != nil {
Expand Down Expand Up @@ -212,10 +212,10 @@ func policy_updateSubjectMapping(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

id := c.Flags.GetRequiredString("id")
id := c.Flags.GetRequiredID("id")
actionsStandard = c.Flags.GetStringSlice("action-standard", actionsStandard, cli.FlagsStringSliceOptions{Min: 0})
actionsCustom = c.Flags.GetStringSlice("action-custom", actionsCustom, cli.FlagsStringSliceOptions{Min: 0})
scsId := c.Flags.GetOptionalString("subject-condition-set-id")
scsId := c.Flags.GetOptionalID("subject-condition-set-id")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

if len(actionsStandard) > 0 {
Expand Down
15 changes: 8 additions & 7 deletions cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import (
"github.com/spf13/cobra"
)

var (
runningInLinux = runtime.GOOS == "linux"
runningInTestMode = config.TestMode == "true"
)

var profileCmd = &cobra.Command{
Use: "profile",
Short: "Manage profiles (experimental)",
Use: "profile",
Short: "Manage profiles (experimental)",
Hidden: runningInLinux && !runningInTestMode,
}

var profileCreateCmd = &cobra.Command{
Expand Down Expand Up @@ -164,11 +170,6 @@ var profileSetEndpointCmd = &cobra.Command{
}

func init() {
// Profiles are not supported on Linux (unless mocked in test mode)
if runtime.GOOS == "linux" && config.TestMode != "true" {
return
}

profileCreateCmd.Flags().Bool("set-default", false, "Set the profile as default")
profileCreateCmd.Flags().Bool("tls-no-verify", false, "Disable TLS verification")

Expand Down
Loading

0 comments on commit 623a82a

Please sign in to comment.