From 2209833ad3f162606a7e7dd867339b7d7968093e Mon Sep 17 00:00:00 2001 From: NamanJain8 Date: Wed, 31 Mar 2021 18:49:19 +0530 Subject: [PATCH 1/2] make upgrade tool to work with non-acl cluster --- upgrade/change_v21.03.0.go | 10 ++++++---- upgrade/upgrade.go | 16 +--------------- upgrade/utils.go | 3 +++ 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/upgrade/change_v21.03.0.go b/upgrade/change_v21.03.0.go index e3e81341518..8f4ba52d568 100644 --- a/upgrade/change_v21.03.0.go +++ b/upgrade/change_v21.03.0.go @@ -152,7 +152,8 @@ func dropDeprecated(dg *dgo.Dgraph) error { } func upgradePersitentQuery() error { - dg, cb := x.GetDgraphClient(Upgrade.Conf, true) + login := len(Upgrade.Conf.GetString(user)) > 0 + dg, cb := x.GetDgraphClient(Upgrade.Conf, login) defer cb() jwt, err := getAccessJwt() @@ -205,7 +206,8 @@ func upgradePersitentQuery() error { } func upgradeCORS() error { - dg, cb := x.GetDgraphClient(Upgrade.Conf, true) + login := len(Upgrade.Conf.GetString(user)) > 0 + dg, cb := x.GetDgraphClient(Upgrade.Conf, login) defer cb() jwt, err := getAccessJwt() @@ -215,7 +217,7 @@ func upgradeCORS() error { // Get CORS. corsData := make(map[string][]cors) - if err = getQueryResult(dg, queryCORS_v21_03_0, &corsData); err != nil { + if err := getQueryResult(dg, queryCORS_v21_03_0, &corsData); err != nil { return errors.Wrap(err, "error querying cors") } @@ -239,7 +241,7 @@ func upgradeCORS() error { // Get GraphQL schema. schemaData := make(map[string][]sch) - if err = getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil { + if err := getQueryResult(dg, querySchema_v21_03_0, &schemaData); err != nil { return errors.Wrap(err, "error querying graphql schema") } diff --git a/upgrade/upgrade.go b/upgrade/upgrade.go index f20a1b9b3e6..fa53bdfad53 100644 --- a/upgrade/upgrade.go +++ b/upgrade/upgrade.go @@ -41,7 +41,6 @@ var ( type versionComparisonResult uint8 const ( - acl = "acl" dryRun = "dry-run" alpha = "alpha" slashGrpc = "slash_grpc_endpoint" @@ -151,9 +150,9 @@ func init() { }, Annotations: map[string]string{"group": "tool"}, } + Upgrade.EnvPrefix = "DGRAPH_UPGRADE" Upgrade.Cmd.SetHelpTemplate(x.NonRootTemplate) flag := Upgrade.Cmd.Flags() - flag.Bool(acl, false, "upgrade ACL from v1.2.2 to >=v20.03.0") flag.Bool(dryRun, false, "dry-run the upgrade") flag.StringP(alpha, "a", "127.0.0.1:9080", "Comma separated list of Dgraph Alpha gRPC server address") @@ -188,24 +187,11 @@ func run() { } func validateAndParseInput() (*commandInput, error) { - if !Upgrade.Conf.GetBool(acl) { - return nil, formatAsFlagParsingError(acl, - fmt.Errorf("we only support acl upgrade as of now")) - } - _, _, err := net.SplitHostPort(strings.TrimSpace(Upgrade.Conf.GetString(alpha))) if err != nil { return nil, formatAsFlagParsingError(alpha, err) } - if strings.TrimSpace(Upgrade.Conf.GetString(user)) == "" { - return nil, formatAsFlagRequiredError(user) - } - - if strings.TrimSpace(Upgrade.Conf.GetString(password)) == "" { - return nil, formatAsFlagRequiredError(password) - } - fromVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(from)) if err != nil { return nil, formatAsFlagParsingError(from, err) diff --git a/upgrade/utils.go b/upgrade/utils.go index d576fa68ad5..8a511e19158 100644 --- a/upgrade/utils.go +++ b/upgrade/utils.go @@ -35,6 +35,9 @@ import ( // getAccessJwt gets the access jwt token from by logging into the cluster. func getAccessJwt() (*api.Jwt, error) { + if len(Upgrade.Conf.GetString(user)) == 0 { + return &api.Jwt{}, nil + } user := Upgrade.Conf.GetString(user) password := Upgrade.Conf.GetString(password) header := http.Header{} From 93ff8cab3f227cb278e2a70236acbeef88b91049 Mon Sep 17 00:00:00 2001 From: NamanJain8 Date: Thu, 1 Apr 2021 11:50:14 +0530 Subject: [PATCH 2/2] address comments --- upgrade/change_v21.03.0.go | 6 ++---- upgrade/utils.go | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/upgrade/change_v21.03.0.go b/upgrade/change_v21.03.0.go index 8f4ba52d568..87ebba284bf 100644 --- a/upgrade/change_v21.03.0.go +++ b/upgrade/change_v21.03.0.go @@ -152,8 +152,7 @@ func dropDeprecated(dg *dgo.Dgraph) error { } func upgradePersitentQuery() error { - login := len(Upgrade.Conf.GetString(user)) > 0 - dg, cb := x.GetDgraphClient(Upgrade.Conf, login) + dg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds()) defer cb() jwt, err := getAccessJwt() @@ -206,8 +205,7 @@ func upgradePersitentQuery() error { } func upgradeCORS() error { - login := len(Upgrade.Conf.GetString(user)) > 0 - dg, cb := x.GetDgraphClient(Upgrade.Conf, login) + dg, cb := x.GetDgraphClient(Upgrade.Conf, hasAclCreds()) defer cb() jwt, err := getAccessJwt() diff --git a/upgrade/utils.go b/upgrade/utils.go index 8a511e19158..5c2fa43ab32 100644 --- a/upgrade/utils.go +++ b/upgrade/utils.go @@ -33,9 +33,13 @@ import ( "github.com/pkg/errors" ) +func hasAclCreds() bool { + return len(Upgrade.Conf.GetString(user)) > 0 +} + // getAccessJwt gets the access jwt token from by logging into the cluster. func getAccessJwt() (*api.Jwt, error) { - if len(Upgrade.Conf.GetString(user)) == 0 { + if !hasAclCreds() { return &api.Jwt{}, nil } user := Upgrade.Conf.GetString(user)