| 422 | } |
| 423 | |
| 424 | func parseEffectiveTime(choosenTime string) (*time.Time, error) { |
| 425 | switch { |
| 426 | case isNow(choosenTime): |
| 427 | now := now().UTC() |
| 428 | log.Debugf("Chosen to use effective time of `now`, using current time %s", now.Format(time.RFC3339)) |
| 429 | return &now, nil |
| 430 | case strings.EqualFold(choosenTime, AtAttestation): |
| 431 | log.Debugf("Chosen to use effective time of `attestation`") |
| 432 | return nil, nil |
| 433 | default: |
| 434 | var err error |
| 435 | if when, err := time.Parse(time.RFC3339, choosenTime); err == nil { |
| 436 | log.Debugf("Using provided effective time %s", when.Format(time.RFC3339)) |
| 437 | whenUTC := when.UTC() |
| 438 | return &whenUTC, nil |
| 439 | } |
| 440 | |
| 441 | log.Debugf("Unable to parse provided effective time `%s` using RFC3339", choosenTime) |
| 442 | errs := err |
| 443 | |
| 444 | if when, err := time.Parse(DateFormat, choosenTime); err == nil { |
| 445 | log.Debugf("Using provided effective time %s", when.Format(time.RFC3339)) |
| 446 | whenUTC := when.UTC() |
| 447 | return &whenUTC, nil |
| 448 | } |
| 449 | log.Debugf("Unable to parse provided effective time string `%s` using %s format", choosenTime, DateFormat) |
| 450 | errs = errors.Join(errs, err) |
| 451 | |
| 452 | return nil, fmt.Errorf("invalid policy time argument: %s", errs) |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | // checkOpts returns an instance based on attributes of the Policy. |
| 457 | func checkOpts(ctx context.Context, p *policy) (*cosign.CheckOpts, error) { |