findGrootAndGuardians returns the UIDs of groot user and guardians group
(c *LocalCluster)
| 281 | |
| 282 | // findGrootAndGuardians returns the UIDs of groot user and guardians group |
| 283 | func findGrootAndGuardians(c *LocalCluster) (string, string, error) { |
| 284 | gc, cleanup, err := c.Client() |
| 285 | if err != nil { |
| 286 | return "", "", errors.Wrapf(err, "error creating grpc client") |
| 287 | } |
| 288 | defer cleanup() |
| 289 | |
| 290 | if c.conf.acl { |
| 291 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 292 | defer cancel() |
| 293 | err = gc.LoginIntoNamespace(ctx, dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace) |
| 294 | if err != nil { |
| 295 | return "", "", errors.Wrapf(err, "error logging in as groot") |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | query := `{ |
| 300 | q(func: eq(dgraph.xid, "groot")){ |
| 301 | uid |
| 302 | dgraph.user.group @filter(eq(dgraph.xid, "guardians")) { |
| 303 | uid |
| 304 | } |
| 305 | } |
| 306 | }` |
| 307 | resp, err := gc.Query(query) |
| 308 | if err != nil { |
| 309 | return "", "", errors.Wrapf(err, "error querying groot & guardians UIDs") |
| 310 | } |
| 311 | var result struct { |
| 312 | Q []struct { |
| 313 | Uid string |
| 314 | Groups []struct { |
| 315 | Uid string |
| 316 | } `json:"dgraph.user.group"` |
| 317 | } |
| 318 | } |
| 319 | if err := json.Unmarshal(resp.Json, &result); err != nil { |
| 320 | return "", "", errors.Wrapf(err, "error unmarshalling resp: [%v]", string(resp.Json)) |
| 321 | } |
| 322 | if len(result.Q) != 1 || result.Q[0].Uid == "" || |
| 323 | len(result.Q[0].Groups) != 1 || result.Q[0].Groups[0].Uid == "" { |
| 324 | return "", "", errors.Errorf("unable to find groot & guardians, resp: [%+v]", resp) |
| 325 | } |
| 326 | return result.Q[0].Uid, result.Q[0].Groups[0].Uid, nil |
| 327 | } |
| 328 | |
| 329 | // modifyACLEntries replaces groot's and guardians' UIDs |
| 330 | // in the exported files to the UIDs in this dgraph cluster. |
no test coverage detected