github.com/polarismesh/polaris@v1.17.8/common/api/v1/auth_response.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 v1 19 20 import ( 21 "github.com/golang/protobuf/ptypes/wrappers" 22 apimodel "github.com/polarismesh/specification/source/go/api/v1/model" 23 apisecurity "github.com/polarismesh/specification/source/go/api/v1/security" 24 apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" 25 ) 26 27 // NewAuthResponse 创建回复消息 28 func NewAuthResponse(code apimodel.Code) *apiservice.Response { 29 return &apiservice.Response{ 30 Code: &wrappers.UInt32Value{Value: uint32(code)}, 31 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 32 } 33 } 34 35 // NewAuthResponseWithMsg 创建回复消息 36 func NewAuthResponseWithMsg(code apimodel.Code, msg string) *apiservice.Response { 37 return &apiservice.Response{ 38 Code: &wrappers.UInt32Value{Value: uint32(code)}, 39 Info: &wrappers.StringValue{Value: code2info[uint32(code)] + ":" + msg}, 40 } 41 } 42 43 // NewAuthBatchWriteResponse 创建批量回复 44 func NewAuthBatchWriteResponse(code apimodel.Code) *apiservice.BatchWriteResponse { 45 return &apiservice.BatchWriteResponse{ 46 Code: &wrappers.UInt32Value{Value: uint32(code)}, 47 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 48 Size: &wrappers.UInt32Value{Value: 0}, 49 } 50 } 51 52 // NewAuthBatchQueryResponse 创建批量查询回复 53 func NewAuthBatchQueryResponse(code apimodel.Code) *apiservice.BatchQueryResponse { 54 return &apiservice.BatchQueryResponse{ 55 Code: &wrappers.UInt32Value{Value: uint32(code)}, 56 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 57 Amount: &wrappers.UInt32Value{Value: 0}, 58 Size: &wrappers.UInt32Value{Value: 0}, 59 } 60 } 61 62 // NewAuthBatchQueryResponseWithMsg 创建带详细信息的批量查询回复 63 func NewAuthBatchQueryResponseWithMsg(code apimodel.Code, msg string) *apiservice.BatchQueryResponse { 64 resp := NewAuthBatchQueryResponse(code) 65 resp.Info.Value += ": " + msg 66 return resp 67 } 68 69 // NewUserResponse 创建回复带用户信息 70 func NewUserResponse(code apimodel.Code, user *apisecurity.User) *apiservice.Response { 71 return &apiservice.Response{ 72 Code: &wrappers.UInt32Value{Value: uint32(code)}, 73 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 74 User: user, 75 } 76 } 77 78 // NewUserResponse 创建回复带用户信息 79 func NewUserResponseWithMsg(code apimodel.Code, info string, user *apisecurity.User) *apiservice.Response { 80 return &apiservice.Response{ 81 Code: &wrappers.UInt32Value{Value: uint32(code)}, 82 Info: &wrappers.StringValue{Value: info}, 83 User: user, 84 } 85 } 86 87 // NewGroupResponse 创建回复带用户组信息 88 func NewGroupResponse(code apimodel.Code, user *apisecurity.UserGroup) *apiservice.Response { 89 return &apiservice.Response{ 90 Code: &wrappers.UInt32Value{Value: uint32(code)}, 91 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 92 UserGroup: user, 93 } 94 } 95 96 // NewModifyGroupResponse 创建修改用户组的响应信息 97 func NewModifyGroupResponse(code apimodel.Code, group *apisecurity.ModifyUserGroup) *apiservice.Response { 98 return &apiservice.Response{ 99 Code: &wrappers.UInt32Value{Value: uint32(code)}, 100 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 101 ModifyUserGroup: group, 102 } 103 } 104 105 // NewGroupRelationResponse 创建用户组关联关系的响应体 106 func NewGroupRelationResponse(code apimodel.Code, relation *apisecurity.UserGroupRelation) *apiservice.Response { 107 return &apiservice.Response{ 108 Code: &wrappers.UInt32Value{Value: uint32(code)}, 109 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 110 Relation: relation, 111 } 112 } 113 114 // NewAuthStrategyResponse 创建鉴权策略响应体 115 func NewAuthStrategyResponse(code apimodel.Code, req *apisecurity.AuthStrategy) *apiservice.Response { 116 return &apiservice.Response{ 117 Code: &wrappers.UInt32Value{Value: uint32(code)}, 118 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 119 AuthStrategy: req, 120 } 121 } 122 123 // NewAuthStrategyResponseWithMsg 创建鉴权策略响应体并自定义Info 124 func NewAuthStrategyResponseWithMsg( 125 code apimodel.Code, msg string, req *apisecurity.AuthStrategy) *apiservice.Response { 126 return &apiservice.Response{ 127 Code: &wrappers.UInt32Value{Value: uint32(code)}, 128 Info: &wrappers.StringValue{Value: msg}, 129 AuthStrategy: req, 130 } 131 } 132 133 // NewModifyAuthStrategyResponse 创建修改鉴权策略响应体 134 func NewModifyAuthStrategyResponse(code apimodel.Code, req *apisecurity.ModifyAuthStrategy) *apiservice.Response { 135 return &apiservice.Response{ 136 Code: &wrappers.UInt32Value{Value: uint32(code)}, 137 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 138 ModifyAuthStrategy: req, 139 } 140 } 141 142 // NewStrategyResourcesResponse 创建修改鉴权策略响应体 143 func NewStrategyResourcesResponse(code apimodel.Code, ret *apisecurity.StrategyResources) *apiservice.Response { 144 return &apiservice.Response{ 145 Code: &wrappers.UInt32Value{Value: uint32(code)}, 146 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 147 Resources: ret, 148 } 149 } 150 151 // NewLoginResponse 创建登录响应体 152 func NewLoginResponse(code apimodel.Code, loginResponse *apisecurity.LoginResponse) *apiservice.Response { 153 return &apiservice.Response{ 154 Code: &wrappers.UInt32Value{Value: uint32(code)}, 155 Info: &wrappers.StringValue{Value: code2info[uint32(code)]}, 156 LoginResponse: loginResponse, 157 } 158 }