Skip to content

Commit

Permalink
chore: improve csb commands (#900)
Browse files Browse the repository at this point in the history
* chore: print upgrade status as part of csb service output

* chore: add csb service-key command
  • Loading branch information
pivotal-marcela-campo authored Nov 16, 2023
1 parent 32ca193 commit 6370bed
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The mimic commands are:
- `csb delete-service` - deletes a service instance
- `csb create-service-key` - creates a "binding" and prints credentials
- `csb service-keys` - lists service keys
- `csb service-key` - prints a service key
- `csb delete-service-key` - deletes a "binding"

The mimic commands build a brokerpak, start an ephemeral CSB server and send OSBAPI
Expand Down
12 changes: 11 additions & 1 deletion cmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func init() {

createServiceKeyCmd := &cobra.Command{
Use: "create-service-key SERVICE_INSTANCE SERVICE_KEY",
Short: "EXPERIMENTAL AND SUBJECT TO BREAKING CHANGE: create a service instance",
Short: "EXPERIMENTAL AND SUBJECT TO BREAKING CHANGE: create a service key",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
local.CreateServiceKey(args[0], args[1], params, viper.GetString(pakCachePath))
Expand All @@ -98,6 +98,16 @@ func init() {
createServiceKeyCmd.Flags().StringVarP(&params, paramsFlag, paramsFlag, "", "parameters as JSON")
rootCmd.AddCommand(createServiceKeyCmd)

serviceKeyCmd := &cobra.Command{
Use: "service-key SERVICE_INSTANCE SERVICE_KEY",
Short: "EXPERIMENTAL AND SUBJECT TO BREAKING CHANGE: print a service key",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
local.ServiceKey(args[0], args[1])
},
}
rootCmd.AddCommand(serviceKeyCmd)

serviceKeysCmd := &cobra.Command{
Use: "service-keys NAME",
Short: "EXPERIMENTAL AND SUBJECT TO BREAKING CHANGE: list service keys for a service instance",
Expand Down
3 changes: 3 additions & 0 deletions internal/local/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func lookupPlanMaintenanceInfoByGUID(clnt *client.Client, serviceID, planGUID st
if s.ID == serviceID {
for _, p := range s.Plans {
if p.ID == planGUID {
if p.MaintenanceInfo == nil {
return domain.MaintenanceInfo{}
}
return *p.MaintenanceInfo
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/local/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func Service(name, cachePath string) {
tfVersion, _ := deployment.TFWorkspace().StateTFVersion()

tp.row("")
tp.row("Showing upgrade status: Terraform version in state is ", tfVersion.String())

tp.row("Showing upgrade status:")
tp.row("Terraform version in state is ", tfVersion.String())
mInfo := lookupPlanMaintenanceInfoByGUID(broker.Client, instance.ServiceGUID, instance.PlanGUID)
tp.row("Plan version is ", mInfo.Version)
tp.print()
}
16 changes: 16 additions & 0 deletions internal/local/service_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package local

import (
"encoding/json"
"fmt"
"log"
)

func ServiceKey(serviceInstanceName, serviceKeyName string) {
credentials, err := store().GetServiceBindingCredentials(nameToID(serviceKeyName), nameToID(serviceInstanceName))
if err != nil {
log.Fatal(err)
}
bytes, _ := json.Marshal(credentials.Credentials)
fmt.Printf("\nService Key: %s\n", bytes)
}

0 comments on commit 6370bed

Please sign in to comment.