@@ -8,12 +8,12 @@ package acl
88import (
99 "context"
1010 "encoding/json"
11+ "errors"
1112 "fmt"
1213 "strings"
1314 "time"
1415
1516 "github.com/golang/glog"
16- "github.com/pkg/errors"
1717 "github.com/spf13/viper"
1818
1919 "github.com/dgraph-io/dgo/v240"
@@ -26,7 +26,7 @@ func getUserAndGroup(conf *viper.Viper) (userId string, groupId string, err erro
2626 groupId = conf .GetString ("group" )
2727 if (len (userId ) == 0 && len (groupId ) == 0 ) ||
2828 (len (userId ) != 0 && len (groupId ) != 0 ) {
29- return "" , "" , errors .Errorf ("one of the --user or --group must be specified, but not both" )
29+ return "" , "" , errors .New ("one of the --user or --group must be specified, but not both" )
3030 }
3131 return userId , groupId , nil
3232}
@@ -47,10 +47,10 @@ func checkForbiddenOpts(conf *viper.Viper, forbiddenOpts []string) error {
4747 case bool :
4848 isSet = conf .GetBool (opt )
4949 default :
50- return errors .Errorf ("unexpected option type for %s" , opt )
50+ return fmt .Errorf ("unexpected option type for %s" , opt )
5151 }
5252 if isSet {
53- return errors .Errorf ("the option --%s should not be set" , opt )
53+ return fmt .Errorf ("the option --%s should not be set" , opt )
5454 }
5555 }
5656
@@ -77,7 +77,7 @@ func add(conf *viper.Viper) error {
7777func userAdd (conf * viper.Viper , userid string , password string ) error {
7878 dc , cancel , err := getClientWithAdminCtx (conf )
7979 if err != nil {
80- return errors . Wrapf ( err , "unable to get admin context" )
80+ return fmt . Errorf ( "unable to get admin context: %w" , err )
8181 }
8282 defer cancel ()
8383
@@ -100,10 +100,10 @@ func userAdd(conf *viper.Viper, userid string, password string) error {
100100
101101 user , err := queryUser (ctx , txn , userid )
102102 if err != nil {
103- return errors . Wrapf ( err , "while querying user" )
103+ return fmt . Errorf ( "while querying user: %w" , err )
104104 }
105105 if user != nil {
106- return errors .Errorf ("unable to create user because of conflict: %v" , userid )
106+ return fmt .Errorf ("unable to create user because of conflict: %v" , userid )
107107 }
108108
109109 createUserNQuads := CreateUserNQuads (userid , password )
@@ -114,7 +114,7 @@ func userAdd(conf *viper.Viper, userid string, password string) error {
114114 }
115115
116116 if _ , err := txn .Mutate (ctx , mu ); err != nil {
117- return errors . Wrapf ( err , "unable to create user" )
117+ return fmt . Errorf ( "unable to create user: %w" , err )
118118 }
119119
120120 fmt .Printf ("Created new user with id %v\n " , userid )
@@ -124,7 +124,7 @@ func userAdd(conf *viper.Viper, userid string, password string) error {
124124func groupAdd (conf * viper.Viper , groupId string ) error {
125125 dc , cancel , err := getClientWithAdminCtx (conf )
126126 if err != nil {
127- return errors . Wrapf ( err , "unable to get admin context" )
127+ return fmt . Errorf ( "unable to get admin context: %w" , err )
128128 }
129129 defer cancel ()
130130
@@ -139,10 +139,10 @@ func groupAdd(conf *viper.Viper, groupId string) error {
139139
140140 group , err := queryGroup (ctx , txn , groupId )
141141 if err != nil {
142- return errors . Wrapf ( err , "while querying group" )
142+ return fmt . Errorf ( "while querying group: %w" , err )
143143 }
144144 if group != nil {
145- return errors .Errorf ("group %q already exists" , groupId )
145+ return fmt .Errorf ("group %q already exists" , groupId )
146146 }
147147
148148 createGroupNQuads := CreateGroupNQuads (groupId )
@@ -152,7 +152,7 @@ func groupAdd(conf *viper.Viper, groupId string) error {
152152 Set : createGroupNQuads ,
153153 }
154154 if _ , err = txn .Mutate (ctx , mu ); err != nil {
155- return errors . Wrapf ( err , "unable to create group" )
155+ return fmt . Errorf ( "unable to create group: %w" , err )
156156 }
157157
158158 fmt .Printf ("Created new group with id %v\n " , groupId )
@@ -191,7 +191,7 @@ func userOrGroupDel(conf *viper.Viper, userOrGroupId string,
191191 queryFn func (context.Context , * dgo.Txn , string ) (AclEntity , error )) error {
192192 dc , cancel , err := getClientWithAdminCtx (conf )
193193 if err != nil {
194- return errors . Wrapf ( err , "unable to get admin context" )
194+ return fmt . Errorf ( "unable to get admin context: %w" , err )
195195 }
196196 defer cancel ()
197197
@@ -209,7 +209,7 @@ func userOrGroupDel(conf *viper.Viper, userOrGroupId string,
209209 return err
210210 }
211211 if len (entity .GetUid ()) == 0 {
212- return errors .Errorf ("unable to delete %q since it does not exist" ,
212+ return fmt .Errorf ("unable to delete %q since it does not exist" ,
213213 userOrGroupId )
214214 }
215215
@@ -226,7 +226,7 @@ func userOrGroupDel(conf *viper.Viper, userOrGroupId string,
226226 }
227227
228228 if _ , err = txn .Mutate (ctx , mu ); err != nil {
229- return errors . Wrapf ( err , "unable to delete %q" , userOrGroupId )
229+ return fmt . Errorf ( "unable to delete %q: %w " , userOrGroupId , err )
230230 }
231231
232232 fmt .Printf ("Successfully deleted %q\n " , userOrGroupId )
@@ -249,8 +249,7 @@ func mod(conf *viper.Viper) error {
249249 groupList := conf .GetString ("group_list" )
250250 if (newPassword && groupList != defaultGroupList ) ||
251251 (! newPassword && groupList == defaultGroupList ) {
252- return errors .Errorf (
253- "one of --new_password or --group_list must be provided, but not both" )
252+ return errors .New ("one of --new_password or --group_list must be provided, but not both" )
254253 }
255254
256255 if newPassword {
@@ -272,7 +271,7 @@ func changePassword(conf *viper.Viper, userId string) error {
272271 // 1. get the dgo client with appropriate access JWT
273272 dc , cancel , err := getClientWithAdminCtx (conf )
274273 if err != nil {
275- return errors . Wrapf ( err , "unable to get dgo client" )
274+ return fmt . Errorf ( "unable to get dgo client: %w" , err )
276275 }
277276 defer cancel ()
278277
@@ -294,10 +293,10 @@ func changePassword(conf *viper.Viper, userId string) error {
294293 // 3. query the user's current uid
295294 user , err := queryUser (ctx , txn , userId )
296295 if err != nil {
297- return errors . Wrapf ( err , "while querying user" )
296+ return fmt . Errorf ( "while querying user: %w" , err )
298297 }
299298 if user == nil {
300- return errors .Errorf ("user %q does not exist" , userId )
299+ return fmt .Errorf ("user %q does not exist" , userId )
301300 }
302301
303302 // 4. mutate the user's password
@@ -312,7 +311,7 @@ func changePassword(conf *viper.Viper, userId string) error {
312311 Set : chPdNQuads ,
313312 }
314313 if _ , err := txn .Mutate (ctx , mu ); err != nil {
315- return errors . Wrapf ( err , "unable to change password for user %v" , userId )
314+ return fmt . Errorf ( "unable to change password for user %v: %w " , userId , err )
316315 }
317316 fmt .Printf ("Successfully changed password for %v\n " , userId )
318317 return nil
@@ -321,7 +320,7 @@ func changePassword(conf *viper.Viper, userId string) error {
321320func userMod (conf * viper.Viper , userId string , groups string ) error {
322321 dc , cancel , err := getClientWithAdminCtx (conf )
323322 if err != nil {
324- return errors . Wrapf ( err , "unable to get admin context" )
323+ return fmt . Errorf ( "unable to get admin context: %w" , err )
325324 }
326325 defer cancel ()
327326
@@ -336,10 +335,10 @@ func userMod(conf *viper.Viper, userId string, groups string) error {
336335
337336 user , err := queryUser (ctx , txn , userId )
338337 if err != nil {
339- return errors . Wrapf ( err , "while querying user" )
338+ return fmt . Errorf ( "while querying user: %w" , err )
340339 }
341340 if user == nil {
342- return errors .Errorf ("user %q does not exist" , userId )
341+ return fmt .Errorf ("user %q does not exist" , userId )
343342 }
344343
345344 targetGroupsMap := make (map [string ]struct {})
@@ -384,7 +383,7 @@ func userMod(conf *viper.Viper, userId string, groups string) error {
384383 }
385384
386385 if _ , err := txn .Mutate (ctx , mu ); err != nil {
387- return errors . Wrapf ( err , "while mutating the group" )
386+ return fmt . Errorf ( "while mutating the group: %w" , err )
388387 }
389388 fmt .Printf ("Successfully modified groups for user %v.\n " , userId )
390389 fmt .Println ("The latest info is:" )
@@ -407,17 +406,17 @@ func chMod(conf *viper.Viper) error {
407406 perm := conf .GetInt ("perm" )
408407 switch {
409408 case len (groupName ) == 0 :
410- return errors .Errorf ("the group must not be empty" )
409+ return errors .New ("the group must not be empty" )
411410 case len (predicate ) == 0 :
412- return errors .Errorf ("no predicates specified" )
411+ return errors .New ("no predicates specified" )
413412 case perm > 7 :
414- return errors .Errorf ("the perm value must be less than or equal to 7, " +
413+ return fmt .Errorf ("the perm value must be less than or equal to 7, " +
415414 "the provided value is %d" , perm )
416415 }
417416
418417 dc , cancel , err := getClientWithAdminCtx (conf )
419418 if err != nil {
420- return errors . Wrapf ( err , "unable to get admin context" )
419+ return fmt . Errorf ( "unable to get admin context: %w" , err )
421420 }
422421 defer cancel ()
423422
@@ -502,10 +501,10 @@ func chMod(conf *viper.Viper) error {
502501
503502 uidCount , ok := jsonResp ["groupUIDCount" ][0 ]["count" ]
504503 if ! ok {
505- return errors .New ("Malformed output of groupUIDCount" )
504+ return errors .New ("malformed output of groupUIDCount" )
506505 } else if uidCount == 0 {
507506 // We already have a check for multiple groups with same name at dgraph/acl/utils.go:142
508- return errors .Errorf ("Group <%s> doesn't exist" , groupName )
507+ return fmt .Errorf ("group <%s> doesn't exist" , groupName )
509508 }
510509 return nil
511510}
@@ -528,7 +527,7 @@ func queryUser(ctx context.Context, txn *dgo.Txn, userid string) (user *User, er
528527
529528 queryResp , err := txn .QueryWithVars (ctx , query , queryVars )
530529 if err != nil {
531- return nil , errors . Wrapf ( err , "hile query user with id %s" , userid )
530+ return nil , fmt . Errorf ( "while query user with id %s: %w " , userid , err )
532531 }
533532 user , err = UnmarshalUser (queryResp , "user" )
534533 if err != nil {
@@ -544,7 +543,7 @@ func getUserModNQuad(ctx context.Context, txn *dgo.Txn, userId string,
544543 return nil , err
545544 }
546545 if group == nil {
547- return nil , errors .Errorf ("group %q does not exist" , groupId )
546+ return nil , fmt .Errorf ("group %q does not exist" , groupId )
548547 }
549548
550549 createUserGroupNQuads := & api.NQuad {
@@ -590,7 +589,7 @@ func queryAndPrintUser(ctx context.Context, txn *dgo.Txn, userId string) error {
590589 return err
591590 }
592591 if user == nil {
593- return errors .Errorf ("The user %q does not exist. \n " , userId )
592+ return fmt .Errorf ("the user %q does not exist" , userId )
594593 }
595594
596595 fmt .Printf ("User : %s\n " , userId )
@@ -608,7 +607,7 @@ func queryAndPrintGroup(ctx context.Context, txn *dgo.Txn, groupId string) error
608607 return err
609608 }
610609 if group == nil {
611- return errors .Errorf ("The group %s doesn't exist" , groupId )
610+ return fmt .Errorf ("the group %s doesn't exist" , groupId )
612611 }
613612
614613 fmt .Printf ("Group: %s\n " , groupId )
@@ -636,7 +635,7 @@ func info(conf *viper.Viper) error {
636635
637636 dc , cancel , err := getClientWithAdminCtx (conf )
638637 if err != nil {
639- return errors . Wrapf ( err , "unable to get admin context" )
638+ return fmt . Errorf ( "unable to get admin context: %w" , err )
640639 }
641640 defer cancel ()
642641
0 commit comments