(conf *viper.Viper, userOrGroupId string, queryFn func(context.Context, *dgo.Txn, string) (AclEntity, error))
| 188 | } |
| 189 | |
| 190 | func userOrGroupDel(conf *viper.Viper, userOrGroupId string, |
| 191 | queryFn func(context.Context, *dgo.Txn, string) (AclEntity, error)) error { |
| 192 | dc, cancel, err := getClientWithAdminCtx(conf) |
| 193 | if err != nil { |
| 194 | return fmt.Errorf("unable to get admin context: %w", err) |
| 195 | } |
| 196 | defer cancel() |
| 197 | |
| 198 | ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 199 | defer ctxCancel() |
| 200 | txn := dc.NewTxn() |
| 201 | defer func() { |
| 202 | if err := txn.Discard(ctx); err != nil { |
| 203 | glog.Errorf("Unable to discard transaction:%v", err) |
| 204 | } |
| 205 | }() |
| 206 | |
| 207 | entity, err := queryFn(ctx, txn, userOrGroupId) |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | if len(entity.GetUid()) == 0 { |
| 212 | return fmt.Errorf("unable to delete %q since it does not exist", |
| 213 | userOrGroupId) |
| 214 | } |
| 215 | |
| 216 | deleteNQuads := []*api.NQuad{ |
| 217 | { |
| 218 | Subject: entity.GetUid(), |
| 219 | Predicate: x.Star, |
| 220 | ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}, |
| 221 | }} |
| 222 | |
| 223 | mu := &api.Mutation{ |
| 224 | CommitNow: true, |
| 225 | Del: deleteNQuads, |
| 226 | } |
| 227 | |
| 228 | if _, err = txn.Mutate(ctx, mu); err != nil { |
| 229 | return fmt.Errorf("unable to delete %q: %w", userOrGroupId, err) |
| 230 | } |
| 231 | |
| 232 | fmt.Printf("Successfully deleted %q\n", userOrGroupId) |
| 233 | return nil |
| 234 | } |
| 235 | |
| 236 | func mod(conf *viper.Viper) error { |
| 237 | userId, _, err := getUserAndGroup(conf) |
no test coverage detected