Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add environment tier to v1 API (#4152)

Danny Xuba34e228710e
diff --git a/frontend/src/types/proto/v1/environment_service.ts b/frontend/src/types/proto/v1/environment_service.ts
index f50047d862..3fd9394242 100644
--- a/frontend/src/types/proto/v1/environment_service.ts
+++ b/frontend/src/types/proto/v1/environment_service.ts
@@ -6,6 +6,45 @@ import { State, stateFromJSON, stateToJSON } from "./common";
export const protobufPackage = "bytebase.v1";
+export enum EnvironmentTier {
+ ENVIRONMENT_TIER_UNSPECIFIED = 0,
+ PROTECTED = 1,
+ UNPROTECTED = 2,
+ UNRECOGNIZED = -1,
+}
+
+export function environmentTierFromJSON(object: any): EnvironmentTier {
+ switch (object) {
+ case 0:
+ case "ENVIRONMENT_TIER_UNSPECIFIED":
+ return EnvironmentTier.ENVIRONMENT_TIER_UNSPECIFIED;
+ case 1:
+ case "PROTECTED":
+ return EnvironmentTier.PROTECTED;
+ case 2:
+ case "UNPROTECTED":
+ return EnvironmentTier.UNPROTECTED;
+ case -1:
+ case "UNRECOGNIZED":
+ default:
+ return EnvironmentTier.UNRECOGNIZED;
+ }
+}
+
+export function environmentTierToJSON(object: EnvironmentTier): string {
+ switch (object) {
+ case EnvironmentTier.ENVIRONMENT_TIER_UNSPECIFIED:
+ return "ENVIRONMENT_TIER_UNSPECIFIED";
+ case EnvironmentTier.PROTECTED:
+ return "PROTECTED";
+ case EnvironmentTier.UNPROTECTED:
+ return "UNPROTECTED";
+ case EnvironmentTier.UNRECOGNIZED:
+ default:
+ return "UNRECOGNIZED";
+ }
+}
+
export interface GetEnvironmentRequest {
/**
* The name of the environment to retrieve.
@@ -96,6 +135,7 @@ export interface Environment {
state: State;
title: string;
order: number;
+ tier: EnvironmentTier;
}
function createBaseGetEnvironmentRequest(): GetEnvironmentRequest {
@@ -493,7 +533,7 @@ export const UndeleteEnvironmentRequest = {
};
function createBaseEnvironment(): Environment {
- return { name: "", uid: "", state: 0, title: "", order: 0 };
+ return { name: "", uid: "", state: 0, title: "", order: 0, tier: 0 };
}
export const Environment = {
@@ -513,6 +553,9 @@ export const Environment = {
if (message.order !== 0) {
writer.uint32(40).int32(message.order);
}
+ if (message.tier !== 0) {
+ writer.uint32(48).int32(message.tier);
+ }
return writer;
},
@@ -538,6 +581,9 @@ export const Environment = {
case 5:
message.order = reader.int32();
break;
+ case 6:
+ message.tier = reader.int32() as any;
+ break;
default:
reader.skipType(tag & 7);
break;
@@ -553,6 +599,7 @@ export const Environment = {
state: isSet(object.state) ? stateFromJSON(object.state) : 0,
title: isSet(object.title) ? String(object.title) : "",
order: isSet(object.order) ? Number(object.order) : 0,
+ tier: isSet(object.tier) ? environmentTierFromJSON(object.tier) : 0,
};
},
@@ -563,6 +610,7 @@ export const Environment = {
message.state !== undefined && (obj.state = stateToJSON(message.state));
message.title !== undefined && (obj.title = message.title);
message.order !== undefined && (obj.order = Math.round(message.order));
+ message.tier !== undefined && (obj.tier = environmentTierToJSON(message.tier));
return obj;
},
@@ -573,6 +621,7 @@ export const Environment = {
message.state = object.state ?? 0;
message.title = object.title ?? "";
message.order = object.order ?? 0;
+ message.tier = object.tier ?? 0;
return message;
},
};
diff --git a/proto/generated-go/v1/environment_service.pb.go b/proto/generated-go/v1/environment_service.pb.go
index c61b1c2234..7a76715a48 100644
--- a/proto/generated-go/v1/environment_service.pb.go
+++ b/proto/generated-go/v1/environment_service.pb.go
@@ -23,6 +23,55 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
+type EnvironmentTier int32
+
+const (
+ EnvironmentTier_ENVIRONMENT_TIER_UNSPECIFIED EnvironmentTier = 0
+ EnvironmentTier_PROTECTED EnvironmentTier = 1
+ EnvironmentTier_UNPROTECTED EnvironmentTier = 2
+)
+
+// Enum value maps for EnvironmentTier.
+var (
+ EnvironmentTier_name = map[int32]string{
+ 0: "ENVIRONMENT_TIER_UNSPECIFIED",
+ 1: "PROTECTED",
+ 2: "UNPROTECTED",
+ }
+ EnvironmentTier_value = map[string]int32{
+ "ENVIRONMENT_TIER_UNSPECIFIED": 0,
+ "PROTECTED": 1,
+ "UNPROTECTED": 2,
+ }
+)
+
+func (x EnvironmentTier) Enum() *EnvironmentTier {
+ p := new(EnvironmentTier)
+ *p = x
+ return p
+}
+
+func (x EnvironmentTier) String() string {
+ return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
+}
+
+func (EnvironmentTier) Descriptor() protoreflect.EnumDescriptor {
+ return file_v1_environment_service_proto_enumTypes[0].Descriptor()
+}
+
+func (EnvironmentTier) Type() protoreflect.EnumType {
+ return &file_v1_environment_service_proto_enumTypes[0]
+}
+
+func (x EnvironmentTier) Number() protoreflect.EnumNumber {
+ return protoreflect.EnumNumber(x)
+}
+
+// Deprecated: Use EnvironmentTier.Descriptor instead.
+func (EnvironmentTier) EnumDescriptor() ([]byte, []int) {
+ return file_v1_environment_service_proto_rawDescGZIP(), []int{0}
+}
+
type GetEnvironmentRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -431,10 +480,11 @@ type Environment struct {
// Format: environments/{environment}
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The system-assigned, unique identifier for a resource.
- Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
- State State `protobuf:"varint,3,opt,name=state,proto3,enum=bytebase.v1.State" json:"state,omitempty"`
- Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"`
- Order int32 `protobuf:"varint,5,opt,name=order,proto3" json:"order,omitempty"`
+ Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
+ State State `protobuf:"varint,3,opt,name=state,proto3,enum=bytebase.v1.State" json:"state,omitempty"`
+ Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"`
+ Order int32 `protobuf:"varint,5,opt,name=order,proto3" json:"order,omitempty"`
+ Tier EnvironmentTier `protobuf:"varint,6,opt,name=tier,proto3,enum=bytebase.v1.EnvironmentTier" json:"tier,omitempty"`
}
func (x *Environment) Reset() {
@@ -504,6 +554,13 @@ func (x *Environment) GetOrder() int32 {
return 0
}
+func (x *Environment) GetTier() EnvironmentTier {
+ if x != nil {
+ return x.Tier
+ }
+ return EnvironmentTier_ENVIRONMENT_TIER_UNSPECIFIED
+}
+
var File_v1_environment_service_proto protoreflect.FileDescriptor
var file_v1_environment_service_proto_rawDesc = []byte{
@@ -564,7 +621,7 @@ var file_v1_environment_service_proto_rawDesc = []byte{
0x6e, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x04, 0x6e,
- 0x61, 0x6d, 0x65, 0x22, 0x8f, 0x01, 0x0a, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
+ 0x61, 0x6d, 0x65, 0x22, 0xc1, 0x01, 0x0a, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x03, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12,
@@ -573,61 +630,69 @@ var file_v1_environment_service_proto_rawDesc = []byte{
0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74,
0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05,
- 0x6f, 0x72, 0x64, 0x65, 0x72, 0x32, 0xc1, 0x06, 0x0a, 0x12, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f,
- 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, 0x0e,
- 0x47, 0x65, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x22,
- 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74,
- 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
- 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31,
- 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x28, 0xda, 0x41,
- 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x12, 0x19, 0x2f, 0x76, 0x31,
+ 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x04, 0x74, 0x69, 0x65, 0x72, 0x18, 0x06, 0x20,
+ 0x01, 0x28, 0x0e, 0x32, 0x1c, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76,
+ 0x31, 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x65,
+ 0x72, 0x52, 0x04, 0x74, 0x69, 0x65, 0x72, 0x2a, 0x53, 0x0a, 0x0f, 0x45, 0x6e, 0x76, 0x69, 0x72,
+ 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x1c, 0x45, 0x4e,
+ 0x56, 0x49, 0x52, 0x4f, 0x4e, 0x4d, 0x45, 0x4e, 0x54, 0x5f, 0x54, 0x49, 0x45, 0x52, 0x5f, 0x55,
+ 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09,
+ 0x50, 0x52, 0x4f, 0x54, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x55,
+ 0x4e, 0x50, 0x52, 0x4f, 0x54, 0x45, 0x43, 0x54, 0x45, 0x44, 0x10, 0x02, 0x32, 0xc1, 0x06, 0x0a,
+ 0x12, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76,
+ 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f,
+ 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x22, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
+ 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
+ 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65,
+ 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
+ 0x65, 0x6e, 0x74, 0x22, 0x28, 0xda, 0x41, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x82, 0xd3, 0xe4, 0x93,
+ 0x02, 0x1b, 0x12, 0x19, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x65, 0x6e,
+ 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x12, 0x7c, 0x0a,
+ 0x10, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74,
+ 0x73, 0x12, 0x24, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e,
+ 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73,
+ 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
+ 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f,
+ 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b,
+ 0xda, 0x41, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x65,
+ 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x7e, 0x0a, 0x11, 0x43,
+ 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74,
+ 0x12, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43,
+ 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74,
+ 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
+ 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+ 0x74, 0x22, 0x28, 0xda, 0x41, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, 0x0b, 0x65, 0x6e,
+ 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x65,
+ 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0xaa, 0x01, 0x0a, 0x11,
+ 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+ 0x74, 0x12, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e,
+ 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+ 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62,
+ 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
+ 0x6e, 0x74, 0x22, 0x54, 0xda, 0x41, 0x17, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
+ 0x6e, 0x74, 0x2c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x82, 0xd3,
+ 0xe4, 0x93, 0x02, 0x34, 0x3a, 0x0b, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+ 0x74, 0x32, 0x25, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
+ 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e,
+ 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x12, 0x7c, 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65,
+ 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e,
+ 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65,
+ 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71,
+ 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
+ 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x28, 0xda, 0x41,
+ 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x2a, 0x19, 0x2f, 0x76, 0x31,
0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
- 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x12, 0x7c, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e,
- 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x24, 0x2e, 0x62, 0x79, 0x74,
- 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x45, 0x6e, 0x76,
- 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
- 0x1a, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4c,
- 0x69, 0x73, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x52,
- 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0xda, 0x41, 0x00, 0x82, 0xd3, 0xe4, 0x93,
- 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
- 0x65, 0x6e, 0x74, 0x73, 0x12, 0x7e, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e,
- 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65,
- 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x6e,
- 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
- 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45,
- 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x28, 0xda, 0x41, 0x00, 0x82,
- 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x3a, 0x0b, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65,
- 0x6e, 0x74, 0x22, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
- 0x65, 0x6e, 0x74, 0x73, 0x12, 0xaa, 0x01, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45,
- 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x62, 0x79, 0x74,
- 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x45,
- 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
- 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e,
- 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x54, 0xda, 0x41, 0x17,
- 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x2c, 0x75, 0x70, 0x64, 0x61,
- 0x74, 0x65, 0x5f, 0x6d, 0x61, 0x73, 0x6b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x34, 0x3a, 0x0b, 0x65,
- 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x32, 0x25, 0x2f, 0x76, 0x31, 0x2f,
- 0x7b, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x6e, 0x61, 0x6d,
- 0x65, 0x3d, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a,
- 0x7d, 0x12, 0x7c, 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72,
- 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,
- 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72,
- 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
- 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
- 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x28, 0xda, 0x41, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x82, 0xd3,
- 0xe4, 0x93, 0x02, 0x1b, 0x2a, 0x19, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x3d,
- 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x12,
- 0x87, 0x01, 0x0a, 0x13, 0x55, 0x6e, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69,
- 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x27, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
- 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x6e, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e,
- 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
- 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45,
- 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93,
- 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x76, 0x31, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65,
- 0x3d, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d,
- 0x3a, 0x75, 0x6e, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x65, 0x6e,
- 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72,
- 0x6f, 0x74, 0x6f, 0x33,
+ 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x12, 0x87, 0x01, 0x0a, 0x13, 0x55, 0x6e, 0x64, 0x65, 0x6c,
+ 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x27,
+ 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x6e, 0x64,
+ 0x65, 0x6c, 0x65, 0x74, 0x65, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74,
+ 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61,
+ 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+ 0x74, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27, 0x3a, 0x01, 0x2a, 0x22, 0x22, 0x2f, 0x76,
+ 0x31, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x3d, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d,
+ 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x2a, 0x7d, 0x3a, 0x75, 0x6e, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65,
+ 0x42, 0x11, 0x5a, 0x0f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f,
+ 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -642,43 +707,46 @@ func file_v1_environment_service_proto_rawDescGZIP() []byte {
return file_v1_environment_service_proto_rawDescData
}
+var file_v1_environment_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_v1_environment_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
var file_v1_environment_service_proto_goTypes = []interface{}{
- (*GetEnvironmentRequest)(nil), // 0: bytebase.v1.GetEnvironmentRequest
- (*ListEnvironmentsRequest)(nil), // 1: bytebase.v1.ListEnvironmentsRequest
- (*ListEnvironmentsResponse)(nil), // 2: bytebase.v1.ListEnvironmentsResponse
- (*CreateEnvironmentRequest)(nil), // 3: bytebase.v1.CreateEnvironmentRequest
- (*UpdateEnvironmentRequest)(nil), // 4: bytebase.v1.UpdateEnvironmentRequest
- (*DeleteEnvironmentRequest)(nil), // 5: bytebase.v1.DeleteEnvironmentRequest
- (*UndeleteEnvironmentRequest)(nil), // 6: bytebase.v1.UndeleteEnvironmentRequest
- (*Environment)(nil), // 7: bytebase.v1.Environment
- (*fieldmaskpb.FieldMask)(nil), // 8: google.protobuf.FieldMask
- (State)(0), // 9: bytebase.v1.State
- (*emptypb.Empty)(nil), // 10: google.protobuf.Empty
+ (EnvironmentTier)(0), // 0: bytebase.v1.EnvironmentTier
+ (*GetEnvironmentRequest)(nil), // 1: bytebase.v1.GetEnvironmentRequest
+ (*ListEnvironmentsRequest)(nil), // 2: bytebase.v1.ListEnvironmentsRequest
+ (*ListEnvironmentsResponse)(nil), // 3: bytebase.v1.ListEnvironmentsResponse
+ (*CreateEnvironmentRequest)(nil), // 4: bytebase.v1.CreateEnvironmentRequest
+ (*UpdateEnvironmentRequest)(nil), // 5: bytebase.v1.UpdateEnvironmentRequest
+ (*DeleteEnvironmentRequest)(nil), // 6: bytebase.v1.DeleteEnvironmentRequest
+ (*UndeleteEnvironmentRequest)(nil), // 7: bytebase.v1.UndeleteEnvironmentRequest
+ (*Environment)(nil), // 8: bytebase.v1.Environment
+ (*fieldmaskpb.FieldMask)(nil), // 9: google.protobuf.FieldMask
+ (State)(0), // 10: bytebase.v1.State
+ (*emptypb.Empty)(nil), // 11: google.protobuf.Empty
}
var file_v1_environment_service_proto_depIdxs = []int32{
- 7, // 0: bytebase.v1.ListEnvironmentsResponse.environments:type_name -> bytebase.v1.Environment
- 7, // 1: bytebase.v1.CreateEnvironmentRequest.environment:type_name -> bytebase.v1.Environment
- 7, // 2: bytebase.v1.UpdateEnvironmentRequest.environment:type_name -> bytebase.v1.Environment
- 8, // 3: bytebase.v1.UpdateEnvironmentRequest.update_mask:type_name -> google.protobuf.FieldMask
- 9, // 4: bytebase.v1.Environment.state:type_name -> bytebase.v1.State
- 0, // 5: bytebase.v1.EnvironmentService.GetEnvironment:input_type -> bytebase.v1.GetEnvironmentRequest
- 1, // 6: bytebase.v1.EnvironmentService.ListEnvironments:input_type -> bytebase.v1.ListEnvironmentsRequest
- 3, // 7: bytebase.v1.EnvironmentService.CreateEnvironment:input_type -> bytebase.v1.CreateEnvironmentRequest
- 4, // 8: bytebase.v1.EnvironmentService.UpdateEnvironment:input_type -> bytebase.v1.UpdateEnvironmentRequest
- 5, // 9: bytebase.v1.EnvironmentService.DeleteEnvironment:input_type -> bytebase.v1.DeleteEnvironmentRequest
- 6, // 10: bytebase.v1.EnvironmentService.UndeleteEnvironment:input_type -> bytebase.v1.UndeleteEnvironmentRequest
- 7, // 11: bytebase.v1.EnvironmentService.GetEnvironment:output_type -> bytebase.v1.Environment
- 2, // 12: bytebase.v1.EnvironmentService.ListEnvironments:output_type -> bytebase.v1.ListEnvironmentsResponse
- 7, // 13: bytebase.v1.EnvironmentService.CreateEnvironment:output_type -> bytebase.v1.Environment
- 7, // 14: bytebase.v1.EnvironmentService.UpdateEnvironment:output_type -> bytebase.v1.Environment
- 10, // 15: bytebase.v1.EnvironmentService.DeleteEnvironment:output_type -> google.protobuf.Empty
- 7, // 16: bytebase.v1.EnvironmentService.UndeleteEnvironment:output_type -> bytebase.v1.Environment
- 11, // [11:17] is the sub-list for method output_type
- 5, // [5:11] is the sub-list for method input_type
- 5, // [5:5] is the sub-list for extension type_name
- 5, // [5:5] is the sub-list for extension extendee
- 0, // [0:5] is the sub-list for field type_name
+ 8, // 0: bytebase.v1.ListEnvironmentsResponse.environments:type_name -> bytebase.v1.Environment
+ 8, // 1: bytebase.v1.CreateEnvironmentRequest.environment:type_name -> bytebase.v1.Environment
+ 8, // 2: bytebase.v1.UpdateEnvironmentRequest.environment:type_name -> bytebase.v1.Environment
+ 9, // 3: bytebase.v1.UpdateEnvironmentRequest.update_mask:type_name -> google.protobuf.FieldMask
+ 10, // 4: bytebase.v1.Environment.state:type_name -> bytebase.v1.State
+ 0, // 5: bytebase.v1.Environment.tier:type_name -> bytebase.v1.EnvironmentTier
+ 1, // 6: bytebase.v1.EnvironmentService.GetEnvironment:input_type -> bytebase.v1.GetEnvironmentRequest
+ 2, // 7: bytebase.v1.EnvironmentService.ListEnvironments:input_type -> bytebase.v1.ListEnvironmentsRequest
+ 4, // 8: bytebase.v1.EnvironmentService.CreateEnvironment:input_type -> bytebase.v1.CreateEnvironmentRequest
+ 5, // 9: bytebase.v1.EnvironmentService.UpdateEnvironment:input_type -> bytebase.v1.UpdateEnvironmentRequest
+ 6, // 10: bytebase.v1.EnvironmentService.DeleteEnvironment:input_type -> bytebase.v1.DeleteEnvironmentRequest
+ 7, // 11: bytebase.v1.EnvironmentService.UndeleteEnvironment:input_type -> bytebase.v1.UndeleteEnvironmentRequest
+ 8, // 12: bytebase.v1.EnvironmentService.GetEnvironment:output_type -> bytebase.v1.Environment
+ 3, // 13: bytebase.v1.EnvironmentService.ListEnvironments:output_type -> bytebase.v1.ListEnvironmentsResponse
+ 8, // 14: bytebase.v1.EnvironmentService.CreateEnvironment:output_type -> bytebase.v1.Environment
+ 8, // 15: bytebase.v1.EnvironmentService.UpdateEnvironment:output_type -> bytebase.v1.Environment
+ 11, // 16: bytebase.v1.EnvironmentService.DeleteEnvironment:output_type -> google.protobuf.Empty
+ 8, // 17: bytebase.v1.EnvironmentService.UndeleteEnvironment:output_type -> bytebase.v1.Environment
+ 12, // [12:18] is the sub-list for method output_type
+ 6, // [6:12] is the sub-list for method input_type
+ 6, // [6:6] is the sub-list for extension type_name
+ 6, // [6:6] is the sub-list for extension extendee
+ 0, // [0:6] is the sub-list for field type_name
}
func init() { file_v1_environment_service_proto_init() }
@@ -790,13 +858,14 @@ func file_v1_environment_service_proto_init() {
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_v1_environment_service_proto_rawDesc,
- NumEnums: 0,
+ NumEnums: 1,
NumMessages: 8,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_v1_environment_service_proto_goTypes,
DependencyIndexes: file_v1_environment_service_proto_depIdxs,
+ EnumInfos: file_v1_environment_service_proto_enumTypes,
MessageInfos: file_v1_environment_service_proto_msgTypes,
}.Build()
File_v1_environment_service_proto = out.File
diff --git a/proto/v1/environment_service.proto b/proto/v1/environment_service.proto
index c8f2e2652c..f15019485f 100644
--- a/proto/v1/environment_service.proto
+++ b/proto/v1/environment_service.proto
@@ -139,4 +139,12 @@ message Environment {
string title = 4;
int32 order = 5;
+
+ EnvironmentTier tier = 6;
+}
+
+enum EnvironmentTier {
+ ENVIRONMENT_TIER_UNSPECIFIED = 0;
+ PROTECTED = 1;
+ UNPROTECTED = 2;
}
\ No newline at end of file
diff --git a/server/api/v1/environment_service.go b/server/api/v1/environment_service.go
index 696af14362..68b5badcb3 100644
--- a/server/api/v1/environment_service.go
+++ b/server/api/v1/environment_service.go
@@ -129,6 +129,9 @@ func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, request *v1p
patch.Name = &request.Environment.Title
case "environment.order":
patch.Order = &request.Environment.Order
+ case "environment.tier":
+ protected := request.Environment.Tier == v1pb.EnvironmentTier_PROTECTED
+ patch.Protected = &protected
}
}
@@ -205,11 +208,16 @@ func (s *EnvironmentService) UndeleteEnvironment(ctx context.Context, request *v
}
func convertToEnvironment(environment *store.EnvironmentMessage) *v1pb.Environment {
+ tier := v1pb.EnvironmentTier_UNPROTECTED
+ if environment.Protected {
+ tier = v1pb.EnvironmentTier_PROTECTED
+ }
return &v1pb.Environment{
Name: fmt.Sprintf("%s%s", environmentNamePrefix, environment.ResourceID),
Uid: fmt.Sprintf("%d", environment.UID),
+ State: convertDeletedToState(environment.Deleted),
Title: environment.Title,
Order: environment.Order,
- State: convertDeletedToState(environment.Deleted),
+ Tier: tier,
}
}
diff --git a/store/environment.go b/store/environment.go
index 65c2189ecf..f49f47e913 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -536,6 +536,7 @@ type EnvironmentMessage struct {
ResourceID string
Title string
Order int32
+ Protected bool
Deleted bool
}
@@ -547,9 +548,10 @@ type FindEnvironmentMessage struct {
// UpdateEnvironmentMessage is the message for updating an environment.
type UpdateEnvironmentMessage struct {
- Name *string
- Order *int32
- Delete *bool
+ Name *string
+ Order *int32
+ Protected *bool
+ Delete *bool
}
// GetEnvironmentV2 gets environment by resource ID.
@@ -604,7 +606,8 @@ func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMess
}
defer tx.Rollback()
- if _, err := tx.ExecContext(ctx, `
+ var uid int
+ if err := tx.QueryRowContext(ctx, `
INSERT INTO environment (
resource_id,
name,
@@ -613,16 +616,36 @@ func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMess
updater_id,
)
VALUES ($1, $2, $3, $4, $5)
+ RETURNING id
`,
create.ResourceID,
create.Title,
create.Order,
creatorID,
creatorID,
+ ).Scan(
+ &uid,
); err != nil {
return nil, FormatError(err)
}
+ value := api.EnvironmentTierValueUnprotected
+ if create.Protected {
+ value = api.EnvironmentTierValueProtected
+ }
+ payload, err := (&api.EnvironmentTierPolicy{EnvironmentTier: value}).String()
+ if err != nil {
+ return nil, err
+ }
+ if _, err := upsertPolicyImpl(ctx, tx, &api.PolicyUpsert{
+ ResourceType: api.PolicyResourceTypeEnvironment,
+ ResourceID: uid,
+ Payload: &payload,
+ UpdaterID: creatorID,
+ }); err != nil {
+ return nil, err
+ }
+
if err := tx.Commit(); err != nil {
return nil, FormatError(err)
}
@@ -661,34 +684,51 @@ func (s *Store) UpdateEnvironmentV2(ctx context.Context, environmentID string, p
}
defer tx.Rollback()
- environment := &EnvironmentMessage{}
- var rowStatus string
+ var uid int
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
UPDATE environment
SET `+strings.Join(set, ", ")+`
WHERE resource_id = $%d
- RETURNING resource_id, name, "order", row_status
+ RETURNING id
`, len(args)),
args...,
).Scan(
- &environment.ResourceID,
- &environment.Title,
- &environment.Order,
- &rowStatus,
+ &uid,
); err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, FormatError(err)
}
- environment.Deleted = convertRowStatusToDeleted(rowStatus)
+
+ // TODO(d): consider moving tier to environment table to simplify things.
+ // TODO(d): move policy interface to store v2.
+ if patch.Protected != nil {
+ value := api.EnvironmentTierValueUnprotected
+ if *patch.Protected {
+ value = api.EnvironmentTierValueProtected
+ }
+ payload, err := (&api.EnvironmentTierPolicy{EnvironmentTier: value}).String()
+ if err != nil {
+ return nil, err
+ }
+ if _, err := upsertPolicyImpl(ctx, tx, &api.PolicyUpsert{
+ ResourceType: api.PolicyResourceTypeEnvironment,
+ ResourceID: uid,
+ Payload: &payload,
+ UpdaterID: updaterID,
+ }); err != nil {
+ return nil, err
+ }
+ }
if err := tx.Commit(); err != nil {
return nil, FormatError(err)
}
+ // Invalid the cache and read the value again.
+ delete(s.environmentCache, environmentID)
- s.environmentCache[environment.ResourceID] = environment
- return environment, nil
+ return s.GetEnvironmentV2(ctx, environmentID)
}
func (s *Store) getEnvironmentImplV2(ctx context.Context, tx *Tx, resourceID string) (*EnvironmentMessage, error) {
@@ -712,21 +752,23 @@ func (s *Store) getEnvironmentImplV2(ctx context.Context, tx *Tx, resourceID str
func listEnvironmentImplV2(ctx context.Context, tx *Tx, find *FindEnvironmentMessage) ([]*EnvironmentMessage, error) {
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ResourceID; v != nil {
- where, args = append(where, fmt.Sprintf("resource_id = $%d", len(args)+1)), append(args, *v)
+ where, args = append(where, fmt.Sprintf("environment.resource_id = $%d", len(args)+1)), append(args, *v)
}
if !find.ShowDeleted {
- where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, api.Normal)
+ where, args = append(where, fmt.Sprintf("environment.row_status = $%d", len(args)+1)), append(args, api.Normal)
}
var environments []*EnvironmentMessage
rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- resource_id,
- name,
- "order",
- row_status
+ environment.id,
+ environment.resource_id,
+ environment.name,
+ environment.order,
+ environment.row_status,
+ policy.payload
FROM environment
+ LEFT JOIN policy ON environment.id = policy.resource_id AND policy.resource_type = 'ENVIRONMENT' AND policy.type = 'bb.policy.environment-tier'
WHERE `+strings.Join(where, " AND "),
args...,
)
@@ -736,6 +778,7 @@ func listEnvironmentImplV2(ctx context.Context, tx *Tx, find *FindEnvironmentMes
defer rows.Close()
for rows.Next() {
var environment EnvironmentMessage
+ var tierPayload sql.NullString
var rowStatus string
if err := rows.Scan(
&environment.UID,
@@ -743,10 +786,18 @@ func listEnvironmentImplV2(ctx context.Context, tx *Tx, find *FindEnvironmentMes
&environment.Title,
&environment.Order,
&rowStatus,
+ &tierPayload,
); err != nil {
return nil, FormatError(err)
}
environment.Deleted = convertRowStatusToDeleted(rowStatus)
+ if tierPayload.Valid {
+ policy, err := api.UnmarshalEnvironmentTierPolicy(tierPayload.String)
+ if err != nil {
+ return nil, err
+ }
+ environment.Protected = policy.EnvironmentTier == api.EnvironmentTierValueProtected
+ }
environments = append(environments, &environment)
}