github.com/polarismesh/polaris@v1.17.8/config/config_file_release_authibility.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package config 19 20 import ( 21 "context" 22 23 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage" 24 25 api "github.com/polarismesh/polaris/common/api/v1" 26 "github.com/polarismesh/polaris/common/model" 27 "github.com/polarismesh/polaris/common/utils" 28 ) 29 30 // PublishConfigFile 发布配置文件 31 func (s *serverAuthability) PublishConfigFile(ctx context.Context, 32 configFileRelease *apiconfig.ConfigFileRelease) *apiconfig.ConfigResponse { 33 34 authCtx := s.collectConfigFileReleaseAuthContext(ctx, 35 []*apiconfig.ConfigFileRelease{configFileRelease}, model.Modify, "PublishConfigFile") 36 37 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 38 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 39 } 40 41 ctx = authCtx.GetRequestContext() 42 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 43 44 return s.targetServer.PublishConfigFile(ctx, configFileRelease) 45 } 46 47 // GetConfigFileRelease 获取配置文件发布内容 48 func (s *serverAuthability) GetConfigFileRelease(ctx context.Context, 49 req *apiconfig.ConfigFileRelease) *apiconfig.ConfigResponse { 50 51 authCtx := s.collectConfigFileReleaseAuthContext(ctx, 52 []*apiconfig.ConfigFileRelease{req}, model.Read, "GetConfigFileRelease") 53 54 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 55 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 56 } 57 ctx = authCtx.GetRequestContext() 58 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 59 return s.targetServer.GetConfigFileRelease(ctx, req) 60 } 61 62 // DeleteConfigFileReleases implements ConfigCenterServer. 63 func (s *serverAuthability) DeleteConfigFileReleases(ctx context.Context, 64 reqs []*apiconfig.ConfigFileRelease) *apiconfig.ConfigBatchWriteResponse { 65 66 authCtx := s.collectConfigFileReleaseAuthContext(ctx, reqs, model.Delete, "DeleteConfigFileReleases") 67 68 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 69 return api.NewConfigBatchWriteResponseWithInfo(convertToErrCode(err), err.Error()) 70 } 71 ctx = authCtx.GetRequestContext() 72 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 73 return s.targetServer.DeleteConfigFileReleases(ctx, reqs) 74 } 75 76 // GetConfigFileReleaseVersions implements ConfigCenterServer. 77 func (s *serverAuthability) GetConfigFileReleaseVersions(ctx context.Context, 78 filters map[string]string) *apiconfig.ConfigBatchQueryResponse { 79 80 authCtx := s.collectConfigFileReleaseAuthContext(ctx, nil, model.Read, "GetConfigFileReleaseVersions") 81 82 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 83 return api.NewConfigBatchQueryResponseWithInfo(convertToErrCode(err), err.Error()) 84 } 85 ctx = authCtx.GetRequestContext() 86 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 87 return s.targetServer.GetConfigFileReleaseVersions(ctx, filters) 88 } 89 90 // GetConfigFileReleases implements ConfigCenterServer. 91 func (s *serverAuthability) GetConfigFileReleases(ctx context.Context, 92 filters map[string]string) *apiconfig.ConfigBatchQueryResponse { 93 94 authCtx := s.collectConfigFileReleaseAuthContext(ctx, nil, model.Read, "GetConfigFileReleases") 95 96 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 97 return api.NewConfigBatchQueryResponseWithInfo(convertToErrCode(err), err.Error()) 98 } 99 ctx = authCtx.GetRequestContext() 100 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 101 return s.targetServer.GetConfigFileReleases(ctx, filters) 102 } 103 104 // RollbackConfigFileReleases implements ConfigCenterServer. 105 func (s *serverAuthability) RollbackConfigFileReleases(ctx context.Context, 106 reqs []*apiconfig.ConfigFileRelease) *apiconfig.ConfigBatchWriteResponse { 107 108 authCtx := s.collectConfigFileReleaseAuthContext(ctx, reqs, model.Modify, "RollbackConfigFileReleases") 109 110 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 111 return api.NewConfigBatchWriteResponseWithInfo(convertToErrCode(err), err.Error()) 112 } 113 ctx = authCtx.GetRequestContext() 114 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 115 return s.targetServer.RollbackConfigFileReleases(ctx, reqs) 116 } 117 118 // UpsertAndReleaseConfigFile . 119 func (s *serverAuthability) UpsertAndReleaseConfigFile(ctx context.Context, 120 req *apiconfig.ConfigFilePublishInfo) *apiconfig.ConfigResponse { 121 authCtx := s.collectConfigFilePublishAuthContext(ctx, []*apiconfig.ConfigFilePublishInfo{req}, 122 model.Modify, "UpsertAndReleaseConfigFile") 123 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 124 return api.NewConfigFileResponse(convertToErrCode(err), nil) 125 } 126 127 ctx = authCtx.GetRequestContext() 128 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 129 130 return s.targetServer.UpsertAndReleaseConfigFile(ctx, req) 131 }