Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse committed Jun 6, 2024
1 parent 8f79ff8 commit 38eafa2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
28 changes: 15 additions & 13 deletions check_upgrade/check_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ func contains(slice []string, value string) bool {
return false
}

func remove(slice []int, index int) []int {
if index < 0 || index >= len(slice) {
return slice // Return the original slice if the index is out of bounds
}
return append(slice[:index], slice[index+1:]...)
}

func findDuplicateNodes(aclNodes []aclNode) [3]map[string][]string {
du := make(map[string][]string)
dg := make(map[string][]string)
Expand Down Expand Up @@ -226,7 +219,7 @@ func queryDuplicateNodes(hc *dgraphapi.HTTPClient) ([3]map[string][]string, erro
return findDuplicateNodes(result.Data.Nodes), nil
}

func printDuplicates(hc *dgraphapi.HTTPClient, entityType string, ns uint64, nodesmap map[string][]string,
func printAndDeleteDuplicates(hc *dgraphapi.HTTPClient, entityType string, ns uint64, nodesmap map[string][]string,
dupDelete bool) error {
if len(nodesmap) == 0 {
return nil
Expand Down Expand Up @@ -502,7 +495,8 @@ func init() {
flag.String(namespace, "", "Namespace to check for duplicate nodes")
flag.String(dgUser, "groot", "Username of the namespace's user")
flag.String(password, "password", "Password of the namespace's user")
flag.String(aclSecretKeyFilePath, "", "path of file that stores secret key or private key, which is used to sign the ACL JWT")
flag.String(aclSecretKeyFilePath, "", "path of file that stores secret key or private key,"+
" which is used to sign the ACL JWT")
flag.String(jwtAlg, "HS256", "JWT signing algorithm")
flag.String(deleteDup, "false", "set this flag to true to delete duplicates nodes")
}
Expand Down Expand Up @@ -551,21 +545,29 @@ func checkUpgrade() error {
return errors.Wrapf(err, "while getting access jwt token for namespace %v", ns)
}
} else {
hc.LoginIntoNamespace(cmdInput.dgUser, cmdInput.password, ns)
if err := hc.LoginIntoNamespace(cmdInput.dgUser, cmdInput.password, ns); err != nil {
return errors.Wrapf(err, "while logging into namespace %v", ns)
}
}

duplicates, err := queryDuplicateNodes(hc)
if err != nil {
return err
}
printDuplicates(hc, "user", ns, duplicates[0], cmdInput.dupDelete)
if err := printAndDeleteDuplicates(hc, "user", ns, duplicates[0], cmdInput.dupDelete); err != nil {
return err
}
// example output:
// Found duplicate users in namespace: #0
// dgraph.xid user1 , Uids: [0x4 0x3]
printDuplicates(hc, "group", ns, duplicates[1], cmdInput.dupDelete)
if err := printAndDeleteDuplicates(hc, "group", ns, duplicates[1], cmdInput.dupDelete); err != nil {
return err
}
// Found duplicate groups in namespace: #1
// dgraph.xid group1 , Uids: [0x2714 0x2711]
printDuplicates(hc, "groups and user", ns, duplicates[2], cmdInput.dupDelete)
if err := printAndDeleteDuplicates(hc, "groups and user", ns, duplicates[2], cmdInput.dupDelete); err != nil {
return err
}
// Found duplicate groups and users in namespace: #0
// dgraph.xid userGroup1 , Uids: [0x7532 0x7531]
}
Expand Down
10 changes: 0 additions & 10 deletions check_upgrade/check_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,3 @@ func TestQueryDuplicateNodes(t *testing.T) {
require.NoError(t, deleteDuplicatesGroup(hc, duplicateNodes[1]))
require.NoError(t, deleteDuplicatesGroup(hc, duplicateNodes[2]))
}

func TestDeleteDuplicateUser(t *testing.T) {
hc, err := setupClient("localhost:36085")

require.NoError(t, err)

require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

}

0 comments on commit 38eafa2

Please sign in to comment.