Skip to content

Commit 0be93a0

Browse files
committed
Warnings are predefined with a specific code and referenced when adding them to the response.
1 parent ed81e90 commit 0be93a0

File tree

5 files changed

+261
-212
lines changed

5 files changed

+261
-212
lines changed

internal/gen/controller/api/warning.pb.go

Lines changed: 155 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/proto/controller/api/v1/warning.proto

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ message BehaviorWarning {
3232
string warning = 1;
3333
}
3434

35-
// Warning is returned by the JSON API when a warning occurs.
35+
// A warning in the Boundary system.
3636
message Warning {
37-
// Request-field-specific warning details.
38-
repeated FieldWarning request_fields = 1 [json_name = "request_fields"];
39-
40-
// Action specific warning details.
41-
repeated ActionWarning actions = 2;
37+
uint32 code = 1;
38+
oneof warning {
39+
FieldWarning request_field = 2 [json_name = "request_fields"];
40+
ActionWarning action = 3;
41+
BehaviorWarning behavior = 4;
42+
}
43+
}
4244

43-
// Boundary behavior warning details.
44-
repeated BehaviorWarning behaviors = 3;
45+
// Warning is returned by the JSON API when a warning occurs.
46+
message WarningResponse {
47+
// Request-field-specific warning details.
48+
repeated Warning warnings = 1;
4549
}

internal/warning/enumerated.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package warning
5+
6+
import pb "github.com/hashicorp/boundary/internal/gen/controller/api"
7+
8+
type apiWarning uint32
9+
10+
// The set of warnings that boundary ever returns as a result of API requests.
11+
// Besides zzzKeepThisLastSentinel, the warnings should keep the numbers they
12+
// are initially released with because the enumerated number is used to uniquely
13+
// identify them and potentially provide additional information in documentation.
14+
const (
15+
Unknown apiWarning = 0
16+
FieldDeprecatedTargetWorkerFilters apiWarning = 1
17+
OidcAuthMethodInactiveCannotBeUsed apiWarning = 2
18+
DeletingKmsLedWorkersMayNotBePermanent apiWarning = 3
19+
20+
// This is a sentinel value that captures the largest apiWarning id currently
21+
// known. Add all warnings above this line.
22+
zzzKeepThisLastSentinel
23+
)
24+
25+
func (a apiWarning) toProto() *pb.Warning {
26+
nw := &pb.Warning{
27+
Code: uint32(a),
28+
}
29+
switch a {
30+
case FieldDeprecatedTargetWorkerFilters:
31+
nw.Warning = &pb.Warning_RequestField{RequestField: &pb.FieldWarning{
32+
Name: "worker_filter",
33+
Warning: "This field is deprecated. Please use ingress_worker_filter and/or egress_worker_filter",
34+
}}
35+
case OidcAuthMethodInactiveCannotBeUsed:
36+
nw.Warning = &pb.Warning_Behavior{Behavior: &pb.BehaviorWarning{
37+
Warning: "OIDC Auth Methods cannot be authenticated until they have been made active.",
38+
}}
39+
case DeletingKmsLedWorkersMayNotBePermanent:
40+
nw.Warning = &pb.Warning_Behavior{Behavior: &pb.BehaviorWarning{
41+
Warning: "A KMS worker may be automatically recreated after deletion if it is still running.",
42+
}}
43+
default:
44+
// don't add any unknown warning to the warner
45+
return nil
46+
}
47+
return nw
48+
}

0 commit comments

Comments
 (0)