MCPcopy Create free account
hub / github.com/conforma/cli / parseEffectiveTime

Function parseEffectiveTime

internal/policy/policy.go:424–454  ·  view source on GitHub ↗
(choosenTime string)

Source from the content-addressed store, hash-verified

422}
423
424func 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.
457func checkOpts(ctx context.Context, p *policy) (*cosign.CheckOpts, error) {

Callers 4

TestParseEffectiveTimeFunction · 0.85
NewOfflinePolicyFunction · 0.85
NewInputPolicyFunction · 0.85
NewPolicyFunction · 0.85

Calls 3

isNowFunction · 0.85
ParseMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestParseEffectiveTimeFunction · 0.68