Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Compose policy relationship before returning to the client
天舟52285862f9f0
diff --git a/api/policy.go b/api/policy.goindex 7834da9365..d704562584 100644--- a/api/policy.go+++ b/api/policy.go@@ -43,7 +43,7 @@ var ()type Policy struct {- ID int `jsonapi:"primary,environment"`+ ID int `jsonapi:"primary,policy"`// Standard fieldsRowStatus RowStatus `jsonapi:"attr,rowStatus"`@@ -55,10 +55,8 @@ type Policy struct {UpdatedTs int64 `jsonapi:"attr,updatedTs"`// Related fields- EnvironmentId int `jsonapi:"attr,environmentId"`- // Do not return this to the client since the client always has the database context and fetching the- // database object and all its own related objects is a bit expensive.- Environment *Environment+ EnvironmentId int+ Environment *Environment `jsonapi:"relation,environment"`// Domain specific fieldsType PolicyType `jsonapi:"attr,type"`diff --git a/server/policy.go b/server/policy.goindex 570a333eee..33fcd6303e 100644--- a/server/policy.go+++ b/server/policy.go@@ -35,6 +35,10 @@ func (s *Server) registerPolicyRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to set policy for type %q", pType)).SetInternal(err)}+ if err := s.ComposePolicyRelationship(context.Background(), policy); err != nil {+ return err+ }+c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, policy); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create set policy response").SetInternal(err)@@ -60,6 +64,10 @@ func (s *Server) registerPolicyRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to get policy for type %q", pType)).SetInternal(err)}+ if err := s.ComposePolicyRelationship(context.Background(), policy); err != nil {+ return err+ }+c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, policy); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal get policy response: %v", pType)).SetInternal(err)@@ -67,3 +75,24 @@ func (s *Server) registerPolicyRoutes(g *echo.Group) {return nil})}++func (s *Server) ComposePolicyRelationship(ctx context.Context, policy *api.Policy) error {+ var err error++ policy.Creator, err = s.ComposePrincipalById(context.Background(), policy.CreatorId)+ if err != nil {+ return err+ }++ policy.Updater, err = s.ComposePrincipalById(context.Background(), policy.UpdaterId)+ if err != nil {+ return err+ }++ policy.Environment, err = s.ComposeEnvironmentById(context.Background(), policy.EnvironmentId)+ if err != nil {+ return err+ }++ return nil+}