sshGen generates a short lived certificate for provided hostname
(c *cli.Context)
| 429 | |
| 430 | // sshGen generates a short lived certificate for provided hostname |
| 431 | func 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 |
| 467 | func getAppURL(cmdArgs []string, log *zerolog.Logger) (*url.URL, error) { |
nothing calls this directly
no test coverage detected