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

Function sshGen

cmd/cloudflared/access/cmd.go:431–464  ·  view source on GitHub ↗

sshGen generates a short lived certificate for provided hostname

(c *cli.Context)

Source from the content-addressed store, hash-verified

429
430// sshGen generates a short lived certificate for provided hostname
431func sshGen(c *cli.Context) error {
432 log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)
433
434 // get the hostname from the cmdline and error out if its not provided
435 rawHostName := c.String(sshHostnameFlag)
436 hostname, err := validation.ValidateHostname(rawHostName)
437 if err != nil || rawHostName == "" {
438 return cli.ShowCommandHelp(c, "ssh-gen")
439 }
440
441 originURL, err := parseURL(hostname)
442 if err != nil {
443 return err
444 }
445
446 // this fetchToken function mutates the appURL param. We should refactor that
447 fetchTokenURL := &url.URL{}
448 *fetchTokenURL = *originURL
449
450 appInfo, err := token.GetAppInfo(fetchTokenURL)
451 if err != nil {
452 return err
453 }
454 cfdToken, err := token.FetchTokenWithRedirect(fetchTokenURL, appInfo, c.Bool(cfdflags.AutoCloseInterstitial), c.Bool(fedrampFlag), log)
455 if err != nil {
456 return err
457 }
458
459 if err := sshgen.GenerateShortLivedCertificate(originURL, cfdToken); err != nil {
460 return err
461 }
462
463 return nil
464}
465
466// getAppURL will pull the request URL needed for fetching a user's Access token
467func getAppURL(cmdArgs []string, log *zerolog.Logger) (*url.URL, error) {

Callers

nothing calls this directly

Calls 8

CreateLoggerFromContextFunction · 0.92
ValidateHostnameFunction · 0.92
GetAppInfoFunction · 0.92
FetchTokenWithRedirectFunction · 0.92
parseURLFunction · 0.85
BoolMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected