From 864e603b4fa07b9b546ce1d9713072daaa5aef8a Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 11 Dec 2025 16:18:34 -0500 Subject: [PATCH 1/6] Update codeowners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8ef236d..71f2786 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # CODEOWNERS info: https://help.github.com/en/articles/about-code-owners # Owners are automatically requested for review for PRs that changes code # that they own. -* @hypermodeinc/database +* @hypermodeinc/maintainers From 7358c70ee0a05e7572585025a19dd2c13875d761 Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 11 Dec 2025 16:19:02 -0500 Subject: [PATCH 2/6] Update README with ns specific examples --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d746dc..2845569 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ fmt.Printf("%s\n", resp.Json) Dgraph v25 supports creating namespaces using grpc API. You can create one using the dgo client. ```go -_, err := client.CreateNamespace(context.TODO()) +nsID, err := client.CreateNamespace(context.TODO()) // Handle error ``` @@ -306,7 +306,7 @@ _, err := client.CreateNamespace(context.TODO()) To drop a namespace: ```go -err := client.DropNamespace(context.TODO()) +err := client.DropNamespace(context.TODO(), nsID) // Handle error ``` From 3a1c3f552c647b818ebe5c49fddf3e3dad4f0aca Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 18 Dec 2025 17:07:16 -0500 Subject: [PATCH 3/6] Update codeowners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 71f2786..a6f79c2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,4 +1,4 @@ # CODEOWNERS info: https://help.github.com/en/articles/about-code-owners # Owners are automatically requested for review for PRs that changes code # that they own. -* @hypermodeinc/maintainers +* @dgraph-io/maintainers From 16b95dccf27221e3d63b0cd4d4293a2f18e23aef Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 18 Dec 2025 17:07:48 -0500 Subject: [PATCH 4/6] Update namespace specific docs and comments --- README.md | 14 +++++++------- open.go | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2845569..cbd7156 100644 --- a/README.md +++ b/README.md @@ -71,18 +71,18 @@ Valid connection string args: | Arg | Value | Description | | ----------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| apikey | \ | a Dgraph Cloud API Key | | bearertoken | \ | an access token | | sslmode | disable \| require \| verify-ca | TLS option, the default is `disable`. If `verify-ca` is set, the TLS certificate configured in the Dgraph cluster must be from a valid certificate authority. | +| namespace | \ | a previously created integer-based namespace, username and password must be supplied | Some example connection strings: -| Value | Explanation | -| ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------- | -| dgraph://localhost:9080 | Connect to localhost, no ACL, no TLS | -| dgraph://sally:supersecret@dg.example.com:443?sslmode=verify-ca | Connect to remote server, use ACL and require TLS and a valid certificate from a CA | -| dgraph://foo-bar.grpc.us-west-2.aws.cloud.dgraph.io:443?sslmode=verify-ca&apikey=\ | Connect to a Dgraph Cloud cluster | -| dgraph://foo-bar.grpc.example.com?sslmode=verify-ca&bearertoken=\ | Connect to a Dgraph cluster protected by a secure gateway | +| Value | Explanation | +| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| dgraph://localhost:9080 | Connect to localhost, no ACL, no TLS | +| dgraph://sally:supersecret@dg.example.com:443?sslmode=verify-ca | Connect to remote server, use ACL and require TLS and a valid certificate from a CA | +| dgraph://foo-bar.grpc.example.com?sslmode=verify-ca&bearertoken=\ | Connect to a Dgraph cluster protected by a secure gateway | +| dgraph://sally:supersecret@dg.example.com:443?namespace=2 | Connect to a ACL enabled Dgraph cluster in namespace 2 | Using the `Open` function with a connection string: diff --git a/open.go b/open.go index 443d2ed..eb53781 100644 --- a/open.go +++ b/open.go @@ -135,8 +135,9 @@ func WithGrpcOption(opt grpc.DialOption) ClientOption { // For example `dgraph://localhost:9080?sslmode=require` // // Parameters: -// - apikey: a Dgraph Cloud API key for authentication -// - bearertoken: a token for bearer authentication +// - apikey: a Dgraph Cloud API key for authentication (deprecated) +// - bearertoken: a token for bearer authentication (deprecated) +// - namespace: a previously created integer-based namespace ID, login credentials must be provided // - sslmode: SSL connection mode (options: disable, require, verify-ca) // - disable: No TLS (default) // - require: Use TLS but skip certificate verification @@ -198,6 +199,9 @@ func Open(connStr string) (*Dgraph, error) { } if nsID != "" { + if u.User == nil { + return nil, errors.New("invalid connection string: both username and password must be provided for namespace") + } nsID, err := strconv.ParseUint(nsID, 10, 64) if err != nil { return nil, fmt.Errorf("invalid namespace ID: %w", err) From 26e5396b407e271fcf09e3e2d85680b727092d0a Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 18 Dec 2025 17:08:14 -0500 Subject: [PATCH 5/6] Add a test for namespace sans user creds --- client_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client_test.go b/client_test.go index 56118a8..a4a98a4 100644 --- a/client_test.go +++ b/client_test.go @@ -73,6 +73,9 @@ func TestOpen(t *testing.T) { _, err = dgo.Open("dgraph://user:pass@localhost:9180") require.ErrorContains(t, err, "invalid username or password") + _, err = dgo.Open("dgraph://localhost:9180?namespace=1") + require.ErrorContains(t, err, "invalid connection string: both username and password must be provided for namespace") + _, err = dgo.Open("dgraph://user:pass@localhost:9180?namespace=root") require.ErrorContains(t, err, "invalid namespace ID: strconv.ParseUint: parsing \"root\": invalid syntax") From a4f7cc59a970518aa470337719dddfb8fcbf598e Mon Sep 17 00:00:00 2001 From: Matthew McNeely Date: Thu, 18 Dec 2025 17:10:27 -0500 Subject: [PATCH 6/6] Update gRPC protobuf regenerate target to use Docker when compiling protos on non-Linux systems This preserves the requisite gRPC versions --- protos/Makefile | 12 ++++++++++++ protos/api/api.pb.go | 2 +- protos/api/api_grpc.pb.go | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/protos/Makefile b/protos/Makefile index f55ec27..8fe5790 100644 --- a/protos/Makefile +++ b/protos/Makefile @@ -8,13 +8,25 @@ clean: @rm -rf api && mkdir -p api @rm -rf api.v2 && mkdir -p api.v2 +UNAME_S := $(shell uname -s) + .PHONY: check check: echo "Installing proto libraries to versions in go.mod." ; \ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.0 ; \ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0 +ifneq ($(UNAME_S),Linux) +.PHONY: regenerate +regenerate: + @echo "Running in Docker..." + @docker run --rm -v $(shell pwd)/..:/go/src/github.com/dgraph-io/dgo \ + -w /go/src/github.com/dgraph-io/dgo/protos \ + golang:1.23.0 \ + /bin/bash -c "apt-get update && apt-get install -y protobuf-compiler && make regenerate" +else .PHONY: regenerate regenerate: check clean @protoc --go_out=api --go-grpc_out=api --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative api.proto @echo Done. +endif diff --git a/protos/api/api.pb.go b/protos/api/api.pb.go index 122222f..5f0a539 100644 --- a/protos/api/api.pb.go +++ b/protos/api/api.pb.go @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: © Hypermode Inc. +// SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc. // SPDX-License-Identifier: Apache-2.0 // Style guide for Protocol Buffer 3. diff --git a/protos/api/api_grpc.pb.go b/protos/api/api_grpc.pb.go index cdf9964..0f8d6a8 100644 --- a/protos/api/api_grpc.pb.go +++ b/protos/api/api_grpc.pb.go @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: © Hypermode Inc. +// SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc. // SPDX-License-Identifier: Apache-2.0 // Style guide for Protocol Buffer 3.