MCPcopy
hub / github.com/cloudflare/cloudflared / tokenCommand

Function tokenCommand

cmd/cloudflared/management/cmd.go:69–91  ·  view source on GitHub ↗

tokenCommand handles the token subcommand execution

(c *cli.Context)

Source from the content-addressed store, hash-verified

67
68// tokenCommand handles the token subcommand execution
69func 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
94func parseResource(resource string) (cfapi.ManagementResource, error) {

Callers

nothing calls this directly

Calls 6

CreateStderrLoggerFunction · 0.92
GetManagementTokenFunction · 0.92
parseResourceFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.65
EncodeMethod · 0.45

Tested by

no test coverage detected