@@ -30,6 +30,21 @@ type UserResponse struct {
3030 Token string `json:"token,omitempty"`
3131}
3232
33+ type ProxyUserResponse struct {
34+ Name string `json:"name"`
35+ GID int `json:"gid"`
36+ UID int `json:"uid"`
37+ Token string `json:"token,omitempty"`
38+ UserId int `json:"user_id,omitempty"`
39+ Path string `json:"path,omitempty"`
40+ }
41+
42+ type ProxyUserCheckResponse struct {
43+ Code string `json:"code"`
44+ Message int `json:"message"`
45+ Result bool `json:"result"`
46+ }
47+
3348const CcAuthToken = "MLSS-Token"
3449
3550// FIXME MLSS Change: get models filter by username and namespace
@@ -137,6 +152,50 @@ func (cc *CcClient) UserNamespaceCheck(token string, userName string, namespace
137152 return nil
138153}
139154
155+ func (cc * CcClient ) GetProxyUserFromCC (token string , proxyUserId string , userId string ) (* ProxyUserResponse , error ) {
156+ apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/proxyUser/%v/user/%v" , proxyUserId , userId )
157+ body , err := cc .accessCheckFromCc (token , apiUrl )
158+ if err != nil {
159+ return nil , err
160+ }
161+ var u = new (ProxyUserResponse )
162+ //json.Unmarshal(body, &u)
163+ err = models .GetResultData (body , & u )
164+ if err != nil {
165+ return nil , errors .New ("GetResultData failed" + err .Error ())
166+ }
167+ log .Debugf ("response=%+v, GID=%v, UID=%v" , u , u .GID , u .UID )
168+ if (u .GID == 0 || u .UID == 0 ) {
169+ return nil , errors .New ("error GUIDCheck is on and GID or UID is 0" )
170+ }
171+ //gid := strconv.Itoa(u.GID)
172+ //uid := strconv.Itoa(u.UID)
173+
174+ return u , nil
175+ }
176+
177+ func (cc * CcClient ) GetGUIDFromProxyUserId (token string , proxyUserId string ) (* string , * string , error ) {
178+ apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/proxyUser/%v" , proxyUserId )
179+ body , err := cc .accessCheckFromCc (token , apiUrl )
180+ if err != nil {
181+ return nil , nil , err
182+ }
183+ var u = new (UserResponse )
184+ //json.Unmarshal(body, &u)
185+ err = models .GetResultData (body , & u )
186+ if err != nil {
187+ return nil , nil , errors .New ("GetResultData failed" )
188+ }
189+ log .Debugf ("response=%+v, GID=%v, UID=%v" , u , u .GID , u .UID )
190+ if u .GUIDCheck && (u .GID == 0 || u .UID == 0 ) {
191+ return nil , nil , errors .New ("error GUIDCheck is on and GID or UID is 0" )
192+ }
193+ gid := strconv .Itoa (u .GID )
194+ uid := strconv .Itoa (u .UID )
195+
196+ return & gid , & uid , nil
197+ }
198+
140199func (cc * CcClient ) GetGUIDFromUserId (token string , userId string ) (* string , * string , error ) {
141200 apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/users/name/%v" , userId )
142201 body , err := cc .accessCheckFromCc (token , apiUrl )
@@ -159,6 +218,7 @@ func (cc *CcClient) GetGUIDFromUserId(token string, userId string) (*string, *st
159218 return & gid , & uid , nil
160219}
161220
221+
162222func (cc * CcClient ) GetUserByName (token string , userId string ) (* UserResponse , error ) {
163223 apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/users/name/%v" , userId )
164224 body , err := cc .accessCheckFromCc (token , apiUrl )
@@ -176,6 +236,24 @@ func (cc *CcClient) GetUserByName(token string, userId string) (*UserResponse, e
176236 return u , nil
177237}
178238
239+ func (cc * CcClient ) ProxyUserCheck (token string , userId string , proxyUser string ) (bool , error ) {
240+ apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/proxyUserCheck/%v/%v" , proxyUser , userId )
241+ body , err := cc .accessCheckFromCc (token , apiUrl )
242+ if err != nil {
243+ return false , err
244+ }
245+ var auth bool
246+ //json.Unmarshal(body, &u)
247+ err = models .GetResultData (body , & auth )
248+
249+ if err != nil {
250+ log .Error ("Unmarshal Error" , err )
251+ return false , errors .New ("Check Proxy User failed" )
252+ }
253+
254+ return auth , nil
255+ }
256+
179257func (cc * CcClient ) AdminUserCheck (token string , adminUserId string , userId string ) error {
180258 apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/auth/access/users/%v/users/%v" , adminUserId , userId )
181259 _ , err := cc .accessCheckFromCc (token , apiUrl )
@@ -303,8 +381,8 @@ func (cc *CcClient) CheckNamespaceUser(token string, namespace string, user stri
303381 return nil
304382}
305383
306- func (cc * CcClient ) GetCurrentUserNamespaceWithRole (token string , roleId string , clusterName string ) ([]byte , error ) {
307- apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/groups/users/roles/%v/namespaces/clusterName/%v " , roleId , clusterName )
384+ func (cc * CcClient ) GetCurrentUserNamespaceWithRole (token string , roleId string ) ([]byte , error ) {
385+ apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/groups/users/roles/%v/namespaces" , roleId )
308386 log .Debugf ("get apiUrl: %v" , apiUrl )
309387 req , err := http .NewRequest ("GET" , apiUrl , strings .NewReader ("" ))
310388 if err != nil {
@@ -330,3 +408,49 @@ func (cc *CcClient) GetCurrentUserNamespaceWithRole(token string, roleId string,
330408 defer resp .Body .Close ()
331409 return body , nil
332410}
411+
412+
413+ type GetGroupFromUserRequest struct {
414+
415+ }
416+
417+ type GetGroupFromUserResponse struct {
418+ ID int64 `gorm:"column:id; PRIMARY_KEY" json:"id"`
419+ Name string `json:"name"`
420+ EnableFlag int8 `json:"enable_flag"`
421+ UserId int64 `json:"user_id"`
422+ RoleId int64 `json:"role_id"`
423+ GroupId int64 `json:"group_id"`
424+ Remarks string `json:"remarks"`
425+ }
426+
427+
428+
429+ func (cc * CcClient ) GetGroupFromUser (username string ) (* GetGroupFromUserResponse ,error ){
430+ apiUrl := cc .ccUrl + fmt .Sprintf ("/cc/v1/group/username/%v" , username )
431+
432+ req ,err := http .NewRequest ("GET" ,apiUrl ,nil )
433+ if err != nil {
434+ return nil ,err
435+ }
436+
437+ res ,err := cc .httpClient .Do (req )
438+ if err != nil {
439+ return nil , err
440+ }
441+
442+ resByte , err := ioutil .ReadAll (res .Body )
443+ if err != nil {
444+ return nil , err
445+ }
446+
447+ group := GetGroupFromUserResponse {}
448+ err = json .Unmarshal (resByte ,& group )
449+ if err != nil {
450+ return nil , err
451+ }
452+
453+ return & group ,nil
454+
455+
456+ }
0 commit comments