Skip to content

Commit

Permalink
i/prompting: use *time.Time for expiration
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
  • Loading branch information
olivercalder committed Apr 24, 2024
1 parent 2458279 commit 90d08d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions interfaces/prompting/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func abstractPermissionsToAppArmorFilePermissions(iface string, permissions []st

// ValidateConstraintsOutcomeLifespanExpiration returns an error if the given
// constraints, outcome, lifespan, or duration are invalid, else returns nil.
func ValidateConstraintsOutcomeLifespanExpiration(iface string, constraints *Constraints, outcome OutcomeType, lifespan LifespanType, expiration string, currTime time.Time) error {
func ValidateConstraintsOutcomeLifespanExpiration(iface string, constraints *Constraints, outcome OutcomeType, lifespan LifespanType, expiration *time.Time, currTime time.Time) error {
if err := constraints.ValidateForInterface(iface); err != nil {
return err
}
Expand All @@ -252,12 +252,12 @@ func ValidateConstraintsOutcomeLifespanExpiration(iface string, constraints *Con
// ValidateConstraintsOutcomeLifespanDuration returns an error if the given
// constraints, outcome, lifespan, or duration are invalid. Otherwise, converts
// the given duration to an expiration timestamp and returns it and nil error.
func ValidateConstraintsOutcomeLifespanDuration(iface string, constraints *Constraints, outcome OutcomeType, lifespan LifespanType, duration string) (string, error) {
func ValidateConstraintsOutcomeLifespanDuration(iface string, constraints *Constraints, outcome OutcomeType, lifespan LifespanType, duration string) (*time.Time, error) {
if err := constraints.ValidateForInterface(iface); err != nil {
return "", err
return nil, err
}
if err := ValidateOutcome(outcome); err != nil {
return "", err
return nil, err
}
return ValidateLifespanParseDuration(lifespan, duration)
}
16 changes: 8 additions & 8 deletions interfaces/prompting/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,20 @@ func (s *promptingSuite) TestValidateConstraintsOutcomeLifespanExpiration(c *C)
goodLifespan := prompting.LifespanTimespan
badLifespan := prompting.LifespanType("foo")
currTime := time.Now()
goodExpiration := currTime.Add(10 * time.Second).Format(time.RFC3339)
badExpiration := currTime.Add(-1 * time.Second).Format(time.RFC3339)
goodExpiration := currTime.Add(10 * time.Second)
badExpiration := currTime.Add(-1 * time.Second)

err := prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, goodLifespan, goodExpiration, currTime)
err := prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, goodLifespan, &goodExpiration, currTime)
c.Check(err, IsNil)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(badInterface, goodConstraints, goodOutcome, goodLifespan, goodExpiration, currTime)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(badInterface, goodConstraints, goodOutcome, goodLifespan, &goodExpiration, currTime)
c.Check(err, NotNil)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, badConstraints, goodOutcome, goodLifespan, goodExpiration, currTime)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, badConstraints, goodOutcome, goodLifespan, &goodExpiration, currTime)
c.Check(err, ErrorMatches, "unsupported permission.*")
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, badOutcome, goodLifespan, goodExpiration, currTime)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, badOutcome, goodLifespan, &goodExpiration, currTime)
c.Check(err, ErrorMatches, "invalid outcome.*")
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, badLifespan, goodExpiration, currTime)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, badLifespan, &goodExpiration, currTime)
c.Check(err, ErrorMatches, "invalid lifespan.*")
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, goodLifespan, badExpiration, currTime)
err = prompting.ValidateConstraintsOutcomeLifespanExpiration(goodInterface, goodConstraints, goodOutcome, goodLifespan, &badExpiration, currTime)
c.Check(err, ErrorMatches, "invalid expiration.*")
}

Expand Down

0 comments on commit 90d08d9

Please sign in to comment.