curl provides a wrapper around curl, passing Access JWT along in request
(c *cli.Context)
| 293 | |
| 294 | // curl provides a wrapper around curl, passing Access JWT along in request |
| 295 | func curl(c *cli.Context) error { |
| 296 | err := sentry.Init(sentry.ClientOptions{ |
| 297 | Dsn: sentryDSN, |
| 298 | Release: c.App.Version, |
| 299 | }) |
| 300 | if err != nil { |
| 301 | return err |
| 302 | } |
| 303 | log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog) |
| 304 | |
| 305 | args := c.Args() |
| 306 | if args.Len() < 1 { |
| 307 | log.Error().Msg("Please provide the access app and command you wish to run.") |
| 308 | return errors.New("incorrect args") |
| 309 | } |
| 310 | |
| 311 | cmdArgs, allowRequest := parseAllowRequest(args.Slice()) |
| 312 | appURL, err := getAppURL(cmdArgs, log) |
| 313 | if err != nil { |
| 314 | return err |
| 315 | } |
| 316 | |
| 317 | appInfo, err := token.GetAppInfo(appURL) |
| 318 | if err != nil { |
| 319 | return err |
| 320 | } |
| 321 | |
| 322 | // Verify that the existing token is still good; if not fetch a new one |
| 323 | if err := verifyTokenAtEdge(appURL, appInfo, c, log); err != nil { |
| 324 | log.Err(err).Msg("Could not verify token") |
| 325 | return err |
| 326 | } |
| 327 | |
| 328 | tok, err := token.GetAppTokenIfExists(appInfo) |
| 329 | if err != nil || tok == "" { |
| 330 | if allowRequest { |
| 331 | log.Info().Msg("You don't have an Access token set. Please run access token <access application> to fetch one.") |
| 332 | return run("curl", cmdArgs...) |
| 333 | } |
| 334 | tok, err = token.FetchToken(appURL, appInfo, c.Bool(cfdflags.AutoCloseInterstitial), c.Bool(fedrampFlag), log) |
| 335 | if err != nil { |
| 336 | log.Err(err).Msg("Failed to refresh token") |
| 337 | return err |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | cmdArgs = append(cmdArgs, "-H") |
| 342 | cmdArgs = append(cmdArgs, fmt.Sprintf("%s: %s", carrier.CFAccessTokenHeader, tok)) |
| 343 | return run("curl", cmdArgs...) |
| 344 | } |
| 345 | |
| 346 | // run kicks off a shell task and pipe the results to the respective std pipes |
| 347 | func run(cmd string, args ...string) error { |
nothing calls this directly
no test coverage detected