Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: use 'environments/*' parent to list all instances from all environments (#4059)
Danny Xuc9004f197b1f
diff --git a/frontend/src/types/proto/v1/instance_service.ts b/frontend/src/types/proto/v1/instance_service.tsindex dcc8cdd07b..66d8f86445 100644--- a/frontend/src/types/proto/v1/instance_service.ts+++ b/frontend/src/types/proto/v1/instance_service.ts@@ -126,6 +126,7 @@ export interface ListInstancesRequest {/*** The parent, which owns this collection of instances.* Format: environments/{environment}+ * Use "environments/*" to list all instances from all environments.*/parent: string;/**diff --git a/proto/generated-go/v1/instance_service.pb.go b/proto/generated-go/v1/instance_service.pb.goindex 0a8267d630..eed8fbc17b 100644--- a/proto/generated-go/v1/instance_service.pb.go+++ b/proto/generated-go/v1/instance_service.pb.go@@ -192,6 +192,7 @@ type ListInstancesRequest struct {// The parent, which owns this collection of instances.// Format: environments/{environment}+ // Use "environments/*" to list all instances from all environments.Parent string `protobuf:"bytes,1,opt,name=parent,proto3" json:"parent,omitempty"`// The maximum number of instances to return. The service may return fewer than// this value.diff --git a/proto/v1/instance_service.proto b/proto/v1/instance_service.protoindex 4ce42baed4..df2d706843 100644--- a/proto/v1/instance_service.proto+++ b/proto/v1/instance_service.proto@@ -67,6 +67,7 @@ message GetInstanceRequest {message ListInstancesRequest {// The parent, which owns this collection of instances.// Format: environments/{environment}+ // Use "environments/*" to list all instances from all environments.string parent = 1 [(google.api.field_behavior) = REQUIRED];// The maximum number of instances to return. The service may return fewer thandiff --git a/server/api/v1/instance_service.go b/server/api/v1/instance_service.goindex adbb84cbc5..8569b40c92 100644--- a/server/api/v1/instance_service.go+++ b/server/api/v1/instance_service.go@@ -56,7 +56,7 @@ func (s *InstanceService) ListInstances(ctx context.Context, request *v1pb.ListIreturn nil, status.Errorf(codes.InvalidArgument, err.Error())}- instances, err := s.store.ListInstanceV2(ctx, environmentID, request.ShowDeleted)+ instances, err := s.store.ListInstancesV2(ctx, environmentID, request.ShowDeleted)if err != nil {return nil, status.Errorf(codes.Internal, err.Error())}@@ -200,6 +200,7 @@ func convertToInstance(environmentID string, instance *store.InstanceMessage) *vTitle: ds.Title,Type: dataSourceType,Username: ds.Username,+ // We don't return the password on reads.SslCa: ds.SslCa,SslCert: ds.SslCert,SslKey: ds.SslKey,diff --git a/store/instance.go b/store/instance.goindex 541b36b2e8..09ffb6a180 100644--- a/store/instance.go+++ b/store/instance.go@@ -833,15 +833,19 @@ func (s *Store) GetInstanceV2(ctx context.Context, environmentID, resourceID strreturn &instanceMessage, nil}-// ListInstanceV2 lists all instance.-func (s *Store) ListInstanceV2(ctx context.Context, environmentID string, showDeleted bool) ([]*InstanceMessage, error) {+// ListInstancesV2 lists all instance.+// If environmentID is "*", we will list all instances from all environments.+func (s *Store) ListInstancesV2(ctx context.Context, environmentID string, showDeleted bool) ([]*InstanceMessage, error) {tx, err := s.db.BeginTx(ctx, nil)if err != nil {return nil, FormatError(err)}defer tx.Rollback()- where, args := []string{"1 = 1"}, []interface{}{environmentID}+ where, args := []string{"1 = 1"}, []interface{}{}+ if environmentID != "*" {+ where, args = append(where, fmt.Sprintf("environment.resource_id = $%d", len(args)+1)), append(args, environmentID)+ }if !showDeleted {where, args = append(where, fmt.Sprintf("instance.row_status = $%d", len(args)+1)), append(args, api.Normal)}@@ -858,7 +862,7 @@ func (s *Store) ListInstanceV2(ctx context.Context, environmentID string, showDeFROM instanceLEFT JOIN environmentON environment.id = instance.environment_id- WHERE environment.resource_id = $1 AND `+strings.Join(where, " AND "),+ WHERE `+strings.Join(where, " AND "),args...,)if err != nil {