Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding auth token support #2692

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"

"github.com/dgraph-io/badger"
bopt "github.com/dgraph-io/badger/options"
Expand All @@ -61,6 +62,7 @@ type options struct {
numRdf int
clientDir string
ignoreIndexConflict bool
authToken string
}

var opt options
Expand Down Expand Up @@ -93,6 +95,8 @@ func init() {
flag.StringP("xidmap", "x", "", "Directory to store xid to uid mapping")
flag.BoolP("ignore_index_conflict", "i", true,
"Ignores conflicts on index keys during transaction")
flag.StringP("auth_token", "a", "",
"The auth token passed to the server for Alter operation of the schema file")

// TLS configuration
x.RegisterTLSFlags(flag)
Expand Down Expand Up @@ -122,6 +126,12 @@ func readLine(r *bufio.Reader, buf *bytes.Buffer) error {
// processSchemaFile process schema for a given gz file.
func processSchemaFile(ctx context.Context, file string, dgraphClient *dgo.Dgraph) error {
fmt.Printf("\nProcessing %s\n", file)
if len(opt.authToken) > 0 {
md := metadata.New(nil)
md.Append("auth-token", opt.authToken)
ctx = metadata.NewOutgoingContext(ctx, md)
}

f, err := os.Open(file)
x.Check(err)
defer f.Close()
Expand Down Expand Up @@ -316,6 +326,7 @@ func run() error {
numRdf: Live.Conf.GetInt("batch"),
clientDir: Live.Conf.GetString("xidmap"),
ignoreIndexConflict: Live.Conf.GetBool("ignore_index_conflict"),
authToken: Live.Conf.GetString("auth_token"),
}
x.LoadTLSConfig(&tlsConf, Live.Conf)
tlsConf.ServerName = Live.Conf.GetString("tls_server_name")
Expand Down