public Check createCheck()

in sources/src/main/java/com/google/solutions/jitaccess/catalog/policy/ExpiryConstraint.java [119:180]


  public Check createCheck() {
    return new Check() {
      private @Nullable Duration userProvidedDuration = null;

      @Override
      public @NotNull Constraint constraint() {
        return ExpiryConstraint.this;
      }

      @Override
      public @NotNull List<Property> input() {
        if(isFixedDuration()) {
          //
          // No input needed.
          //
          return List.of();
        }
        else {
          return List.of(new AbstractDurationProperty(NAME, "Expiry", true, ExpiryConstraint.this.minDuration,
            ExpiryConstraint.this.maxDuration) {
            @Override
            protected void setCore(@Nullable Duration value) {
              userProvidedDuration = value;
            }

            @Override
            protected @Nullable Duration getCore() {
              return userProvidedDuration;
            }
          });
        }
      }

      @Override
      public @NotNull Context addContext(@NotNull String name) {
        //
        // We don't use contexts.
        //
        return new Context() {
          @Override
          public Context set(@NotNull String name, @NotNull Object val) {
            return this;
          }
        };
      }

      @Override
      public @NotNull Boolean evaluate() {
        if (isFixedDuration()) {
          return true;
        }
        else {
          //
          // Verify that the user-provided duration is within range.
          //
          return this.userProvidedDuration != null &&
            this.userProvidedDuration.toMinutes() >= ExpiryConstraint.this.minDuration.toMinutes() &&
            this.userProvidedDuration.toMinutes() <= ExpiryConstraint.this.maxDuration.toMinutes();
        }
      }
    };
  }