Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add cli attribute values crud #49

Merged
merged 19 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The CLI is configured via the `tructl.yaml`. There is an example provided in `ex

Run `cp example-tructl.yaml tructl.yaml` to copy the example config when running the CLI.

Load up the platform (see its [README](https://github.com/opentdf/platform?tab=readme-ov-file#run) for instructions).

## Development

### CLI
Expand Down
16 changes: 7 additions & 9 deletions cmd/auth-login.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (
"github.com/zalando/go-keyring"
)

var (
auth_loginCommands = []string{
// auth_loginPassword.Use,
auth_loginClientCredentials.Use,
}
)
var auth_loginCommands = []string{
// auth_loginPassword.Use,
auth_loginClientCredentials.Use,
}

var auth_loginCmd = &cobra.Command{
Use: "login",
Expand Down Expand Up @@ -53,7 +51,7 @@ var auth_loginClientCredentials = &cobra.Command{
if clientId == "" {
errMsg = fmt.Sprintf("Please provide required flag: (%s)", "clientId")
fmt.Println(cli.ErrorMessage(errMsg, nil))
cli.ExitWithError("Could not create attribute", nil)
cli.ExitWithError("Failed to create attribute", nil)
return
}

Expand All @@ -69,12 +67,12 @@ var auth_loginClientCredentials = &cobra.Command{
if clientSecret == "" {
errMsg = fmt.Sprintf("Please provide required flag: (%s)", "clientSecret")
fmt.Println(cli.ErrorMessage(errMsg, nil))
cli.ExitWithError("Could not create attribute", nil)
cli.ExitWithError("Failed to create attribute", nil)
return
}

// for now we're hardcoding the TOKEN_URL as a constant at the top
var _, err = h.GetTokenWithClientCredentials(clientId, clientSecret, handlers.TOKEN_URL, false)
_, err := h.GetTokenWithClientCredentials(clientId, clientSecret, handlers.TOKEN_URL, false)

if err != nil {
errMsg = cli.ErrorMessage("An error occurred during login. Please check your credentials and try again.", nil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func unMarshalMetadata(m string) *common.MetadataMutable {
if m != "" {
metadata := &common.MetadataMutable{}
if err := json.Unmarshal([]byte(m), metadata); err != nil {
cli.ExitWithError("Could not unmarshal metadata", err)
cli.ExitWithError("Failed to unmarshal metadata", err)
}
return metadata
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/kas-grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ var (
if attr != "" {
res, err = h.UpdateKasGrantForAttribute(attr, kas)
if err != nil {
cli.ExitWithError("Could not update KAS grant for attribute", err)
cli.ExitWithError("Failed to update KAS grant for attribute", err)
}
id = attr
header = "Attribute ID"
} else {
res, err = h.UpdateKasGrantForValue(val, kas)
if err != nil {
cli.ExitWithError("Could not update KAS grant for attribute value", err)
cli.ExitWithError("Failed to update KAS grant for attribute value", err)
}
id = val
header = "Value ID"
Expand Down Expand Up @@ -90,19 +90,19 @@ var (
err error
)

cli.ConfirmDelete("KAS ID: ", kas)
cli.ConfirmAction(cli.ActionDelete, "KAS ID: ", kas)

if attr != "" {
res, err = h.DeleteKasGrantFromAttribute(attr, kas)
if err != nil {
cli.ExitWithError("Could not update KAS grant for attribute", err)
cli.ExitWithError("Failed to update KAS grant for attribute", err)
}
id = attr
header = "Attribute ID"
} else {
_, err := h.DeleteKasGrantFromValue(val, kas)
if err != nil {
cli.ExitWithError("Could not update KAS grant for attribute value", err)
cli.ExitWithError("Failed to update KAS grant for attribute value", err)
}
id = val
header = "Value ID"
Expand Down
20 changes: 10 additions & 10 deletions cmd/kas-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ var (

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

keyType := "Local"
Expand Down Expand Up @@ -76,7 +76,7 @@ var (

list, err := h.ListKasRegistryEntries()
if err != nil {
cli.ExitWithError("Could not get KAS registry entries", err)
cli.ExitWithError("Failed to list KAS registry entries", err)
}

t := cli.NewTable()
Expand Down Expand Up @@ -138,7 +138,7 @@ var (
getMetadataMutable(metadataLabels),
)
if err != nil {
cli.ExitWithError("Could not create KAS registry entry", err)
cli.ExitWithError("Failed to create KAS registry entry", err)
}

t := cli.NewTabular().
Expand Down Expand Up @@ -193,7 +193,7 @@ var (
getMetadataUpdateBehavior(),
)
if err != nil {
cli.ExitWithError("Could not update KAS registry entry", err)
cli.ExitWithError(fmt.Sprintf("Failed to update KAS registry entry (%s)", id), err)
}
t := cli.NewTabular().
Rows([][]string{
Expand All @@ -217,14 +217,14 @@ var (

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

cli.ConfirmDelete("KAS Registry Entry: ", id)
cli.ConfirmAction(cli.ActionDelete, "KAS Registry Entry: ", id)

if err := h.DeleteKasRegistryEntry(id); err != nil {
errMsg := fmt.Sprintf("Could not delete KAS registry entry (%s)", id)
if _, err := h.DeleteKasRegistryEntry(id); err != nil {
errMsg := fmt.Sprintf("Failed to delete KAS registry entry (%s)", id)
cli.ExitWithError(errMsg, err)
}

Expand Down
Loading
Loading