From 69b7792e4b7788ae82d653b64b1e0d68b91729a8 Mon Sep 17 00:00:00 2001 From: Jake Van Vorhis <83739412+jakedoublev@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:31:56 -0700 Subject: [PATCH] feat(core): enable styled and json default outputs (#66) 1. Adds a `tructl.yaml` config to drive things like global CLI output format 2. Adds global command `tructl config output --format <'json' | 'styled'>` that updates the config file 3. Maintains support for global command `--json` to output a single run of the CLI as json but not overwrite the config 4. Reads the `--json` and config for output format 5. Unifies success handling throughout all existing policy flows to print styled output or JSON as applicable Closes https://github.com/opentdf/tructl/issues/30 --- README.md | 4 +- cmd/config.go | 46 +++++++ cmd/dev.go | 18 ++- cmd/policy-attributes.go | 66 +++++----- cmd/policy-namespaces.go | 53 ++++---- cmd/policy-resourceMappings.go | 176 ------------------------- cmd/policy-resource_mappings.go | 189 ++++++++++++++++++++++++++ cmd/policy-subject_mappings.go | 135 +++++++------------ cmd/root.go | 19 ++- go.mod | 55 +++++--- go.sum | 90 +++++++++++++ internal/config/config.go | 89 +++++++++++++ pkg/cli/sdkHelpers.go | 4 +- pkg/cli/tabular.go | 3 + pkg/handlers/attribute.go | 41 +++--- pkg/handlers/attribute_values.go | 7 +- pkg/handlers/kas-registry.go | 9 +- pkg/handlers/namespaces.go | 12 +- pkg/handlers/resourceMappings.go | 26 ++-- pkg/handlers/sdk.go | 9 +- pkg/handlers/subjectmappings.go | 220 +++++++++++++++---------------- tructl.yaml | 2 + tui/form/addAttribute.go | 12 +- 23 files changed, 743 insertions(+), 542 deletions(-) create mode 100644 cmd/config.go delete mode 100644 cmd/policy-resourceMappings.go create mode 100644 cmd/policy-resource_mappings.go create mode 100644 internal/config/config.go create mode 100644 tructl.yaml diff --git a/README.md b/README.md index 483766ad..8145d4f9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ The main goals are to: ## TODO list -- [ ] Add support for `--json` persistent flag - [ ] Add support for json input as piped input - [ ] Add help level handler for each command - [ ] Add support for `--verbose` persistent flag @@ -28,13 +27,14 @@ The CLI is built using [cobra](https://cobra.dev/). The primary function is to support CRUD operations using commands as arguments and flags as the values. +The output format (currently `styled` or `json`) is configurable in the `tructl.yaml` or via CLI flag. + #### To add a command 1. Capture the flag value and validate the values 1. Alt support JSON input as piped input 2. Run the handler which is located in `pkg/handlers` and pass the values as arguments 3. Handle any errors and return the result in a lite TUI format - 1. Alt support JSON output when `--json` flag is passed ### TUI diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 00000000..6f663b54 --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "fmt" + + "github.com/opentdf/tructl/internal/config" + "github.com/opentdf/tructl/pkg/cli" + "github.com/spf13/cobra" +) + +// configCmd is the command for managing configuration +var configCmd = &cobra.Command{ + Use: "config", + Short: "Manage configuration", + Long: ` +Manage configuration within 'tructl'. + +Configuration is used to manage the configuration of the 'tructl' command line tool and updates the +config .yaml file in the root directory when changes have been made. +`, +} + +var updateOutputFormatCmd = &cobra.Command{ + Use: "output", + Short: "Define the configured output format", + Long: ` +Define the configured output format for the 'tructl' command line tool. The only supported outputs at +this time are 'json' and styled CLI output, which is the default when unspecified. +`, + Run: func(cmd *cobra.Command, args []string) { + h := cli.NewHandler(cmd) + defer h.Close() + + flagHelper := cli.NewFlagHelper(cmd) + format := flagHelper.GetRequiredString("format") + + config.UpdateOutputFormat(format) + fmt.Println(cli.SuccessMessage(fmt.Sprintf("Output format updated to %s", format))) + }, +} + +func init() { + updateOutputFormatCmd.Flags().String("format", "", "'json' or 'styled' as the configured output format") + configCmd.AddCommand(updateOutputFormatCmd) + rootCmd.AddCommand(configCmd) +} diff --git a/cmd/dev.go b/cmd/dev.go index a988d8fa..b96f7c44 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -4,7 +4,9 @@ import ( "encoding/json" "fmt" + "github.com/charmbracelet/lipgloss/table" "github.com/opentdf/platform/protocol/go/common" + "github.com/opentdf/tructl/internal/config" "github.com/opentdf/tructl/pkg/cli" "github.com/spf13/cobra" ) @@ -59,9 +61,6 @@ func getMetadataRows(m *common.Metadata) [][]string { } metadataRows = append(metadataRows, []string{"Labels", cli.CommaSeparated(labelRows)}) } - if m.Description != "" { - metadataRows = append(metadataRows, []string{"Description", m.Description}) - } return metadataRows } return nil @@ -78,6 +77,19 @@ func unMarshalMetadata(m string) *common.MetadataMutable { return nil } +// HandleSuccess prints a success message according to the configured format (styled table or JSON) +func HandleSuccess(command *cobra.Command, id string, t *table.Table, policyObject interface{}) { + if TructlCfg.Output.Format == config.OutputJSON || configFlagOverrides.OutputFormatJSON { + if output, err := json.MarshalIndent(policyObject, "", " "); err != nil { + cli.ExitWithError("Error marshalling policy object", err) + } else { + fmt.Println(string(output)) + } + return + } + cli.PrintSuccessTable(command, id, t) +} + func init() { rootCmd.AddCommand(devCmd) devCmd.AddCommand(designCmd) diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index b2b22ac3..b75eb25c 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/opentdf/platform/protocol/go/policy/attributes" + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/tructl/pkg/cli" "github.com/spf13/cobra" ) @@ -51,7 +51,7 @@ used to define the access controls based on subject encodings and entity entitle } // create attribute values - attrValues := make([]*attributes.Value, 0, len(values)) + attrValues := make([]*policy.Value, 0, len(values)) valueErrors := make(map[string]error) for _, value := range values { v, err := h.CreateAttributeValue(attr.Id, value) @@ -61,7 +61,7 @@ used to define the access controls based on subject encodings and entity entitle attrValues = append(attrValues, v) } - a := cli.GetSimpleAttribute(&attributes.Attribute{ + a := cli.GetSimpleAttribute(&policy.Attribute{ Id: attr.Id, Name: attr.Name, Rule: attr.Rule, @@ -69,15 +69,12 @@ used to define the access controls based on subject encodings and entity entitle Namespace: attr.Namespace, }) - fmt.Println(cli.SuccessMessage("Attribute created")) - fmt.Println( - cli.NewTabular().Rows([][]string{ - {"Name", a.Name}, - {"Rule", a.Rule}, - {"Values", cli.CommaSeparated(a.Values)}, - {"Namespace", a.Namespace}, - }...).Render(), - ) + t := cli.NewTabular().Rows([][]string{ + {"Name", a.Name}, + {"Rule", a.Rule}, + {"Values", cli.CommaSeparated(a.Values)}, + {"Namespace", a.Namespace}, + }...) if len(valueErrors) > 0 { fmt.Println(cli.ErrorMessage("Error creating attribute values", nil)) @@ -85,6 +82,7 @@ used to define the access controls based on subject encodings and entity entitle cli.ErrorMessage(value, err) } } + HandleSuccess(cmd, a.Id, t, a) }, } @@ -107,17 +105,15 @@ used to define the access controls based on subject encodings and entity entitle } a := cli.GetSimpleAttribute(attr) - fmt.Println(cli.SuccessMessage("Attribute found")) - fmt.Println( - cli.NewTabular(). - Rows([][]string{ - {"Id", a.Id}, - {"Name", a.Name}, - {"Rule", a.Rule}, - {"Values", cli.CommaSeparated(a.Values)}, - {"Namespace", a.Namespace}, - }...).Render(), - ) + t := cli.NewTabular(). + Rows([][]string{ + {"Id", a.Id}, + {"Name", a.Name}, + {"Rule", a.Rule}, + {"Values", cli.CommaSeparated(a.Values)}, + {"Namespace", a.Namespace}, + }...) + HandleSuccess(cmd, a.Id, t, a) }, } @@ -146,7 +142,7 @@ used to define the access controls based on subject encodings and entity entitle cli.CommaSeparated(a.Values), ) } - fmt.Println(t.Render()) + HandleSuccess(cmd, "", t, attrs) }, } @@ -177,16 +173,14 @@ used to define the access controls based on subject encodings and entity entitle } a := cli.GetSimpleAttribute(attr) - fmt.Println(cli.SuccessMessage("Attribute deactivated")) - fmt.Println( - cli.NewTabular(). - Rows([][]string{ - {"Name", a.Name}, - {"Rule", a.Rule}, - {"Values", cli.CommaSeparated(a.Values)}, - {"Namespace", a.Namespace}, - }...).Render(), - ) + t := cli.NewTabular(). + Rows([][]string{ + {"Name", a.Name}, + {"Rule", a.Rule}, + {"Values", cli.CommaSeparated(a.Values)}, + {"Namespace", a.Namespace}, + }...) + HandleSuccess(cmd, a.Id, t, a) }, } @@ -201,10 +195,10 @@ used to define the access controls based on subject encodings and entity entitle flagHelper := cli.NewFlagHelper(cmd) id := flagHelper.GetRequiredString("id") - if _, err := h.UpdateAttribute(id); err != nil { + if a, err := h.UpdateAttribute(id); err != nil { cli.ExitWithError("Could not update attribute", err) } else { - fmt.Println(cli.SuccessMessage(fmt.Sprintf("Attribute id: %s updated.", id))) + HandleSuccess(cmd, id, nil, a) } }, } diff --git a/cmd/policy-namespaces.go b/cmd/policy-namespaces.go index 0b093e47..dfc0d268 100644 --- a/cmd/policy-namespaces.go +++ b/cmd/policy-namespaces.go @@ -46,14 +46,12 @@ or different attributes tied to each. cli.ExitWithError(errMsg, err) } - fmt.Println(cli.SuccessMessage("Namespace found")) - fmt.Println( - cli.NewTabular(). - Rows([][]string{ - {"Id", ns.Id}, - {"Name", ns.Name}, - }...).Render(), - ) + t := cli.NewTabular(). + Rows([][]string{ + {"Id", ns.Id}, + {"Name", ns.Name}, + }...) + HandleSuccess(cmd, ns.Id, t, ns) }, } @@ -77,7 +75,7 @@ or different attributes tied to each. ns.Name, ) } - fmt.Println(t.Render()) + HandleSuccess(cmd, "", t, list) }, } @@ -96,13 +94,11 @@ or different attributes tied to each. cli.ExitWithError("Could not create namespace", err) } - fmt.Println(cli.SuccessMessage("Namespace created")) - fmt.Println( - cli.NewTabular().Rows([][]string{ - {"Name", name}, - {"Id", created.Id}, - }...).Render(), - ) + t := cli.NewTabular().Rows([][]string{ + {"Name", name}, + {"Id", created.Id}, + }...) + HandleSuccess(cmd, created.Id, t, created) }, } @@ -131,14 +127,12 @@ or different attributes tied to each. cli.ExitWithError(errMsg, err) } - fmt.Println(cli.SuccessMessage("Namespace deactivated")) - fmt.Println( - cli.NewTabular(). - Rows([][]string{ - {"Id", ns.Id}, - {"Name", ns.Name}, - }...).Render(), - ) + t := cli.NewTabular(). + Rows([][]string{ + {"Id", ns.Id}, + {"Name", ns.Name}, + }...) + HandleSuccess(cmd, ns.Id, t, ns) }, } @@ -155,13 +149,18 @@ or different attributes tied to each. id := flagHelper.GetRequiredString("id") name := flagHelper.GetRequiredString("name") - if _, err := h.UpdateNamespace( + ns, err := h.UpdateNamespace( id, name, - ); err != nil { + ) + if err != nil { cli.ExitWithError("Could not update namespace", err) } - fmt.Println(cli.SuccessMessage(fmt.Sprintf("Namespace id: (%s) updated. Name set to (%s).", id, name))) + t := cli.NewTabular().Rows([][]string{ + {"Id", ns.Id}, + {"Name", ns.Name}, + }...) + HandleSuccess(cmd, id, t, ns) }, } ) diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go deleted file mode 100644 index 97a63b5e..00000000 --- a/cmd/policy-resourceMappings.go +++ /dev/null @@ -1,176 +0,0 @@ -package cmd - -import ( - _ "embed" - "fmt" - "strings" - - "github.com/opentdf/tructl/docs/man" - "github.com/opentdf/tructl/pkg/cli" - "github.com/spf13/cobra" -) - -var ( - policy_resourceMappingsTerms []string - - policy_resourceMappingsCmd = &cobra.Command{ - Use: man.PolicyResourceMappings["en"].Command, - Aliases: man.PolicyResourceMappings["en"].Aliases, - Short: man.PolicyResourceMappings["en"].ShortWithSubCommands([]string{ - policy_resourceMappingsCreateCmd.Use, - policy_resourceMappingsGetCmd.Use, - policy_resourceMappingsListCmd.Use, - policy_resourceMappingsUpdateCmd.Use, - policy_resourceMappingsDeleteCmd.Use, - }), - Long: man.PolicyResourceMappings["en"].Long, - } - - policy_resourceMappingsCreateCmd = &cobra.Command{ - Use: "create", - Short: "Create resource mappings", - Run: func(cmd *cobra.Command, args []string) { - h := cli.NewHandler(cmd) - defer h.Close() - - flagHelper := cli.NewFlagHelper(cmd) - attrId := flagHelper.GetRequiredString("attribute-value-id") - terms := flagHelper.GetStringSlice("terms", policy_resourceMappingsTerms, cli.FlagHelperStringSliceOptions{ - Min: 1, - }) - - resourceMapping, err := h.CreateResourceMapping(attrId, terms) - if err != nil { - cli.ExitWithError("Failed to create resource mapping", err) - } - - fmt.Println(cli.SuccessMessage("Resource mapping created")) - fmt.Println(cli.NewTabular().Rows([][]string{ - {"Id", resourceMapping.Id}, - {"Attribute Id", resourceMapping.AttributeValue.AttributeId}, - {"Attribute Value", resourceMapping.AttributeValue.Value}, - {"Terms", strings.Join(resourceMapping.Terms, ", ")}, - }...).Render()) - }, - } - - policy_resourceMappingsGetCmd = &cobra.Command{ - Use: "get", - Short: "Get resource mappings", - Run: func(cmd *cobra.Command, args []string) { - h := cli.NewHandler(cmd) - defer h.Close() - - flagHelper := cli.NewFlagHelper(cmd) - id := flagHelper.GetRequiredString("id") - - resourceMapping, err := h.GetResourceMapping(id) - if err != nil { - cli.ExitWithError("Failed to get resource mapping", err) - } - - fmt.Println(cli.NewTabular().Rows([][]string{ - {"Id", resourceMapping.Id}, - {"Attribute Id", resourceMapping.AttributeValue.AttributeId}, - {"Attribute Value", resourceMapping.AttributeValue.Value}, - {"Terms", strings.Join(resourceMapping.Terms, ", ")}, - }...).Render()) - }, - } - - policy_resourceMappingsListCmd = &cobra.Command{ - Use: "list", - Short: "List resource mappings", - Run: func(cmd *cobra.Command, args []string) { - h := cli.NewHandler(cmd) - defer h.Close() - - r, err := h.ListResourceMappings() - if err != nil { - cli.ExitWithError("Failed to list resource mappings", err) - } - - t := cli.NewTable() - t.Headers("Id", "Attribute Id", "Attribute Value", "Terms") - for _, resourceMapping := range r { - t.Row(resourceMapping.Id, resourceMapping.AttributeValue.AttributeId, resourceMapping.AttributeValue.Value, strings.Join(resourceMapping.Terms, ", ")) - } - fmt.Println(t.Render()) - }, - } - - policy_resourceMappingsUpdateCmd = &cobra.Command{ - Use: "update", - Short: "Update resource mappings", - Run: func(cmd *cobra.Command, args []string) { - h := cli.NewHandler(cmd) - defer h.Close() - - flagHelper := cli.NewFlagHelper(cmd) - id := flagHelper.GetRequiredString("id") - attrValueId := flagHelper.GetOptionalString("attribute-value-id") - terms := flagHelper.GetStringSlice("terms", policy_resourceMappingsTerms, cli.FlagHelperStringSliceOptions{}) - - resourceMapping, err := h.UpdateResourceMapping(id, attrValueId, terms) - if err != nil { - cli.ExitWithError("Failed to update resource mapping", err) - } - - fmt.Println(cli.SuccessMessage("Resource mapping updated")) - fmt.Println(cli.NewTabular().Rows([][]string{ - {"Id", resourceMapping.Id}, - {"Attribute Id", resourceMapping.AttributeValue.AttributeId}, - {"Attribute Value", resourceMapping.AttributeValue.Value}, - {"Terms", strings.Join(resourceMapping.Terms, ", ")}, - }...).Render()) - }, - } - - policy_resourceMappingsDeleteCmd = &cobra.Command{ - Use: "delete", - Short: "Delete resource mappings", - Run: func(cmd *cobra.Command, args []string) { - h := cli.NewHandler(cmd) - defer h.Close() - - flagHelper := cli.NewFlagHelper(cmd) - id := flagHelper.GetRequiredString("id") - - cli.ConfirmDelete("resource-mapping", id) - - resourceMapping, err := h.DeleteResourceMapping(id) - if err != nil { - cli.ExitWithError("Failed to delete resource mapping", err) - } - - fmt.Println(cli.SuccessMessage("Resource mapping deleted")) - fmt.Println(cli.NewTabular().Rows([][]string{ - {"Id", resourceMapping.Id}, - {"Attribute Id", resourceMapping.AttributeValue.AttributeId}, - {"Attribute Value", resourceMapping.AttributeValue.Value}, - {"Terms", strings.Join(resourceMapping.Terms, ", ")}, - }...).Render()) - }, - } -) - -func init() { - policyCmd.AddCommand(policy_resourceMappingsCmd) - - policy_resourceMappingsCmd.AddCommand(policy_resourceMappingsCreateCmd) - policy_resourceMappingsCreateCmd.Flags().String("attribute-value-id", "", "Attribute Value ID") - policy_resourceMappingsCreateCmd.Flags().StringSliceVar(&policy_resourceMappingsTerms, "terms", []string{}, "Synonym terms") - - policy_resourceMappingsCmd.AddCommand(policy_resourceMappingsGetCmd) - policy_resourceMappingsGetCmd.Flags().String("id", "", "Resource Mapping ID") - - policy_resourceMappingsCmd.AddCommand(policy_resourceMappingsListCmd) - - policy_resourceMappingsCmd.AddCommand(policy_resourceMappingsUpdateCmd) - policy_resourceMappingsUpdateCmd.Flags().String("id", "", "Resource Mapping ID") - policy_resourceMappingsUpdateCmd.Flags().String("attribute-value-id", "", "Attribute Value ID") - policy_resourceMappingsUpdateCmd.Flags().StringSliceVar(&policy_resourceMappingsTerms, "terms", []string{}, "Synonym terms") - - policy_resourceMappingsCmd.AddCommand(policy_resourceMappingsDeleteCmd) - policy_resourceMappingsDeleteCmd.Flags().String("id", "", "Resource Mapping ID") -} diff --git a/cmd/policy-resource_mappings.go b/cmd/policy-resource_mappings.go new file mode 100644 index 00000000..2dd38527 --- /dev/null +++ b/cmd/policy-resource_mappings.go @@ -0,0 +1,189 @@ +package cmd + +import ( + _ "embed" +) + +// TODO: add metadata to outputs once [https://github.com/opentdf/tructl/issues/30] is addressed + +var ( +// policy_resource_mappingsTerms []string + +// policy_resource_mappingsCmd = &cobra.Command{ +// Use: man.PolicyResourceMappings["en"].Command, +// Aliases: man.PolicyResourceMappings["en"].Aliases, +// Short: man.PolicyResourceMappings["en"].ShortWithSubCommands([]string{ +// policy_resource_mappingsCreateCmd.Use, +// policy_resource_mappingsGetCmd.Use, +// policy_resource_mappingsListCmd.Use, +// policy_resource_mappingsUpdateCmd.Use, +// policy_resource_mappingsDeleteCmd.Use, +// }), +// Long: man.PolicyResourceMappings["en"].Long, +// } + +// policy_resource_mappingsCreateCmd = &cobra.Command{ +// Use: "create", +// Short: "Create resource mappings", +// Run: func(cmd *cobra.Command, args []string) { +// h := cli.NewHandler(cmd) +// defer h.Close() + +// flagHelper := cli.NewFlagHelper(cmd) +// attrId := flagHelper.GetRequiredString("attribute-value-id") +// terms := flagHelper.GetStringSlice("terms", policy_resource_mappingsTerms, cli.FlagHelperStringSliceOptions{ +// Min: 1, +// }) +// metadataLabels := flagHelper.GetStringSlice("label", newMetadataLabels, cli.FlagHelperStringSliceOptions{Min: 0}) + +// resourceMapping, err := h.CreateResourceMapping(attrId, terms, getMetadata(metadataLabels)) +// if err != nil { +// cli.ExitWithError("Failed to create resource mapping", err) +// } + +// fmt.Println(cli.SuccessMessage("Resource mapping created")) +// fmt.Println(cli.NewTabular().Rows([][]string{ +// {"Id", resourceMapping.Id}, +// {"Attribute Value Id", resourceMapping.AttributeValue.Id}, +// {"Attribute Value", resourceMapping.AttributeValue.Value}, +// {"Terms", strings.Join(resourceMapping.Terms, ", ")}, +// }...).Render()) +// }, +// } + +// policy_resource_mappingsGetCmd = &cobra.Command{ +// Use: "get", +// Short: "Get resource mappings", +// Run: func(cmd *cobra.Command, args []string) { +// h := cli.NewHandler(cmd) +// defer h.Close() + +// flagHelper := cli.NewFlagHelper(cmd) +// id := flagHelper.GetRequiredString("id") + +// resourceMapping, err := h.GetResourceMapping(id) +// if err != nil { +// cli.ExitWithError("Failed to get resource mapping", err) +// } + +// fmt.Println(cli.NewTabular().Rows([][]string{ +// {"Id", resourceMapping.Id}, +// {"Attribute Value Id", resourceMapping.AttributeValue.Id}, +// {"Attribute Value", resourceMapping.AttributeValue.Value}, +// {"Terms", strings.Join(resourceMapping.Terms, ", ")}, +// }...).Render()) +// }, +// } + +// policy_resource_mappingsListCmd = &cobra.Command{ +// Use: "list", +// Short: "List resource mappings", +// Run: func(cmd *cobra.Command, args []string) { +// h := cli.NewHandler(cmd) +// defer h.Close() + +// r, err := h.ListResourceMappings() +// if err != nil { +// cli.ExitWithError("Failed to list resource mappings", err) +// } + +// t := cli.NewTable() +// t.Headers("Id", "Attribute Value Id", "Attribute Value", "Terms") +// for _, resourceMapping := range r { +// t.Row(resourceMapping.Id, resourceMapping.AttributeValue.Id, resourceMapping.AttributeValue.Value, strings.Join(resourceMapping.Terms, ", ")) +// } +// fmt.Println(t.Render()) +// }, +// } + +// policy_resource_mappingsUpdateCmd = &cobra.Command{ +// Use: "update", +// Short: "Update resource mappings", +// Run: func(cmd *cobra.Command, args []string) { +// h := cli.NewHandler(cmd) +// defer h.Close() + +// flagHelper := cli.NewFlagHelper(cmd) +// id := flagHelper.GetRequiredString("id") +// attrValueId := flagHelper.GetOptionalString("attribute-value-id") +// terms := flagHelper.GetStringSlice("terms", policy_resource_mappingsTerms, cli.FlagHelperStringSliceOptions{}) +// newLabels := flagHelper.GetStringSlice("label-new", newMetadataLabels, cli.FlagHelperStringSliceOptions{Min: 0}) +// replacedLabels := flagHelper.GetStringSlice("label-replace", updatedMetadataLabels, cli.FlagHelperStringSliceOptions{Min: 0}) + +// metadata, behavior := processUpdateMetadata(newLabels, replacedLabels, func() (*common.Metadata, error) { +// rm, err := h.GetResourceMapping(id) +// if err != nil { +// errMsg := fmt.Sprintf("Could not find resource mapping (%s)", id) +// cli.ExitWithNotFoundError(errMsg, err) +// cli.ExitWithError(errMsg, err) +// } +// return rm.Metadata, nil +// }, +// ) + +// resourceMapping, err := h.UpdateResourceMapping(id, attrValueId, terms, metadata, behavior) +// if err != nil { +// cli.ExitWithError("Failed to update resource mapping", err) +// } + +// fmt.Println(cli.SuccessMessage("Resource mapping updated")) +// fmt.Println(cli.NewTabular().Rows([][]string{ +// {"Id", resourceMapping.Id}, +// {"Attribute Value Id", resourceMapping.AttributeValue.Id}, +// {"Attribute Value", resourceMapping.AttributeValue.Value}, +// {"Terms", strings.Join(resourceMapping.Terms, ", ")}, +// }...).Render()) +// }, +// } + +// policy_resource_mappingsDeleteCmd = &cobra.Command{ +// Use: "delete", +// Short: "Delete resource mappings", +// Run: func(cmd *cobra.Command, args []string) { +// h := cli.NewHandler(cmd) +// defer h.Close() + +// flagHelper := cli.NewFlagHelper(cmd) +// id := flagHelper.GetRequiredString("id") + +// cli.ConfirmDelete("resource-mapping", id) + +// resourceMapping, err := h.DeleteResourceMapping(id) +// if err != nil { +// cli.ExitWithError("Failed to delete resource mapping", err) +// } + +// fmt.Println(cli.SuccessMessage("Resource mapping deleted")) +// fmt.Println(cli.NewTabular().Rows([][]string{ +// {"Id", resourceMapping.Id}, +// {"Attribute Value Id", resourceMapping.AttributeValue.Id}, +// {"Attribute Value", resourceMapping.AttributeValue.Value}, +// {"Terms", strings.Join(resourceMapping.Terms, ", ")}, +// }...).Render()) +// }, +// } +) + +func init() { + // policyCmd.AddCommand(policy_resource_mappingsCmd) + + // policy_resource_mappingsCmd.AddCommand(policy_resource_mappingsCreateCmd) + // policy_resource_mappingsCreateCmd.Flags().String("attribute-value-id", "", "Attribute Value ID") + // policy_resource_mappingsCreateCmd.Flags().StringSliceVar(&policy_resource_mappingsTerms, "terms", []string{}, "Synonym terms") + // policy_resource_mappingsCreateCmd.Flags().StringSliceVarP(&newMetadataLabels, "label", "l", []string{}, "Optional metadata 'labels' in the format: key=value") + + // policy_resource_mappingsCmd.AddCommand(policy_resource_mappingsGetCmd) + // policy_resource_mappingsGetCmd.Flags().String("id", "", "Resource Mapping ID") + + // policy_resource_mappingsCmd.AddCommand(policy_resource_mappingsListCmd) + + // policy_resource_mappingsCmd.AddCommand(policy_resource_mappingsUpdateCmd) + // policy_resource_mappingsUpdateCmd.Flags().String("id", "", "Resource Mapping ID") + // policy_resource_mappingsUpdateCmd.Flags().String("attribute-value-id", "", "Attribute Value ID") + // policy_resource_mappingsUpdateCmd.Flags().StringSliceVar(&policy_resource_mappingsTerms, "terms", []string{}, "Synonym terms") + // policy_resource_mappingsUpdateCmd.Flags().StringSliceVarP(&newMetadataLabels, "label-new", "n", []string{}, "Optional metadata 'labels' in the format: key=value") + // policy_resource_mappingsUpdateCmd.Flags().StringSliceVarP(&updatedMetadataLabels, "label-replace", "r", []string{}, "Optional metadata 'labels' in the format: key=value. Note: providing one destructively replaces entire set of labels.") + + // policy_resource_mappingsCmd.AddCommand(policy_resource_mappingsDeleteCmd) + // policy_resource_mappingsDeleteCmd.Flags().String("id", "", "Resource Mapping ID") +} diff --git a/cmd/policy-subject_mappings.go b/cmd/policy-subject_mappings.go index 04d8f17b..96b92054 100644 --- a/cmd/policy-subject_mappings.go +++ b/cmd/policy-subject_mappings.go @@ -1,28 +1,19 @@ package cmd -import ( - // "encoding/json" - "fmt" - // "strings" - // "github.com/opentdf/tructl/pkg/cli" - // "github.com/opentdf/tructl/pkg/handlers" - // "github.com/spf13/cobra" -) - -// var ( -// policy_subjectMappingsCmds = []string{ -// policy_subjectMappingCreateCmd.Use, -// policy_subjectMappingGetCmd.Use, -// policy_subjectMappingsListCmd.Use, -// policy_subjectMappingUpdateCmd.Use, -// policy_subjectMappingDeleteCmd.Use, +var ( +// policy_subject_mappingsCmds = []string{ +// policy_subject_mappingCreateCmd.Use, +// policy_subject_mappingGetCmd.Use, +// policy_subject_mappingsListCmd.Use, +// policy_subject_mappingUpdateCmd.Use, +// policy_subject_mappingDeleteCmd.Use, // } // subjectValues []string -// policy_subjectMappingsCmd = &cobra.Command{ +// policy_subject_mappingsCmd = &cobra.Command{ // Use: "subject-mappings", -// Short: "Manage subject mappings [" + strings.Join(policy_subjectMappingsCmds, ", ") + "]", +// Short: "Manage subject mappings [" + strings.Join(policy_subject_mappingsCmds, ", ") + "]", // Long: ` // Subject Mappings - commands to manage relationships between subjects (PEs, NPEs, etc) and attributes. @@ -33,7 +24,7 @@ import ( // `, // } -// policy_subjectMappingGetCmd = &cobra.Command{ +// policy_subject_mappingGetCmd = &cobra.Command{ // Use: "get", // Short: "Get a subject mapping by id", // Run: func(cmd *cobra.Command, args []string) { @@ -61,19 +52,11 @@ import ( // rows = append(rows, mdRows...) // } -// if !jsonOutput { -// cli.PrintSuccessTable(cmd, id, cli.NewTabular().Rows(rows...)) -// } else { -// if output, err := json.MarshalIndent(mapping, "", " "); err != nil { -// cli.ExitWithError("Error marshalling subject mapping", err) -// } else { -// fmt.Println(string(output)) -// } -// } +// HandleSuccess(cmd, id, cli.NewTabular().Rows(rows...), mapping) // }, // } -// policy_subjectMappingsListCmd = &cobra.Command{ +// policy_subject_mappingsListCmd = &cobra.Command{ // Use: "list", // Short: "List subject mappings", // Run: func(cmd *cobra.Command, args []string) { @@ -85,32 +68,23 @@ import ( // cli.ExitWithError("Could not get subject mappings", err) // } -// if jsonOutput { -// if output, err := json.MarshalIndent(list, "", " "); err != nil { -// cli.ExitWithError("Error marshalling subject mappings", err) -// } else { -// fmt.Println(string(output)) -// } -// return -// } - // t := cli.NewTable().Width(180) // t.Headers("Id", "Subject Attribute", "Operator", "Subject Values", "Attribute Value ID") // for _, sm := range list { // rowCells := []string{ // sm.Id, -// sm.SubjectAttribute, -// handlers.GetSubjectMappingOperatorChoiceFromEnum(sm.Operator), -// strings.Join(sm.SubjectValues, ", "), +// // sm.SubjectAttribute, +// // handlers.GetSubjectMappingOperatorChoiceFromEnum(sm.Operator), +// // strings.Join(sm.SubjectValues, ", "), // sm.AttributeValue.Id, // } // t.Row(rowCells...) // } -// cli.PrintSuccessTable(cmd, "", t) +// HandleSuccess(cmd, "", t, list) // }, // } -// policy_subjectMappingCreateCmd = &cobra.Command{ +// policy_subject_mappingCreateCmd = &cobra.Command{ // Use: "create", // Short: "Create a new subject mapping", // Run: func(cmd *cobra.Command, args []string) { @@ -131,15 +105,6 @@ import ( // cli.ExitWithError("Could not create subject mapping", err) // } -// if jsonOutput { -// if output, err := json.MarshalIndent(mapping, "", " "); err != nil { -// cli.ExitWithError("Error marshalling subject mapping", err) -// } else { -// fmt.Println(string(output)) -// } -// return -// } - // rows := [][]string{ // {"Id", mapping.Id}, // {"Subject Attribute", mapping.SubjectAttribute}, @@ -152,13 +117,13 @@ import ( // rows = append(rows, mdRows...) // } -// cli.PrintSuccessTable(cmd, mapping.Id, +// HandleSuccess(cmd, mapping.Id, // cli.NewTabular(). -// Rows(rows...)) +// Rows(rows...), mapping) // }, // } -// policy_subjectMappingDeleteCmd = &cobra.Command{ +// policy_subject_mappingDeleteCmd = &cobra.Command{ // Use: "delete", // Short: "Delete a subject mapping by id", // Run: func(cmd *cobra.Command, args []string) { @@ -188,7 +153,7 @@ import ( // }, // } -// policy_subjectMappingUpdateCmd = &cobra.Command{ +// policy_subject_mappingUpdateCmd = &cobra.Command{ // Use: "update", // Short: "Update a subject mapping", // Run: func(cmd *cobra.Command, args []string) { @@ -216,43 +181,35 @@ import ( // cli.ExitWithError("Could not update subject mapping", err) // } -// // TODO: handle json output once service sends back updated subject mapping -// fmt.Println(cli.SuccessMessage(fmt.Sprintf("Subject mapping id: (%s) updated.", id))) -// }, -// } -// ) - -// func init() { -// policyCmd.AddCommand(policy_subjectMappingsCmd) - -// policy_subjectMappingsCmd.AddCommand(policy_subjectMappingGetCmd) -// policy_subjectMappingGetCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") +// // TODO: handle json output once service sends back updated subject mapping +// fmt.Println(cli.SuccessMessage(fmt.Sprintf("Subject mapping id: (%s) updated.", id))) +// }, +// } +) -// policy_subjectMappingsCmd.AddCommand(policy_subjectMappingsListCmd) +func init() { + // policyCmd.AddCommand(policy_subject_mappingsCmd) -// policy_subjectMappingsCmd.AddCommand(policy_subjectMappingCreateCmd) -// policy_subjectMappingCreateCmd.Flags().StringP("attribute-value-id", "a", "", "Id of the attribute value") -// policy_subjectMappingCreateCmd.Flags().StringP("subject-attribute", "s", "", "Subject attribute") -// policy_subjectMappingCreateCmd.Flags().StringSliceVarP(&subjectValues, "subject-values", "v", []string{}, "Subject values") -// policy_subjectMappingCreateCmd.Flags().StringP("operator", "o", "", "Operator") -// policy_subjectMappingCreateCmd.Flags().StringP("metadata", "m", "", "Metadata (optional): labels and description") + // policy_subject_mappingsCmd.AddCommand(policy_subject_mappingGetCmd) + // policy_subject_mappingGetCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") -// policy_subjectMappingsCmd.AddCommand(policy_subjectMappingUpdateCmd) -// policy_subjectMappingUpdateCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") -// policy_subjectMappingUpdateCmd.Flags().StringP("attribute-value-id", "a", "", "Id of the attribute value") -// policy_subjectMappingUpdateCmd.Flags().StringP("subject-attribute", "s", "", "Subject attribute") -// policy_subjectMappingUpdateCmd.Flags().StringSliceVarP(&subjectValues, "subject-values", "v", []string{}, "Subject values") -// policy_subjectMappingUpdateCmd.Flags().StringP("operator", "o", "", "Operator: [IN, NOT_IN]") -// policy_subjectMappingUpdateCmd.Flags().StringP("metadata", "m", "", "Metadata (optional): labels and description") + // policy_subject_mappingsCmd.AddCommand(policy_subject_mappingsListCmd) -// policy_subjectMappingsCmd.AddCommand(policy_subjectMappingDeleteCmd) -// policy_subjectMappingDeleteCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") -// } + // policy_subject_mappingsCmd.AddCommand(policy_subject_mappingCreateCmd) + // policy_subject_mappingCreateCmd.Flags().StringP("attribute-value-id", "a", "", "Id of the attribute value") + // policy_subject_mappingCreateCmd.Flags().StringP("subject-attribute", "s", "", "Subject attribute") + // policy_subject_mappingCreateCmd.Flags().StringSliceVarP(&subjectValues, "subject-values", "v", []string{}, "Subject values") + // policy_subject_mappingCreateCmd.Flags().StringP("operator", "o", "", "Operator") + // policy_subject_mappingCreateCmd.Flags().StringP("metadata", "m", "", "Metadata (optional): labels and description") -func placeholder() { - fmt.Println("This is a placeholder for the policy-subject_mappings.go file, once the subject mappings have been stablized") -} + // policy_subject_mappingsCmd.AddCommand(policy_subject_mappingUpdateCmd) + // policy_subject_mappingUpdateCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") + // policy_subject_mappingUpdateCmd.Flags().StringP("attribute-value-id", "a", "", "Id of the attribute value") + // policy_subject_mappingUpdateCmd.Flags().StringP("subject-attribute", "s", "", "Subject attribute") + // policy_subject_mappingUpdateCmd.Flags().StringSliceVarP(&subjectValues, "subject-values", "v", []string{}, "Subject values") + // policy_subject_mappingUpdateCmd.Flags().StringP("operator", "o", "", "Operator: [IN, NOT_IN]") + // policy_subject_mappingUpdateCmd.Flags().StringP("metadata", "m", "", "Metadata (optional): labels and description") -func main() { - placeholder() + // policy_subject_mappingsCmd.AddCommand(policy_subject_mappingDeleteCmd) + // policy_subject_mappingDeleteCmd.Flags().StringP("id", "i", "", "Id of the subject mapping") } diff --git a/cmd/root.go b/cmd/root.go index 3a83d24c..25df22ef 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,14 +4,18 @@ Copyright © 2023 NAME HERE package cmd import ( + "fmt" "os" + "github.com/opentdf/tructl/internal/config" "github.com/spf13/cobra" ) var ( - cfgFile string - jsonOutput bool + cfgFile string + TructlCfg config.Config + + configFlagOverrides = config.ConfigFlagOverrides{} ) // rootCmd represents the base command when called without any subcommands @@ -32,9 +36,14 @@ func Execute() { } func init() { - rootCmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "output in JSON format") + rootCmd.PersistentFlags().BoolVar(&configFlagOverrides.OutputFormatJSON, "json", false, "output single command in JSON (overrides configured output format)") rootCmd.PersistentFlags().String("host", "localhost:9000", "host:port of the Virtru Data Security Platform gRPC server") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config-file", "", "config file (default is $HOME/.tructl.yaml)") - // TODO: Implement Viper and allow configs - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tructl.yaml)") + cfg, err := config.LoadConfig("tructl") + if err != nil { + fmt.Println("Error loading config:", err) + os.Exit(1) + } + TructlCfg = *cfg } diff --git a/go.mod b/go.mod index 386e6ec9..4ff3ddcf 100644 --- a/go.mod +++ b/go.mod @@ -1,68 +1,79 @@ module github.com/opentdf/tructl -go 1.21.7 - -toolchain go1.22.1 +go 1.22.1 require ( github.com/adrg/frontmatter v0.2.0 - github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6 + github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/huh v0.3.0 - github.com/charmbracelet/lipgloss v0.9.1 + github.com/charmbracelet/lipgloss v0.10.0 github.com/muesli/reflow v0.3.0 - github.com/opentdf/platform/protocol/go v0.0.0-20240301211102-04107b3757a9 - github.com/opentdf/platform/sdk v0.0.0-20240305152130-b34c2fe9ad70 + github.com/opentdf/platform/protocol/go v0.0.0-20240314151303-79519c9c870f + github.com/opentdf/platform/sdk v0.0.0-20240314151303-79519c9c870f github.com/spf13/cobra v1.8.0 - google.golang.org/grpc v1.61.0 + google.golang.org/grpc v1.62.1 ) require ( - buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 // indirect + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1 // indirect github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/BurntSushi/toml v0.3.1 // indirect github.com/alessio/shellescape v1.4.1 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/catppuccin/go v0.2.0 // indirect - github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect + github.com/containerd/console v1.0.4 // indirect github.com/coreos/go-oidc/v3 v3.9.0 // indirect + github.com/creasty/defaults v1.7.0 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect - github.com/go-jose/go-jose/v3 v3.0.1 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/go-jose/go-jose/v3 v3.0.3 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/klauspost/compress v1.17.2 // indirect github.com/lestrrat-go/blackmagic v1.0.2 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect - github.com/lestrrat-go/httprc v1.0.4 // indirect + github.com/lestrrat-go/httprc v1.0.5 // indirect github.com/lestrrat-go/iter v1.0.2 // indirect - github.com/lestrrat-go/jwx/v2 v2.0.19 // indirect + github.com/lestrrat-go/jwx/v2 v2.0.21 // indirect github.com/lestrrat-go/option v1.0.1 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.15.2 // indirect - github.com/opentdf/backend-go v0.1.16 // indirect + github.com/opentdf/backend-go v0.1.17 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/rivo/uniseg v0.4.4 // indirect + github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect github.com/segmentio/asm v1.2.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.18.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/virtru/access-pdp v1.11.0 // indirect github.com/zalando/go-keyring v0.2.3 // indirect go.opentelemetry.io/otel v1.21.0 // indirect @@ -80,10 +91,12 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.16.1 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect - google.golang.org/protobuf v1.32.0 // indirect - gopkg.in/go-jose/go-jose.v2 v2.6.2 // indirect + google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect + google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 1f687255..2c6abdd0 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk= buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1 h1:0nWhrRcnkgw1kwJ7xibIO8bqfOA7pBzBjGCDBxIHch8= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1/go.mod h1:Tgn5bgL220vkFOI0KPStlcClPeOJzAv4uT+V8JXGUnw= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= @@ -24,14 +26,20 @@ github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqy github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6 h1:6nVCV8pqGaeyxetur3gpX3AAaiyKgzjIoCPV3NXKZBE= github.com/charmbracelet/bubbles v0.17.2-0.20240108170749-ec883029c8e6/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o= +github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= +github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM= github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg= github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE= github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA= github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg= github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I= +github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= +github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= +github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro= +github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/containerd v1.7.12 h1:+KQsnv4VnzyxWcfO9mlxxELaoztsDEjOuCMPAuPqgU0= github.com/containerd/containerd v1.7.12/go.mod h1:/5OMpE1p0ylxtEUGY8kuCYkDRzJm9NO1TFMWjUpdevk= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= @@ -41,9 +49,12 @@ github.com/coreos/go-oidc/v3 v3.9.0/go.mod h1:rTKz2PYwftcrtoCzV5g5kvfJoWcm0Mk8AF github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA= +github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= @@ -58,8 +69,12 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4 github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA= github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= +github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= +github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -81,14 +96,19 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= @@ -107,10 +127,14 @@ github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZ github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= github.com/lestrrat-go/httprc v1.0.4 h1:bAZymwoZQb+Oq8MEbyipag7iSq6YIga8Wj6GOiJGdI8= github.com/lestrrat-go/httprc v1.0.4/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo= +github.com/lestrrat-go/httprc v1.0.5 h1:bsTfiH8xaKOJPrg1R+E3iE/AWZr/x0Phj9PBTG/OLUk= +github.com/lestrrat-go/httprc v1.0.5/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo= github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4= github.com/lestrrat-go/jwx/v2 v2.0.19 h1:ekv1qEZE6BVct89QA+pRF6+4pCpfVrOnEJnTnT4RXoY= github.com/lestrrat-go/jwx/v2 v2.0.19/go.mod h1:l3im3coce1lL2cDeAjqmaR+Awx+X8Ih+2k8BuHNJ4CU= +github.com/lestrrat-go/jwx/v2 v2.0.21 h1:jAPKupy4uHgrHFEdjVjNkUgoBKtVDgrQPB/h55FHrR0= +github.com/lestrrat-go/jwx/v2 v2.0.21/go.mod h1:09mLW8zto6bWL9GbwnqAli+ArLf+5M33QLQPDggkUWM= github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -128,6 +152,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= @@ -152,12 +178,20 @@ github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/ github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= github.com/opentdf/backend-go v0.1.16 h1:t7OD3ShBCeuAZWUKZNYJJBfC01d4X0EL5a6J1UnIdx4= github.com/opentdf/backend-go v0.1.16/go.mod h1:4RAZ3K19YOJkpxSh4jl6vtjOUkK3H/zqA32LeBf3CDQ= +github.com/opentdf/backend-go v0.1.17 h1:RA/9Mj7OKycnvOrkIZTJCsSyROCcioXzzqMUlnCxP48= +github.com/opentdf/backend-go v0.1.17/go.mod h1:4RAZ3K19YOJkpxSh4jl6vtjOUkK3H/zqA32LeBf3CDQ= github.com/opentdf/platform/protocol/go v0.0.0-20240301211102-04107b3757a9 h1:7E2tnDEZjIwHys0gPPs56Emf+sw1dKXmr+Ho/n/jH8M= github.com/opentdf/platform/protocol/go v0.0.0-20240301211102-04107b3757a9/go.mod h1:O0Wolf3NAhKII0hfDcEPtpsXe/VcUI7Lq/rNqh8I7Wk= +github.com/opentdf/platform/protocol/go v0.0.0-20240314151303-79519c9c870f h1:+xE7MKFotF15VAEzvgx8LEK/ysx0RuZhoOc6vnKOr8Q= +github.com/opentdf/platform/protocol/go v0.0.0-20240314151303-79519c9c870f/go.mod h1:qwJ2OQqNVtucVgkLlZhz6O1I1fxqHTXrl5HVRu9AO4Y= github.com/opentdf/platform/sdk v0.0.0-20240301211102-04107b3757a9 h1:NY4GcZ5IETFH2NyexuEENgkL79ZiSQNaZhzs9OkozaI= github.com/opentdf/platform/sdk v0.0.0-20240301211102-04107b3757a9/go.mod h1:ugS04emTB9g96A4sqNjOFVn0Ip4B/VVYQ+eAKD7OFxM= github.com/opentdf/platform/sdk v0.0.0-20240305152130-b34c2fe9ad70 h1:FjKH+bwYRho7mJqPjX3vFnZu5jv7sjdupPhAI37xYgM= github.com/opentdf/platform/sdk v0.0.0-20240305152130-b34c2fe9ad70/go.mod h1:secHYA6In0KqYB67IzB6b/GdFciPPSZUsjAXjvWkuU0= +github.com/opentdf/platform/sdk v0.0.0-20240314151303-79519c9c870f h1:T7z84OKFYYX59KHAB3ifcu1EUUQT1kcCthADLihvSA4= +github.com/opentdf/platform/sdk v0.0.0-20240314151303-79519c9c870f/go.mod h1:7HLs/qMMlM3aTf6alULPgXet/AYzc4EySv94GRoA50Q= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -169,9 +203,15 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= @@ -182,15 +222,29 @@ github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFt github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/testcontainers/testcontainers-go v0.28.0 h1:1HLm9qm+J5VikzFDYhOd+Zw12NtOl+8drH2E8nTY1r8= github.com/testcontainers/testcontainers-go v0.28.0/go.mod h1:COlDpUXbwW3owtpMkEB1zo9gwb1CoKVKlyrVPejF4AU= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= @@ -208,32 +262,44 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q= go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= @@ -244,6 +310,7 @@ golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -254,26 +321,35 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -282,21 +358,35 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe h1:USL2DhxfgRchafRvt/wYyyQNzwgL7ZiURcozOE/Pkvo= google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro= +google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 h1:ImUcDPHjTrAqNhlOkSocDLfG9rrNHH7w7uoKWPaWZ8s= +google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 h1:x9PwdEgd11LgK+orcck69WVRo7DezSO4VUMPI4xpc8A= google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014/go.mod h1:rbHMSEDyoYX62nRVLOCc4Qt1HbsdytAYoVwgjiOhF3I= +google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 h1:oqta3O3AnlWbmIE3bFnWbu4bRxZjfbWCp0cKSuZh01E= +google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe h1:bQnxqljG/wqi4NTXu2+DJ3n7APcEA882QZ1JvhQAq9o= google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 h1:8EeVk1VKMD+GD/neyEHGmz7pFblqPjHoi+PGQIlLx2s= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= +google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= +google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/go-jose/go-jose.v2 v2.6.2 h1:Rl5+9rA0kG3vsO1qhncMPRT5eHICihAMQYJkD7u/i4M= gopkg.in/go-jose/go-jose.v2 v2.6.2/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI= +gopkg.in/go-jose/go-jose.v2 v2.6.3 h1:nt80fvSDlhKWQgSWyHyy5CfmlQr+asih51R8PTWNKKs= +gopkg.in/go-jose/go-jose.v2 v2.6.3/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 00000000..b5b8eed6 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,89 @@ +package config + +import ( + "errors" + "fmt" + "log/slog" + "os" + "strings" + + "github.com/creasty/defaults" + "github.com/spf13/viper" +) + +type Output struct { + Format string `yaml:"format" default:"styled"` +} + +type Config struct { + Output Output `yaml:"output"` +} + +// captures all CLI flags that will override pre-specified config values +type ConfigFlagOverrides struct { + OutputFormatJSON bool +} + +type Error string + +func (e Error) Error() string { + return string(e) +} + +const ( + OutputJSON = "json" + OutputStyled = "styled" + + ErrLoadingConfig Error = "error loading config" +) + +// Load config with viper. +func LoadConfig(key string) (*Config, error) { + if key == "" { + key = "tructl" + slog.Debug("LoadConfig: key not provided, using default", "config file", key) + } else { + slog.Debug("LoadConfig", "config file", key) + } + + config := &Config{} + homedir, err := os.UserHomeDir() + if err != nil { + return nil, errors.Join(err, ErrLoadingConfig) + } + viper.AddConfigPath(fmt.Sprintf("%s/."+key, homedir)) + viper.AddConfigPath("." + key) + viper.AddConfigPath(".") + viper.SetConfigName(key) + viper.SetConfigType("yaml") + + viper.SetEnvPrefix(key) + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() + + if err := viper.ReadInConfig(); err != nil { + return nil, errors.Join(err, ErrLoadingConfig) + } + + if err := defaults.Set(config); err != nil { + return nil, errors.Join(err, ErrLoadingConfig) + } + + err = viper.Unmarshal(config) + if err != nil { + return nil, errors.Join(err, ErrLoadingConfig) + } + + return config, nil +} + +func UpdateOutputFormat(format string) { + v := viper.GetViper() + format = strings.ToLower(format) + if format == OutputJSON { + v.Set("output.format", OutputJSON) + } else { + v.Set("output.format", OutputStyled) + } + viper.WriteConfig() +} diff --git a/pkg/cli/sdkHelpers.go b/pkg/cli/sdkHelpers.go index 844dd306..bfcae94a 100644 --- a/pkg/cli/sdkHelpers.go +++ b/pkg/cli/sdkHelpers.go @@ -1,7 +1,7 @@ package cli import ( - "github.com/opentdf/platform/protocol/go/policy/attributes" + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/tructl/pkg/handlers" ) @@ -13,7 +13,7 @@ type SimpleAttribute struct { Namespace string } -func GetSimpleAttribute(a *attributes.Attribute) SimpleAttribute { +func GetSimpleAttribute(a *policy.Attribute) SimpleAttribute { values := []string{} for _, v := range a.Values { values = append(values, v.Value) diff --git a/pkg/cli/tabular.go b/pkg/cli/tabular.go index 95224adc..e4cad33b 100644 --- a/pkg/cli/tabular.go +++ b/pkg/cli/tabular.go @@ -38,6 +38,9 @@ func PrintSuccessTable(cmd *cobra.Command, id string, t *table.Table) { case "delete": msg.verb = fmt.Sprintf("Deleted %s: %s", resource, id) msg.helper = getJsonHelper(resource + " list") + case "deactivate": + msg.verb = fmt.Sprintf("Deactivated %s: %s", resource, id) + msg.helper = getJsonHelper(resource + " list") // TODO: make sure the filters are provided here to get ACTIVE/INACTIVE/ANY case "list": msg.verb = fmt.Sprintf("Found %s list", resource) msg.helper = getJsonHelper(resource + " get --id=") diff --git a/pkg/handlers/attribute.go b/pkg/handlers/attribute.go index 006175ed..fa85857a 100644 --- a/pkg/handlers/attribute.go +++ b/pkg/handlers/attribute.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/opentdf/platform/protocol/go/common" + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/platform/protocol/go/policy/attributes" ) @@ -29,7 +30,7 @@ func (e *CreateAttributeError) Error() string { return "Error creating attribute" } -func (h Handler) GetAttribute(id string) (*attributes.Attribute, error) { +func (h Handler) GetAttribute(id string) (*policy.Attribute, error) { resp, err := h.sdk.Attributes.GetAttribute(h.ctx, &attributes.GetAttributeRequest{ Id: id, }) @@ -40,7 +41,7 @@ func (h Handler) GetAttribute(id string) (*attributes.Attribute, error) { return resp.Attribute, nil } -func (h Handler) ListAttributes() ([]*attributes.Attribute, error) { +func (h Handler) ListAttributes() ([]*policy.Attribute, error) { resp, err := h.sdk.Attributes.ListAttributes(h.ctx, &attributes.ListAttributesRequest{}) if err != nil { return nil, err @@ -48,18 +49,16 @@ func (h Handler) ListAttributes() ([]*attributes.Attribute, error) { return resp.Attributes, err } -func (h Handler) CreateAttribute(name string, rule string, namespace string) (*attributes.Attribute, error) { +func (h Handler) CreateAttribute(name string, rule string, namespace string) (*policy.Attribute, error) { r, err := GetAttributeRuleFromReadableString(rule) if err != nil { return nil, err } attrReq := &attributes.CreateAttributeRequest{ - Attribute: &attributes.AttributeCreateUpdate{ - NamespaceId: namespace, - Name: name, - Rule: r, - }, + NamespaceId: namespace, + Name: name, + Rule: r, } resp, err := h.sdk.Attributes.CreateAttribute(h.ctx, attrReq) @@ -69,7 +68,7 @@ func (h Handler) CreateAttribute(name string, rule string, namespace string) (*a attr := resp.Attribute - return &attributes.Attribute{ + return &policy.Attribute{ Id: attr.Id, Name: attr.Name, Rule: attr.Rule, @@ -82,14 +81,12 @@ func (h *Handler) UpdateAttribute( fns ...func(*common.MetadataMutable) *common.MetadataMutable, ) (*attributes.UpdateAttributeResponse, error) { return h.sdk.Attributes.UpdateAttribute(h.ctx, &attributes.UpdateAttributeRequest{ - Id: id, - Attribute: &attributes.AttributeCreateUpdate{ - Metadata: buildMetadata(&common.MetadataMutable{}, fns...), - }, + Id: id, + Metadata: buildMetadata(&common.MetadataMutable{}, fns...), }) } -func (h Handler) DeactivateAttribute(id string) (*attributes.Attribute, error) { +func (h Handler) DeactivateAttribute(id string) (*policy.Attribute, error) { resp, err := h.sdk.Attributes.DeactivateAttribute(h.ctx, &attributes.DeactivateAttributeRequest{ Id: id, }) @@ -111,27 +108,27 @@ func GetAttributeRuleOptions() []string { } } -func GetAttributeRuleFromAttributeType(rule attributes.AttributeRuleTypeEnum) string { +func GetAttributeRuleFromAttributeType(rule policy.AttributeRuleTypeEnum) string { switch rule { - case attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF: + case policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF: return AttributeRuleAllOf - case attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF: + case policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF: return AttributeRuleAnyOf - case attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY: + case policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY: return AttributeRuleHierarchy default: return "" } } -func GetAttributeRuleFromReadableString(rule string) (attributes.AttributeRuleTypeEnum, error) { +func GetAttributeRuleFromReadableString(rule string) (policy.AttributeRuleTypeEnum, error) { switch rule { case AttributeRuleAllOf: - return attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF, nil + return policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF, nil case AttributeRuleAnyOf: - return attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF, nil + return policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF, nil case AttributeRuleHierarchy: - return attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY, nil + return policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY, nil } return 0, fmt.Errorf("invalid attribute rule: %s", rule) } diff --git a/pkg/handlers/attribute_values.go b/pkg/handlers/attribute_values.go index f26008e7..ea587355 100644 --- a/pkg/handlers/attribute_values.go +++ b/pkg/handlers/attribute_values.go @@ -1,15 +1,14 @@ package handlers import ( + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/platform/protocol/go/policy/attributes" ) -func (h *Handler) CreateAttributeValue(attributeId string, value string) (*attributes.Value, error) { +func (h *Handler) CreateAttributeValue(attributeId string, value string) (*policy.Value, error) { resp, err := h.sdk.Attributes.CreateAttributeValue(h.ctx, &attributes.CreateAttributeValueRequest{ AttributeId: attributeId, - Value: &attributes.ValueCreateUpdate{ - Value: value, - }, + Value: value, }) if err != nil { return nil, err diff --git a/pkg/handlers/kas-registry.go b/pkg/handlers/kas-registry.go index 12002128..72d25c1f 100644 --- a/pkg/handlers/kas-registry.go +++ b/pkg/handlers/kas-registry.go @@ -36,11 +36,9 @@ func (h Handler) ListKasRegistryEntries() ([]*kasregistry.KeyAccessServer, error func (h Handler) CreateKasRegistryEntry(uri string, publicKey *kasregistry.PublicKey, metadata *common.MetadataMutable) (*kasregistry.KeyAccessServer, error) { // Create a request to create a KeyAccessServer entry. req := &kasregistry.CreateKeyAccessServerRequest{ - KeyAccessServer: &kasregistry.KeyAccessServerCreateUpdate{ - Uri: uri, - PublicKey: publicKey, - Metadata: metadata, - }, + Uri: uri, + PublicKey: publicKey, + Metadata: metadata, } // Create the KeyAccessServer entry using the SDK. @@ -56,7 +54,6 @@ func (h Handler) CreateKasRegistryEntry(uri string, publicKey *kasregistry.Publi // UpdateKasRegistryEntry updates a KeyAccessServer entry in the project. // note: we are specifically building the request on the otherside, due to so manu of the options being optional func (h Handler) UpdateKasRegistryEntry(id string, kasUpdateReq *kasregistry.UpdateKeyAccessServerRequest) (*kasregistry.KeyAccessServer, error) { - // Update the KeyAccessServer entry using the SDK. resp, err := h.sdk.KeyAccessServerRegistry.UpdateKeyAccessServer(h.ctx, kasUpdateReq) if err != nil { diff --git a/pkg/handlers/namespaces.go b/pkg/handlers/namespaces.go index 17218182..651c6787 100644 --- a/pkg/handlers/namespaces.go +++ b/pkg/handlers/namespaces.go @@ -1,10 +1,11 @@ package handlers import ( + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/platform/protocol/go/policy/namespaces" ) -func (h Handler) GetNamespace(id string) (*namespaces.Namespace, error) { +func (h Handler) GetNamespace(id string) (*policy.Namespace, error) { resp, err := h.sdk.Namespaces.GetNamespace(h.ctx, &namespaces.GetNamespaceRequest{ Id: id, }) @@ -15,7 +16,7 @@ func (h Handler) GetNamespace(id string) (*namespaces.Namespace, error) { return resp.Namespace, nil } -func (h Handler) ListNamespaces() ([]*namespaces.Namespace, error) { +func (h Handler) ListNamespaces() ([]*policy.Namespace, error) { resp, err := h.sdk.Namespaces.ListNamespaces(h.ctx, &namespaces.ListNamespacesRequest{}) if err != nil { return nil, err @@ -24,7 +25,7 @@ func (h Handler) ListNamespaces() ([]*namespaces.Namespace, error) { return resp.Namespaces, nil } -func (h Handler) CreateNamespace(name string) (*namespaces.Namespace, error) { +func (h Handler) CreateNamespace(name string) (*policy.Namespace, error) { resp, err := h.sdk.Namespaces.CreateNamespace(h.ctx, &namespaces.CreateNamespaceRequest{ Name: name, }) @@ -35,10 +36,9 @@ func (h Handler) CreateNamespace(name string) (*namespaces.Namespace, error) { return resp.Namespace, nil } -func (h Handler) UpdateNamespace(id string, name string) (*namespaces.Namespace, error) { +func (h Handler) UpdateNamespace(id string, name string) (*policy.Namespace, error) { resp, err := h.sdk.Namespaces.UpdateNamespace(h.ctx, &namespaces.UpdateNamespaceRequest{ - Id: id, - Name: name, + Id: id, }) if err != nil { return nil, err diff --git a/pkg/handlers/resourceMappings.go b/pkg/handlers/resourceMappings.go index cfb3426e..3b4321ff 100644 --- a/pkg/handlers/resourceMappings.go +++ b/pkg/handlers/resourceMappings.go @@ -3,6 +3,7 @@ package handlers import ( "context" + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/platform/protocol/go/policy/resourcemapping" ) @@ -12,12 +13,10 @@ type ResourceMapping struct { Terms []string } -func (h *Handler) CreateResourceMapping(attributeId string, terms []string) (*resourcemapping.ResourceMapping, error) { +func (h *Handler) CreateResourceMapping(attributeId string, terms []string) (*policy.ResourceMapping, error) { res, err := h.sdk.ResourceMapping.CreateResourceMapping(context.Background(), &resourcemapping.CreateResourceMappingRequest{ - ResourceMapping: &resourcemapping.ResourceMappingCreateUpdate{ - AttributeValueId: attributeId, - Terms: terms, - }, + AttributeValueId: attributeId, + Terms: terms, }) if err != nil { return nil, err @@ -26,7 +25,7 @@ func (h *Handler) CreateResourceMapping(attributeId string, terms []string) (*re return res.ResourceMapping, nil } -func (h *Handler) GetResourceMapping(id string) (*resourcemapping.ResourceMapping, error) { +func (h *Handler) GetResourceMapping(id string) (*policy.ResourceMapping, error) { res, err := h.sdk.ResourceMapping.GetResourceMapping(context.Background(), &resourcemapping.GetResourceMappingRequest{ Id: id, }) @@ -37,7 +36,7 @@ func (h *Handler) GetResourceMapping(id string) (*resourcemapping.ResourceMappin return res.ResourceMapping, nil } -func (h *Handler) ListResourceMappings() ([]*resourcemapping.ResourceMapping, error) { +func (h *Handler) ListResourceMappings() ([]*policy.ResourceMapping, error) { res, err := h.sdk.ResourceMapping.ListResourceMappings(context.Background(), &resourcemapping.ListResourceMappingsRequest{}) if err != nil { return nil, err @@ -46,23 +45,20 @@ func (h *Handler) ListResourceMappings() ([]*resourcemapping.ResourceMapping, er return res.ResourceMappings, nil } -func (h *Handler) UpdateResourceMapping(id string, attrValueId string, terms []string) (*resourcemapping.ResourceMapping, error) { +func (h *Handler) UpdateResourceMapping(id string, attrValueId string, terms []string) (*policy.ResourceMapping, error) { res, err := h.sdk.ResourceMapping.UpdateResourceMapping(context.Background(), &resourcemapping.UpdateResourceMappingRequest{ - Id: id, - ResourceMapping: &resourcemapping.ResourceMappingCreateUpdate{ - AttributeValueId: attrValueId, - Terms: terms, - }, + Id: id, + AttributeValueId: attrValueId, + Terms: terms, }) if err != nil { return nil, err } return res.ResourceMapping, nil - } -func (h *Handler) DeleteResourceMapping(id string) (*resourcemapping.ResourceMapping, error) { +func (h *Handler) DeleteResourceMapping(id string) (*policy.ResourceMapping, error) { resp, err := h.sdk.ResourceMapping.DeleteResourceMapping(context.Background(), &resourcemapping.DeleteResourceMappingRequest{ Id: id, }) diff --git a/pkg/handlers/sdk.go b/pkg/handlers/sdk.go index 27cfa198..ee9ba537 100644 --- a/pkg/handlers/sdk.go +++ b/pkg/handlers/sdk.go @@ -53,8 +53,7 @@ func (h Handler) Close() error { func (h Handler) WithDescriptionMetadata(metadata *common.Metadata, description string) func() *common.Metadata { return func() *common.Metadata { nextMetadata := &common.Metadata{ - Labels: metadata.Labels, - Description: description, + Labels: metadata.Labels, } return nextMetadata } @@ -64,8 +63,7 @@ func (h Handler) WithDescriptionMetadata(metadata *common.Metadata, description func (h Handler) WithReplaceLabelsMetadata(metadata *common.MetadataMutable, labels map[string]string) func(*common.MetadataMutable) *common.MetadataMutable { return func(*common.MetadataMutable) *common.MetadataMutable { nextMetadata := &common.MetadataMutable{ - Labels: labels, - Description: metadata.Description, + Labels: labels, } return nextMetadata } @@ -77,8 +75,7 @@ func (h Handler) WithLabelMetadata(metadata *common.MetadataMutable, key, value labels := metadata.Labels labels[key] = value nextMetadata := &common.MetadataMutable{ - Labels: labels, - Description: metadata.Description, + Labels: labels, } return nextMetadata } diff --git a/pkg/handlers/subjectmappings.go b/pkg/handlers/subjectmappings.go index a2bd8903..a9f30993 100644 --- a/pkg/handlers/subjectmappings.go +++ b/pkg/handlers/subjectmappings.go @@ -1,125 +1,113 @@ -// SubjectMappings are pretty unstable right now -// and undergoing active arch changes, so for now we're completely -// commenting them out. -// We'll uncomment them once we have a stable version of the SubjectMappings in a few days - package handlers import ( "fmt" + "slices" + "strings" + + "github.com/opentdf/platform/protocol/go/common" + "github.com/opentdf/platform/protocol/go/policy" + "github.com/opentdf/platform/protocol/go/policy/subjectmapping" ) -// const ( -// SubjectMappingOperatorIn = "IN" -// SubjectMappingOperatorNotIn = "NOT_IN" -// SubjectMappingOperatorUnspecified = "UNSPECIFIED" -// ) - -// var SubjectMappingOperatorEnumChoices = []string{SubjectMappingOperatorIn, SubjectMappingOperatorNotIn, SubjectMappingOperatorUnspecified} - -// func (h Handler) GetSubjectMapping(id string) (*subjectmapping.SubjectMapping, error) { -// resp, err := h.sdk.SubjectMapping.GetSubjectMapping(h.ctx, &subjectmapping.GetSubjectMappingRequest{ -// Id: id, -// }) -// if err != nil { -// return nil, err -// } - -// return resp.SubjectMapping, nil -// } - -// func (h Handler) ListSubjectMappings() ([]*subjectmapping.SubjectMapping, error) { -// resp, err := h.sdk.SubjectMapping.ListSubjectMappings(h.ctx, &subjectmapping.ListSubjectMappingsRequest{}) -// if err != nil { -// return nil, err -// } - -// return resp.SubjectMappings, nil -// } - -// func (h Handler) CreateNewSubjectMapping(attributeValueId string, subjectAttribute string, subjectValues []string, operator string, metadata *common.MetadataMutable) (*subjectmapping.SubjectMapping, error) { -// if !slices.Contains(SubjectMappingOperatorEnumChoices, operator) { -// return nil, fmt.Errorf("Invalid operator. Must be one of [%s]" + strings.Join(SubjectMappingOperatorEnumChoices, ", ")) -// } - -// resp, err := h.sdk.SubjectMapping.CreateSubjectMapping(h.ctx, &subjectmapping.CreateSubjectMappingRequest{ -// SubjectMapping: &subjectmapping.SubjectMappingCreateUpdate{ -// AttributeValueId: attributeValueId, -// SubjectAttribute: subjectAttribute, -// SubjectValues: subjectValues, -// Operator: GetSubjectMappingOperatorFromChoice(operator), -// Metadata: metadata, -// }, -// }) -// if err != nil { -// return nil, err -// } - -// return resp.SubjectMapping, nil -// } - -// func (h Handler) UpdateSubjectMapping(id string, attributeValueId string, subjectAttribute string, subjectValues []string, operator string, metadata *common.MetadataMutable) (*subjectmapping.SubjectMapping, error) { -// if !slices.Contains(SubjectMappingOperatorEnumChoices, operator) { -// return nil, fmt.Errorf("Invalid operator. Must be one of [%s]" + strings.Join(SubjectMappingOperatorEnumChoices, ", ")) -// } - -// resp, err := h.sdk.SubjectMapping.UpdateSubjectMapping(h.ctx, &subjectmapping.UpdateSubjectMappingRequest{ -// Id: id, -// SubjectMapping: &subjectmapping.SubjectMappingCreateUpdate{ -// AttributeValueId: attributeValueId, -// SubjectAttribute: subjectAttribute, -// SubjectValues: subjectValues, -// Operator: GetSubjectMappingOperatorFromChoice(operator), -// Metadata: metadata, -// }, -// }) -// if err != nil { -// return nil, err -// } -// return resp.SubjectMapping, nil -// } - -// func (h Handler) DeleteSubjectMapping(id string) error { -// _, err := h.sdk.SubjectMapping.DeleteSubjectMapping(h.ctx, &subjectmapping.DeleteSubjectMappingRequest{ -// Id: id, -// }) -// if err != nil { -// return err -// } - -// return nil -// } - -// func GetSubjectMappingOperatorFromChoice(readable string) subjectmapping.SubjectMappingOperatorEnum { -// switch readable { -// case SubjectMappingOperatorIn: -// return subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN -// case SubjectMappingOperatorNotIn: -// return subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN -// case SubjectMappingOperatorUnspecified: -// return subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED -// default: -// return subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED -// } -// } - -// func GetSubjectMappingOperatorChoiceFromEnum(enum subjectmapping.SubjectMappingOperatorEnum) string { -// switch enum { -// case subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN: -// return SubjectMappingOperatorIn -// case subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN: -// return SubjectMappingOperatorNotIn -// case subjectmapping.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED: -// return SubjectMappingOperatorUnspecified -// default: -// return SubjectMappingOperatorUnspecified -// } -// } - -func placeholder() { - fmt.Println("This is a placeholder for the subjectmappings.go file, once the subject mappings have been stablized") +const ( + SubjectMappingOperatorIn = "IN" + SubjectMappingOperatorNotIn = "NOT_IN" + SubjectMappingOperatorUnspecified = "UNSPECIFIED" +) + +var SubjectMappingOperatorEnumChoices = []string{SubjectMappingOperatorIn, SubjectMappingOperatorNotIn, SubjectMappingOperatorUnspecified} + +func (h Handler) GetSubjectMapping(id string) (*policy.SubjectMapping, error) { + resp, err := h.sdk.SubjectMapping.GetSubjectMapping(h.ctx, &subjectmapping.GetSubjectMappingRequest{ + Id: id, + }) + if err != nil { + return nil, err + } + + return resp.SubjectMapping, nil +} + +func (h Handler) ListSubjectMappings() ([]*policy.SubjectMapping, error) { + resp, err := h.sdk.SubjectMapping.ListSubjectMappings(h.ctx, &subjectmapping.ListSubjectMappingsRequest{}) + if err != nil { + return nil, err + } + + return resp.SubjectMappings, nil +} + +func (h Handler) CreateNewSubjectMapping(attributeValueId string, subjectAttribute string, subjectValues []string, operator string, metadata *common.MetadataMutable) (*policy.SubjectMapping, error) { + if !slices.Contains(SubjectMappingOperatorEnumChoices, operator) { + return nil, fmt.Errorf("Invalid operator. Must be one of [%s]" + strings.Join(SubjectMappingOperatorEnumChoices, ", ")) + } + + resp, err := h.sdk.SubjectMapping.CreateSubjectMapping(h.ctx, &subjectmapping.CreateSubjectMappingRequest{ + AttributeValueId: attributeValueId, + // SubjectAttribute: subjectAttribute, + // SubjectValues: subjectValues, + // Operator: GetSubjectMappingOperatorFromChoice(operator), + Metadata: metadata, + }) + if err != nil { + return nil, err + } + + return resp.SubjectMapping, nil +} + +func (h Handler) UpdateSubjectMapping(id string, attributeValueId string, subjectAttribute string, subjectValues []string, operator string, metadata *common.MetadataMutable) (*policy.SubjectMapping, error) { + if !slices.Contains(SubjectMappingOperatorEnumChoices, operator) { + return nil, fmt.Errorf("Invalid operator. Must be one of [%s]" + strings.Join(SubjectMappingOperatorEnumChoices, ", ")) + } + + resp, err := h.sdk.SubjectMapping.UpdateSubjectMapping(h.ctx, &subjectmapping.UpdateSubjectMappingRequest{ + Id: id, + // SubjectAttribute: subjectAttribute, + // SubjectValues: subjectValues, + // Operator: GetSubjectMappingOperatorFromChoice(operator), + Metadata: metadata, + }) + if err != nil { + return nil, err + } + return resp.SubjectMapping, nil +} + +func (h Handler) DeleteSubjectMapping(id string) error { + _, err := h.sdk.SubjectMapping.DeleteSubjectMapping(h.ctx, &subjectmapping.DeleteSubjectMappingRequest{ + Id: id, + }) + if err != nil { + return err + } + + return nil +} + +func GetSubjectMappingOperatorFromChoice(readable string) policy.SubjectMappingOperatorEnum { + switch readable { + case SubjectMappingOperatorIn: + return policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN + case SubjectMappingOperatorNotIn: + return policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN + case SubjectMappingOperatorUnspecified: + return policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED + default: + return policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED + } } -func main() { - placeholder() +func GetSubjectMappingOperatorChoiceFromEnum(enum policy.SubjectMappingOperatorEnum) string { + switch enum { + case policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN: + return SubjectMappingOperatorIn + case policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN: + return SubjectMappingOperatorNotIn + case policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_UNSPECIFIED: + return SubjectMappingOperatorUnspecified + default: + return SubjectMappingOperatorUnspecified + } } diff --git a/tructl.yaml b/tructl.yaml new file mode 100644 index 00000000..5dedadc4 --- /dev/null +++ b/tructl.yaml @@ -0,0 +1,2 @@ +output: + format: styled diff --git a/tui/form/addAttribute.go b/tui/form/addAttribute.go index 7f31ffa7..f2bb3163 100644 --- a/tui/form/addAttribute.go +++ b/tui/form/addAttribute.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/charmbracelet/huh" - "github.com/opentdf/platform/protocol/go/policy/attributes" + "github.com/opentdf/platform/protocol/go/policy" ) type AttributeDefinition struct { @@ -13,7 +13,7 @@ type AttributeDefinition struct { Description string Labels map[string]string Type string - Rule attributes.AttributeRuleTypeEnum + Rule policy.AttributeRuleTypeEnum Values []string } @@ -40,12 +40,12 @@ func AddAttribute() (AttributeDefinition, error) { Value(&attr.Description), // Select Rule - huh.NewSelect[attributes.AttributeRuleTypeEnum](). + huh.NewSelect[policy.AttributeRuleTypeEnum](). Title("Rule"). Options( - huh.NewOption("All Of", attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF), - huh.NewOption("Any Of", attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF), - huh.NewOption("Hierarchical", attributes.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY), + huh.NewOption("All Of", policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF), + huh.NewOption("Any Of", policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF), + huh.NewOption("Hierarchical", policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY), ). Value(&attr.Rule), ),