|
| 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