Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 7 additions & 7 deletions cmd/kas-grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func policy_assignKasGrant(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
nsID := c.Flags.GetOptionalID("namespace-id")
attrID := c.Flags.GetOptionalID("attribute-id")
valID := c.Flags.GetOptionalID("value-id")
Expand All @@ -40,12 +41,11 @@ func policy_assignKasGrant(cmd *cobra.Command, args []string) {
rowID []string
)

kas, err := h.GetKasRegistryEntry(kasID)
kas, err := h.GetKasRegistryEntry(ctx, kasID)
if err != nil || kas == nil {
cli.ExitWithError("Failed to get registered KAS", err)
}

ctx := cmd.Context()
//nolint:gocritic,nestif // this is more readable than a switch statement
if nsID != "" {
res, err = h.AssignKasGrantToNamespace(ctx, nsID, kasID)
Expand Down Expand Up @@ -76,6 +76,7 @@ func policy_unassignKasGrant(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
nsID := c.Flags.GetOptionalID("namespace-id")
attrID := c.Flags.GetOptionalID("attribute-id")
valID := c.Flags.GetOptionalID("value-id")
Expand All @@ -99,16 +100,15 @@ func policy_unassignKasGrant(cmd *cobra.Command, args []string) {
rowFQN []string
)

kas, err := h.GetKasRegistryEntry(kasID)
kas, err := h.GetKasRegistryEntry(ctx, kasID)
if err != nil || kas == nil {
cli.ExitWithError("Failed to get registered KAS", err)
}
kasURI := kas.GetUri()

ctx := cmd.Context()
//nolint:gocritic,nestif // this is more readable than a switch statement
if nsID != "" {
ns, err := h.GetNamespace(nsID)
ns, err := h.GetNamespace(ctx, nsID)
if err != nil || ns == nil {
cli.ExitWithError("Failed to get namespace definition", err)
}
Expand All @@ -122,7 +122,7 @@ func policy_unassignKasGrant(cmd *cobra.Command, args []string) {
rowID = []string{"Namespace ID", nsID}
rowFQN = []string{"Namespace FQN", ns.GetFqn()}
} else if attrID != "" {
attr, err := h.GetAttribute(attrID)
attr, err := h.GetAttribute(ctx, attrID)
if err != nil || attr == nil {
cli.ExitWithError("Failed to get attribute definition", err)
}
Expand All @@ -136,7 +136,7 @@ func policy_unassignKasGrant(cmd *cobra.Command, args []string) {
rowID = []string{"Attribute ID", attrID}
rowFQN = []string{"Attribute FQN", attr.GetFqn()}
} else {
val, err := h.GetAttributeValue(valID)
val, err := h.GetAttributeValue(ctx, valID)
if err != nil || val == nil {
cli.ExitWithError("Failed to get attribute value", err)
}
Expand Down
11 changes: 7 additions & 4 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) {

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

kas, err := h.GetKasRegistryEntry(id)
kas, err := h.GetKasRegistryEntry(cmd.Context(), id)
if err != nil {
errMsg := fmt.Sprintf("Failed to get Registered KAS entry (%s)", id)
cli.ExitWithError(errMsg, err)
Expand Down Expand Up @@ -60,7 +60,7 @@ func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) {
limit := c.Flags.GetRequiredInt32("limit")
offset := c.Flags.GetRequiredInt32("offset")

list, page, err := h.ListKasRegistryEntries(limit, offset)
list, page, err := h.ListKasRegistryEntries(cmd.Context(), limit, offset)
if err != nil {
cli.ExitWithError("Failed to list Registered KAS entries", err)
}
Expand Down Expand Up @@ -120,6 +120,7 @@ func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) {
}

created, err := h.CreateKasRegistryEntry(
cmd.Context(),
uri,
key,
name,
Expand Down Expand Up @@ -177,6 +178,7 @@ func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
}

updated, err := h.UpdateKasRegistryEntry(
cmd.Context(),
id,
uri,
name,
Expand Down Expand Up @@ -208,18 +210,19 @@ func policy_deleteKeyAccessRegistry(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")
force := c.Flags.GetOptionalBool("force")

kas, err := h.GetKasRegistryEntry(id)
kas, err := h.GetKasRegistryEntry(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to get Registered KAS entry (%s)", id)
cli.ExitWithError(errMsg, err)
}

cli.ConfirmAction(cli.ActionDelete, "Registered KAS", id, force)

if _, err := h.DeleteKasRegistryEntry(id); err != nil {
if _, err := h.DeleteKasRegistryEntry(ctx, id); err != nil {
errMsg := fmt.Sprintf("Failed to delete Registered KAS entry (%s)", id)
cli.ExitWithError(errMsg, err)
}
Expand Down
27 changes: 16 additions & 11 deletions cmd/policy-attributeNamespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func policy_getAttributeNamespace(cmd *cobra.Command, args []string) {

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

ns, err := h.GetNamespace(id)
ns, err := h.GetNamespace(cmd.Context(), id)
if err != nil {
errMsg := fmt.Sprintf("Failed to get namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -48,7 +48,7 @@ func policy_listAttributeNamespaces(cmd *cobra.Command, args []string) {
limit := c.Flags.GetRequiredInt32("limit")
offset := c.Flags.GetRequiredInt32("offset")

list, page, err := h.ListNamespaces(state, limit, offset)
list, page, err := h.ListNamespaces(cmd.Context(), state, limit, offset)
if err != nil {
cli.ExitWithError("Failed to list namespaces", err)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func policy_createAttributeNamespace(cmd *cobra.Command, args []string) {
name := c.Flags.GetRequiredString("name")
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

created, err := h.CreateNamespace(name, getMetadataMutable(metadataLabels))
created, err := h.CreateNamespace(cmd.Context(), name, getMetadataMutable(metadataLabels))
if err != nil {
cli.ExitWithError("Failed to create namespace", err)
}
Expand All @@ -108,18 +108,19 @@ func policy_deactivateAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
force := c.Flags.GetOptionalBool("force")
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
ns, err := h.GetNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to find namespace (%s)", id)
cli.ExitWithError(errMsg, err)
}

cli.ConfirmAction(cli.ActionDeactivate, "namespace", ns.GetName(), force)

d, err := h.DeactivateNamespace(id)
d, err := h.DeactivateNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to deactivate namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -144,6 +145,7 @@ func policy_updateAttributeNamespace(cmd *cobra.Command, args []string) {
metadataLabels = c.Flags.GetStringSlice("label", metadataLabels, cli.FlagsStringSliceOptions{Min: 0})

ns, err := h.UpdateNamespace(
cmd.Context(),
id,
getMetadataMutable(metadataLabels),
getMetadataUpdateBehavior(),
Expand All @@ -168,9 +170,10 @@ func policy_unsafeDeleteAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
ns, err := h.GetNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to find namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -180,7 +183,7 @@ func policy_unsafeDeleteAttributeNamespace(cmd *cobra.Command, args []string) {
cli.ConfirmTextInput(cli.ActionDelete, "namespace", cli.InputNameFQN, ns.GetFqn())
}

if err := h.UnsafeDeleteNamespace(id, ns.GetFqn()); err != nil {
if err := h.UnsafeDeleteNamespace(ctx, id, ns.GetFqn()); err != nil {
errMsg := fmt.Sprintf("Failed to delete namespace (%s)", id)
cli.ExitWithError(errMsg, err)
}
Expand All @@ -201,9 +204,10 @@ func policy_unsafeReactivateAttributeNamespace(cmd *cobra.Command, args []string
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")

ns, err := h.GetNamespace(id)
ns, err := h.GetNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to find namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -213,7 +217,7 @@ func policy_unsafeReactivateAttributeNamespace(cmd *cobra.Command, args []string
cli.ConfirmTextInput(cli.ActionReactivate, "namespace", cli.InputNameFQN, ns.GetFqn())
}

ns, err = h.UnsafeReactivateNamespace(id)
ns, err = h.UnsafeReactivateNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to reactivate namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -235,10 +239,11 @@ func policy_unsafeUpdateAttributeNamespace(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

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

ns, err := h.GetNamespace(id)
ns, err := h.GetNamespace(ctx, id)
if err != nil {
errMsg := fmt.Sprintf("Failed to find namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand All @@ -248,7 +253,7 @@ func policy_unsafeUpdateAttributeNamespace(cmd *cobra.Command, args []string) {
cli.ConfirmTextInput(cli.ActionUpdateUnsafe, "namespace", cli.InputNameFQNUpdated, ns.GetFqn())
}

ns, err = h.UnsafeUpdateNamespace(id, name)
ns, err = h.UnsafeUpdateNamespace(ctx, id, name)
if err != nil {
errMsg := fmt.Sprintf("Failed to reactivate namespace (%s)", id)
cli.ExitWithError(errMsg, err)
Expand Down
34 changes: 20 additions & 14 deletions cmd/policy-attributeValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ func policy_createAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

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

attr, err := h.GetAttribute(attrId)
attr, err := h.GetAttribute(ctx, attrId)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get parent attribute (%s)", attrId), err)
}

v, err := h.CreateAttributeValue(attr.GetId(), value, getMetadataMutable(metadataLabels))
v, err := h.CreateAttributeValue(ctx, attr.GetId(), value, getMetadataMutable(metadataLabels))
if err != nil {
cli.ExitWithError("Failed to create attribute value", err)
}
Expand All @@ -41,7 +42,7 @@ func policy_getAttributeValue(cmd *cobra.Command, args []string) {

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

v, err := h.GetAttributeValue(id)
v, err := h.GetAttributeValue(cmd.Context(), id)
if err != nil {
cli.ExitWithError("Failed to find attribute value", err)
}
Expand All @@ -59,7 +60,7 @@ func policy_listAttributeValue(cmd *cobra.Command, args []string) {
limit := c.Flags.GetRequiredInt32("limit")
offset := c.Flags.GetRequiredInt32("offset")

vals, page, err := h.ListAttributeValues(attrId, state, limit, offset)
vals, page, err := h.ListAttributeValues(cmd.Context(), attrId, state, limit, offset)
if err != nil {
cli.ExitWithError("Failed to list attribute values", err)
}
Expand Down Expand Up @@ -93,15 +94,16 @@ func policy_updateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

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

_, err := h.GetAttributeValue(id)
_, err := h.GetAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get attribute value (%s)", id), err)
}

v, err := h.UpdateAttributeValue(id, getMetadataMutable(metadataLabels), getMetadataUpdateBehavior())
v, err := h.UpdateAttributeValue(ctx, id, getMetadataMutable(metadataLabels), getMetadataUpdateBehavior())
if err != nil {
cli.ExitWithError("Failed to update attribute value", err)
}
Expand All @@ -114,16 +116,17 @@ func policy_deactivateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")

value, err := h.GetAttributeValue(id)
value, err := h.GetAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get attribute value (%s)", id), err)
}

cli.ConfirmAction(cli.ActionDeactivate, "attribute value", value.GetValue(), false)

deactivated, err := h.DeactivateAttributeValue(id)
deactivated, err := h.DeactivateAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError("Failed to deactivate attribute value", err)
}
Expand All @@ -136,9 +139,10 @@ func policy_unsafeReactivateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")

v, err := h.GetAttributeValue(id)
v, err := h.GetAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get attribute value (%s)", id), err)
}
Expand All @@ -147,7 +151,7 @@ func policy_unsafeReactivateAttributeValue(cmd *cobra.Command, args []string) {
cli.ConfirmTextInput(cli.ActionReactivate, "attribute value", cli.InputNameFQN, v.GetFqn())
}

if reactivated, err := h.UnsafeReactivateAttributeValue(id); err != nil {
if reactivated, err := h.UnsafeReactivateAttributeValue(ctx, id); err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to reactivate attribute value (%s)", id), err)
} else {
rows := [][]string{
Expand All @@ -167,10 +171,11 @@ func policy_unsafeUpdateAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")
value := c.Flags.GetOptionalString("value")

v, err := h.GetAttributeValue(id)
v, err := h.GetAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get attribute value (%s)", id), err)
}
Expand All @@ -179,7 +184,7 @@ func policy_unsafeUpdateAttributeValue(cmd *cobra.Command, args []string) {
cli.ConfirmTextInput(cli.ActionUpdateUnsafe, "attribute value", cli.InputNameFQN, v.GetFqn())
}

if err := h.UnsafeUpdateAttributeValue(id, value); err != nil {
if err := h.UnsafeUpdateAttributeValue(ctx, id, value); err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to update attribute value (%s)", id), err)
} else {
rows := [][]string{
Expand All @@ -199,9 +204,10 @@ func policy_unsafeDeleteAttributeValue(cmd *cobra.Command, args []string) {
h := NewHandler(c)
defer h.Close()

ctx := cmd.Context()
id := c.Flags.GetRequiredID("id")

v, err := h.GetAttributeValue(id)
v, err := h.GetAttributeValue(ctx, id)
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to get attribute value (%s)", id), err)
}
Expand All @@ -210,7 +216,7 @@ func policy_unsafeDeleteAttributeValue(cmd *cobra.Command, args []string) {
cli.ConfirmTextInput(cli.ActionDelete, "attribute value", cli.InputNameFQN, v.GetFqn())
}

if err := h.UnsafeDeleteAttributeValue(id, v.GetFqn()); err != nil {
if err := h.UnsafeDeleteAttributeValue(ctx, id, v.GetFqn()); err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to delete attribute (%s)", id), err)
} else {
rows := [][]string{
Expand Down
Loading
Loading