(c flags.FlagContext)
| 67 | } |
| 68 | |
| 69 | func (cmd *ServiceKey) Execute(c flags.FlagContext) error { |
| 70 | serviceInstance := cmd.serviceInstanceRequirement.GetServiceInstance() |
| 71 | serviceKeyName := c.Args()[1] |
| 72 | |
| 73 | if !c.Bool("guid") { |
| 74 | cmd.ui.Say(T("Getting key {{.ServiceKeyName}} for service instance {{.ServiceInstanceName}} as {{.CurrentUser}}...", |
| 75 | map[string]interface{}{ |
| 76 | "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), |
| 77 | "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name), |
| 78 | "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), |
| 79 | })) |
| 80 | } |
| 81 | |
| 82 | serviceKey, err := cmd.serviceKeyRepo.GetServiceKey(serviceInstance.GUID, serviceKeyName) |
| 83 | if err != nil { |
| 84 | switch err.(type) { |
| 85 | case *errors.NotAuthorizedError: |
| 86 | cmd.ui.Say(T("No service key {{.ServiceKeyName}} found for service instance {{.ServiceInstanceName}}", |
| 87 | map[string]interface{}{ |
| 88 | "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), |
| 89 | "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name)})) |
| 90 | return nil |
| 91 | default: |
| 92 | return err |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if c.Bool("guid") { |
| 97 | cmd.ui.Say(serviceKey.Fields.GUID) |
| 98 | } else { |
| 99 | if serviceKey.Fields.Name == "" { |
| 100 | return errors.New( |
| 101 | T("No service key {{.ServiceKeyName}} found for service instance {{.ServiceInstanceName}}", |
| 102 | map[string]interface{}{ |
| 103 | "ServiceKeyName": terminal.EntityNameColor(serviceKeyName), |
| 104 | "ServiceInstanceName": terminal.EntityNameColor(serviceInstance.Name)})) |
| 105 | } |
| 106 | |
| 107 | jsonBytes, err := json.MarshalIndent(serviceKey.Credentials, "", " ") |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | cmd.ui.Say("") |
| 113 | cmd.ui.Say(string(jsonBytes)) |
| 114 | } |
| 115 | return nil |
| 116 | } |
nothing calls this directly
no test coverage detected