1+ // Copyright Project Harbor Authors
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
115package api
216
317import (
18+ "encoding/json"
19+ "fmt"
20+
421 "github.com/goharbor/go-client/pkg/sdk/v2.0/client/usergroup"
522 "github.com/goharbor/go-client/pkg/sdk/v2.0/models"
623 "github.com/goharbor/harbor-cli/pkg/utils"
7- "fmt"
824 log "github.com/sirupsen/logrus"
9- "encoding/json"
1025)
1126
12-
1327func CreateUserGroup (groupName string , groupType int64 , ldapGroupDn string ) error {
14- ctx , client , err := utils .ContextWithClient ()
15- if err != nil {
16- return fmt .Errorf ("failed to create client: %v" , err )
17- }
18-
19- userGroup := & models.UserGroup {
20- GroupName : groupName ,
21- GroupType : groupType ,
22- }
23-
24- if groupType == 1 {
25- userGroup .LdapGroupDn = ldapGroupDn
26- }
27-
28- _ , err = client .Usergroup .CreateUserGroup (ctx , & usergroup.CreateUserGroupParams {
29- Usergroup : userGroup ,
30- })
31-
32- if err != nil {
28+ ctx , client , err := utils .ContextWithClient ()
29+ if err != nil {
30+ return fmt .Errorf ("failed to create client: %v" , err )
31+ }
32+
33+ userGroup := & models.UserGroup {
34+ GroupName : groupName ,
35+ GroupType : groupType ,
36+ }
37+
38+ if groupType == 1 {
39+ userGroup .LdapGroupDn = ldapGroupDn
40+ }
41+
42+ _ , err = client .Usergroup .CreateUserGroup (ctx , & usergroup.CreateUserGroupParams {
43+ Usergroup : userGroup ,
44+ })
45+ if err != nil {
3346 switch e := err .(type ) {
3447 case * usergroup.CreateUserGroupBadRequest :
3548 payload , _ := json .MarshalIndent (e .Payload , "" , " " )
@@ -40,10 +53,9 @@ func CreateUserGroup(groupName string, groupType int64, ldapGroupDn string) erro
4053 default :
4154 return fmt .Errorf ("failed to create user group: %v" , err )
4255 }
43- }
44-
45- return nil
56+ }
4657
58+ return nil
4759}
4860
4961func DeleteUserGroup (groupId int64 ) error {
@@ -115,9 +127,8 @@ func UpdateUserGroup(groupId int64, groupName string, groupType int64) error {
115127 GroupType : groupType ,
116128 },
117129 })
118-
119130 if err != nil {
120131 return err
121132 }
122133 return nil
123- }
134+ }
0 commit comments