tokenCommand handles the token subcommand execution
(c *cli.Context)
| 67 | |
| 68 | // tokenCommand handles the token subcommand execution |
| 69 | func tokenCommand(c *cli.Context) error { |
| 70 | log := cliutil.CreateStderrLogger(c) |
| 71 | |
| 72 | // Parse and validate resource flag |
| 73 | resourceStr := c.String("resource") |
| 74 | resource, err := parseResource(resourceStr) |
| 75 | if err != nil { |
| 76 | return fmt.Errorf("invalid resource '%s': %w", resourceStr, err) |
| 77 | } |
| 78 | |
| 79 | // Get management token |
| 80 | token, err := cliutil.GetManagementToken(c, log, resource, buildInfo) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | // Output JSON to stdout |
| 86 | tokenResponse := struct { |
| 87 | Token string `json:"token"` |
| 88 | }{Token: token} |
| 89 | |
| 90 | return json.NewEncoder(os.Stdout).Encode(tokenResponse) |
| 91 | } |
| 92 | |
| 93 | // parseResource converts resource string to ManagementResource enum |
| 94 | func parseResource(resource string) (cfapi.ManagementResource, error) { |
nothing calls this directly
no test coverage detected