Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,35 @@ public record DeploymentRequestView(
VerificationStatus verificationStatus,
Instant verificationStartedAt,
Instant verificationFinishedAt,
String verificationDetail) {
String verificationDetail,
/** The config snapshot the window was opened with (#1027); null when never verified. */
DeploymentVerificationSnapshotView verificationSnapshot) {

/** Backward-compatible constructor without the #1027 verification snapshot. */
public DeploymentRequestView(UUID id, UUID pipelineId, String pipelineName, PipelineProvider provider,
UUID environmentId, String environmentName, UUID submittedBy,
String submittedByEmail, String version, String commitSha,
String artifactRef, String runUrl, String externalRunId,
Map<String, Object> metadata, QueryStatus status,
SubmissionReason submissionReason, String justification,
UUID aiAnalysisId, RiskLevel aiRiskLevel, Integer aiRiskScore,
String aiSummary, int requiredApprovals, Instant scheduledFor,
DeploymentOutcome outcome, Instant outcomeReportedAt,
String outcomeDetail, Instant createdAt,
List<DeploymentReviewDecisionView> decisions, UUID onBehalfOfUserId,
String onBehalfOfEmail, boolean changeTicketRequired,
DeploymentTicketView changeTicket,
VerificationStatus verificationStatus,
Instant verificationStartedAt, Instant verificationFinishedAt,
String verificationDetail) {
this(id, pipelineId, pipelineName, provider, environmentId, environmentName, submittedBy,
submittedByEmail, version, commitSha, artifactRef, runUrl, externalRunId, metadata,
status, submissionReason, justification, aiAnalysisId, aiRiskLevel, aiRiskScore,
aiSummary, requiredApprovals, scheduledFor, outcome, outcomeReportedAt, outcomeDetail,
createdAt, decisions, onBehalfOfUserId, onBehalfOfEmail, changeTicketRequired,
changeTicket, verificationStatus, verificationStartedAt, verificationFinishedAt,
verificationDetail, null);
}

/** Backward-compatible constructor without the #874 on-behalf-of principal. */
public DeploymentRequestView(UUID id, UUID pipelineId, String pipelineName, PipelineProvider provider,
Expand All @@ -75,7 +103,7 @@ public DeploymentRequestView(UUID id, UUID pipelineId, String pipelineName, Pipe
status, submissionReason, justification, aiAnalysisId, aiRiskLevel, aiRiskScore,
aiSummary, requiredApprovals, scheduledFor, outcome, outcomeReportedAt, outcomeDetail,
createdAt, decisions, null, null, false, null, VerificationStatus.PENDING, null, null,
null);
null, null);
}

public DeploymentRequestView {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.bablsoft.accessflow.deploygov.api;

import java.time.Duration;

/**
* The verification config a request was verified against (#1027), as snapshotted when its window
* opened. Deliberately carries no check URLs or queries: the request detail is readable by its
* submitter and reviewers, while an environment's config is admin-only.
*/
public record DeploymentVerificationSnapshotView(Duration window, Duration sampleInterval,
int failureThreshold, int checkCount) {

public static DeploymentVerificationSnapshotView of(DeploymentVerificationConfig config) {
return config == null ? null
: new DeploymentVerificationSnapshotView(config.window(), config.sampleInterval(),
config.failureThreshold(), config.checks().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.bablsoft.accessflow.deploygov.api.DeploymentRequestSubmissionResult;
import com.bablsoft.accessflow.deploygov.api.DeploymentRequestView;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationSampleView;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationSnapshotView;
import com.bablsoft.accessflow.deploygov.api.DeploymentReviewDecisionView;
import com.bablsoft.accessflow.deploygov.api.DeploymentTicketView;
import com.bablsoft.accessflow.deploygov.api.FreezeBehavior;
Expand All @@ -37,7 +38,9 @@
import com.bablsoft.accessflow.deploygov.internal.persistence.repo.DeploymentReviewDecisionRepository;
import com.bablsoft.accessflow.deploygov.internal.persistence.repo.DeploymentTicketRepository;
import com.bablsoft.accessflow.deploygov.internal.persistence.repo.DeploymentVerificationRepository;
import com.bablsoft.accessflow.deploygov.internal.verification.DeploymentVerificationConfigCodec;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
Expand All @@ -61,6 +64,7 @@
* trigger is idempotent on the CI run identity, and an active {@code REJECT} freeze window
* auto-rejects at submission.
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class DefaultDeploymentRequestService implements DeploymentRequestService {
Expand Down Expand Up @@ -88,6 +92,7 @@ public class DefaultDeploymentRequestService implements DeploymentRequestService
private final ObjectMapper objectMapper;
private final Clock clock;
private final DeploymentVerificationRepository verificationRepository;
private final DeploymentVerificationConfigCodec verificationConfigCodec;

@Override
@Transactional
Expand Down Expand Up @@ -435,7 +440,21 @@ private DeploymentRequestView toView(DeploymentRequestEntity entity,
entity.getVerificationStatus(),
entity.getVerificationStartedAt(),
entity.getVerificationFinishedAt(),
entity.getVerificationDetail());
entity.getVerificationDetail(),
readVerificationSnapshot(entity));
}

/** Fail-soft on read: an unreadable snapshot hides the card; the job already failed it closed. */
private DeploymentVerificationSnapshotView readVerificationSnapshot(
DeploymentRequestEntity entity) {
try {
return DeploymentVerificationSnapshotView.of(
verificationConfigCodec.fromJson(entity.getVerificationConfig()));
} catch (DeploymentVerificationConfigCodec.VerificationConfigParseException ex) {
log.debug("Unreadable verification snapshot on deployment request {}: {}",
entity.getId(), ex.getMessage());
return null;
}
}

private Map<String, Object> readMetadata(String json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.bablsoft.accessflow.core.api.SubmissionReason;
import com.bablsoft.accessflow.deploygov.api.DeploymentOutcome;
import com.bablsoft.accessflow.deploygov.api.DeploymentRequestView;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationSnapshotView;
import com.bablsoft.accessflow.deploygov.api.PipelineProvider;
import com.bablsoft.accessflow.deploygov.api.VerificationStatus;

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -54,7 +56,26 @@ public record DeploymentRequestResponse(
VerificationStatus verificationStatus,
Instant verificationStartedAt,
Instant verificationFinishedAt,
String verificationDetail) {
String verificationDetail,
/** The config the window was opened with (#1027); null (omitted) when never verified. */
VerificationSnapshot verificationSnapshot) {

/** Window and interval as ISO-8601 strings; no check URLs or queries. */
public record VerificationSnapshot(String window, String sampleInterval, int failureThreshold,
int checkCount) {

static VerificationSnapshot from(DeploymentVerificationSnapshotView view) {
if (view == null) {
return null;
}
return new VerificationSnapshot(iso(view.window()), iso(view.sampleInterval()),
view.failureThreshold(), view.checkCount());
}

private static String iso(Duration duration) {
return duration == null ? null : duration.toString();
}
}

/** Every path but the detail read: reviewer eligibility is a detail-read concern, never computed here. */
static DeploymentRequestResponse from(DeploymentRequestView view) {
Expand All @@ -75,6 +96,7 @@ static DeploymentRequestResponse from(DeploymentRequestView view, boolean canRev
view.changeTicketRequired(),
DeploymentChangeTicketResponse.from(view.changeTicket()),
view.verificationStatus(), view.verificationStartedAt(),
view.verificationFinishedAt(), view.verificationDetail());
view.verificationFinishedAt(), view.verificationDetail(),
VerificationSnapshot.from(view.verificationSnapshot()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import com.bablsoft.accessflow.core.api.UserQueryService;
import com.bablsoft.accessflow.core.api.UserRoleType;
import com.bablsoft.accessflow.core.api.UserView;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationConfig;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationSnapshotView;
import com.bablsoft.accessflow.deploygov.api.HttpHealthCheck;
import com.bablsoft.accessflow.deploygov.internal.verification.DeploymentVerificationConfigCodec;
import com.bablsoft.accessflow.deploygov.api.DeploymentBreakGlassNotAllowedException;
import com.bablsoft.accessflow.deploygov.api.DeploymentEnvironmentNotFoundException;
import com.bablsoft.accessflow.deploygov.api.DeploymentPipelineNotFoundException;
Expand Down Expand Up @@ -49,6 +53,7 @@
import tools.jackson.databind.json.JsonMapper;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.List;
Expand Down Expand Up @@ -116,7 +121,8 @@ void setUp() {
permissionResolver,
freezeWindowEvaluator, stateService, auditWriter, aiAnalysisLookupService,
userQueryService, eventPublisher, JsonMapper.builder().build(), CLOCK,
verificationRepository);
verificationRepository,
new DeploymentVerificationConfigCodec(JsonMapper.builder().build()));

pipeline = pipeline();
environment = environment();
Expand Down Expand Up @@ -631,6 +637,41 @@ void getCarriesTheVerificationState() {
assertThat(view.verificationStartedAt()).isEqualTo(started);
assertThat(view.verificationFinishedAt()).isEqualTo(started.plusSeconds(60));
assertThat(view.verificationDetail()).isEqualTo("health: 1/1 failed samples");
assertThat(view.verificationSnapshot()).isNull();
}

@Test
void getCarriesTheVerificationSnapshotWithoutCheckTargets() {
var entity = existing(QueryStatus.EXECUTED);
entity.setVerificationStatus(VerificationStatus.RUNNING);
entity.setVerificationConfig(new DeploymentVerificationConfigCodec(JsonMapper.builder().build())
.toJson(new DeploymentVerificationConfig(Duration.ofMinutes(15),
Duration.ofSeconds(30), 3, List.of(
new HttpHealthCheck("health", "https://svc.example.com/healthz", 200,
null),
new HttpHealthCheck("ready", "https://svc.example.com/ready", 204,
"ok")))));
when(requestRepository.findByIdAndOrganizationId(entity.getId(), ORG))
.thenReturn(Optional.of(entity));

var snapshot = service.get(entity.getId(), ORG, SUBMITTER, Set.of()).verificationSnapshot();

assertThat(snapshot).isEqualTo(new DeploymentVerificationSnapshotView(
Duration.ofMinutes(15), Duration.ofSeconds(30), 3, 2));
}

@Test
void getHidesAnUnreadableVerificationSnapshot() {
var entity = existing(QueryStatus.FAILED);
entity.setVerificationStatus(VerificationStatus.FAILED);
entity.setVerificationConfig("{\"window\":\"PT1M\"}");
when(requestRepository.findByIdAndOrganizationId(entity.getId(), ORG))
.thenReturn(Optional.of(entity));

var view = service.get(entity.getId(), ORG, SUBMITTER, Set.of());

assertThat(view.verificationSnapshot()).isNull();
assertThat(view.verificationStatus()).isEqualTo(VerificationStatus.FAILED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bablsoft.accessflow.core.api.QueryStatus;
import com.bablsoft.accessflow.core.api.RiskLevel;
import com.bablsoft.accessflow.core.api.SubmissionReason;
import com.bablsoft.accessflow.deploygov.api.DeploymentVerificationSnapshotView;
import com.bablsoft.accessflow.deploygov.api.DeploymentEnvironmentView;
import com.bablsoft.accessflow.deploygov.api.DeploymentFreezeWindowView;
import com.bablsoft.accessflow.deploygov.api.DeploymentGateView;
Expand All @@ -26,6 +27,7 @@
import tools.jackson.databind.json.JsonMapper;
import tools.jackson.databind.PropertyNamingStrategies;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
import java.util.Map;
Expand Down Expand Up @@ -538,6 +540,60 @@ void deploymentRequestViewDefaultsVerificationStatusAndResponseMapsIt() {
SubmissionReason.USER_SUBMITTED, null, null, null, null, null, 1, null, null, null,
null, Instant.now(), null, null, null, false, null, null, null, null, null);
assertThat(defaulted.verificationStatus()).isEqualTo(VerificationStatus.PENDING);
assertThat(response.verificationSnapshot()).isNull();
}

@Test
void deploymentRequestResponseMapsTheVerificationSnapshotAsIsoDurations() {
var view = new DeploymentRequestView(UUID.randomUUID(), UUID.randomUUID(), "p",
PipelineProvider.GENERIC, UUID.randomUUID(), "prod", UUID.randomUUID(), null,
"1.0.0", null, null, null, null, null, QueryStatus.EXECUTED,
SubmissionReason.USER_SUBMITTED, null, null, null, null, null, 1, null, null, null,
null, Instant.now(), null, null, null, false, null, VerificationStatus.RUNNING,
null, null, null, new DeploymentVerificationSnapshotView(Duration.ofMinutes(15),
Duration.ofSeconds(30), 3, 2));

var snapshot = DeploymentRequestResponse.from(view).verificationSnapshot();

assertThat(snapshot).isEqualTo(
new DeploymentRequestResponse.VerificationSnapshot("PT15M", "PT30S", 3, 2));
assertThat(DeploymentRequestResponse.VerificationSnapshot.from(
new DeploymentVerificationSnapshotView(null, null, 1, 1)))
.isEqualTo(new DeploymentRequestResponse.VerificationSnapshot(null, null, 1, 1));
assertThat(DeploymentVerificationSnapshotView.of(null)).isNull();
}

@Test
void deploymentRequestWireShapeCarriesTheVerificationSnapshotInSnakeCase() {
var mapper = JsonMapper.builder()
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(
JsonInclude.Include.NON_NULL))
.build();
var verified = new DeploymentRequestView(UUID.randomUUID(), UUID.randomUUID(), "p",
PipelineProvider.GENERIC, UUID.randomUUID(), "prod", UUID.randomUUID(), null,
"1.0.0", null, null, null, null, null, QueryStatus.EXECUTED,
SubmissionReason.USER_SUBMITTED, null, null, null, null, null, 1, null, null, null,
null, Instant.now(), null, null, null, false, null, VerificationStatus.RUNNING,
null, null, null, new DeploymentVerificationSnapshotView(Duration.ofMinutes(15),
Duration.ofSeconds(30), 3, 2));

var json = mapper.readTree(mapper.writeValueAsString(DeploymentRequestResponse.from(verified)));

var snapshot = json.get("verification_snapshot");
assertThat(snapshot.get("window").asString()).isEqualTo("PT15M");
assertThat(snapshot.get("sample_interval").asString()).isEqualTo("PT30S");
assertThat(snapshot.get("failure_threshold").asInt()).isEqualTo(3);
assertThat(snapshot.get("check_count").asInt()).isEqualTo(2);

var unverified = new DeploymentRequestView(UUID.randomUUID(), UUID.randomUUID(), "p",
PipelineProvider.GENERIC, UUID.randomUUID(), "prod", UUID.randomUUID(), null,
"1.0.0", null, null, null, null, null, QueryStatus.APPROVED,
SubmissionReason.USER_SUBMITTED, null, null, null, null, null, 1, null, null, null,
null, Instant.now(), null);
var plain = mapper.readTree(
mapper.writeValueAsString(DeploymentRequestResponse.from(unverified)));
assertThat(plain.has("verification_snapshot")).isFalse();
}

@Test
Expand Down
8 changes: 7 additions & 1 deletion docs/04-api-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -9516,7 +9516,13 @@ back. Break-glass deployments are verified like any other.
Request detail and list bodies carry `verification_status`, `verification_started_at`,
`verification_finished_at` and `verification_detail` (breach detail reads
`"<check>: <n>/<threshold> failed samples"`); the gate carries `verification_status` and
`verification_detail`. A breach reaches the submitter's browser through the existing
`verification_detail`. Since #1027 the request detail and list bodies — not the gate — also
carry `verification_snapshot`: the config the window was opened with, omitted until a window
opens (and when the stored snapshot cannot be read), e.g. `{ "window": "PT15M",
"sample_interval": "PT30S", "failure_threshold": 3, "check_count": 2 }`. It deliberately carries
**no** check names, URLs or queries: the request is readable by its submitter and reviewers,
while an environment's config is admin-only. A breach reaches the submitter's browser through
the existing
`deployment.status_changed` WebSocket event.

**Sample entry** (`GET /deployment-requests/{id}/verification-samples`):
Expand Down
Loading
Loading