Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Add missing endpoints from authentication to v2
- Add missing endpoints from general-request-handling to v2
- Add benchmark tests for v1 and v2 to compare performance
- Add endpoint to fetch deployment id

## [2.1.5](https://github.com/arangodb/go-driver/tree/v2.1.5) (2025-08-31)
- Add tasks endpoints to v2
Expand Down
8 changes: 8 additions & 0 deletions v2/arangodb/client_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type ClientAdmin interface {
// ReloadJWTSecrets forces the server to reload the JWT secrets from disk.
// Requires a superuser JWT for authorization.
ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, error)

// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error)
}

type ClientAdminLog interface {
Expand Down Expand Up @@ -607,3 +610,8 @@ type JWTSecretsResult struct {
type JWTSecret struct {
SHA256 *string `json:"sha256,omitempty"` // SHA-256 hash of the JWT secret
}

type DeploymentIdResponse struct {
// Id represents the unique deployment identifier
Id *string `json:"id"`
}
22 changes: 22 additions & 0 deletions v2/arangodb/client_admin_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,25 @@ func (c *clientAdmin) ReloadJWTSecrets(ctx context.Context) (JWTSecretsResult, e
return JWTSecretsResult{}, response.AsArangoErrorWithCode(code)
}
}

// GetDeploymentId retrieves the unique deployment ID for the ArangoDB deployment.
func (c *clientAdmin) GetDeploymentId(ctx context.Context) (DeploymentIdResponse, error) {
url := connection.NewUrl("_admin", "deployment", "id")

var response struct {
shared.ResponseStruct `json:",inline"`
DeploymentIdResponse `json:",inline"`
}

resp, err := connection.CallGet(ctx, c.client.connection, url, &response)
if err != nil {
return DeploymentIdResponse{}, errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return response.DeploymentIdResponse, nil
default:
return DeploymentIdResponse{}, response.AsArangoErrorWithCode(code)
}
}
34 changes: 34 additions & 0 deletions v2/tests/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,37 @@ func Test_HandleAdminVersion(t *testing.T) {
})
})
}

// Test_GetDeploymentId verifies that the deployment ID can be retrieved successfully.
func Test_GetDeploymentId(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
t.Run("Success case", func(t *testing.T) {
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
version := skipBelowVersion(client, ctx, "3.12.6", t)
t.Logf("Current Version %s", version.Version)

resp, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp.Id)

// Verify ID format (assuming it's UUID-like)
require.Regexp(t, `^[a-zA-Z0-9\-]+$`, *resp.Id, "Deployment ID should be alphanumeric with hyphens")
})
})

t.Run("Multiple calls consistency", func(t *testing.T) {
withContextT(t, time.Minute, func(ctx context.Context, t testing.TB) {
resp1, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp1.Id)

resp2, err := client.GetDeploymentId(ctx)
require.NoError(t, err)
require.NotNil(t, resp2.Id)

// IDs should be consistent across calls
require.Equal(t, *resp1.Id, *resp2.Id, "Deployment ID should be consistent across calls")
})
})
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing Version Check in Deployment Test

The "Multiple calls consistency" subtest in Test_GetDeploymentId is missing the skipBelowVersion check for ArangoDB 3.12.6+. Since the GetDeploymentId endpoint requires this version, the subtest will fail on older ArangoDB versions while the "Success case" subtest correctly skips.

Fix in Cursor Fix in Web

}