Skip to content

Commit ccd0518

Browse files
authored
Merge pull request #89 from arangodb-managed/OAS-8698
OAS-8698 | Add User-Agent
2 parents 314f264 + 29fb0b5 commit ccd0518

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/arangodb-managed/terraform-provider-oasis
33
go 1.20
44

55
require (
6-
github.com/arangodb-managed/apis v0.83.1
6+
github.com/arangodb-managed/apis v0.84.3
77
github.com/arangodb-managed/log-helper v0.2.5
88
github.com/gogo/protobuf v1.3.2
99
github.com/hashicorp/terraform-plugin-docs v0.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/
3030
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
3131
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
3232
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
33-
github.com/arangodb-managed/apis v0.83.1 h1:Os+gxplikZDRFcpuO4Lk60qfrYHj8BInuOj955I3W2o=
34-
github.com/arangodb-managed/apis v0.83.1/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY=
33+
github.com/arangodb-managed/apis v0.84.3 h1:Mk2wFdbIvE0nNp/0sKZ4BV4qBQbIcVVfrIUuFCJyNcY=
34+
github.com/arangodb-managed/apis v0.84.3/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY=
3535
github.com/arangodb-managed/log-helper v0.2.5 h1:Kg3+0bDVFhEgyjMhIbCIj9hejgN2VaD4Cw/JQ4ARsd4=
3636
github.com/arangodb-managed/log-helper v0.2.5/go.mod h1:G17ASSd3Edday3i1QREGefyLJ2TduHxxFsOaqoigurE=
3737
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

internal/client.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -17,10 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Joerg Schad
21-
// Author Gergely Brautigam
22-
// Author Robert Stam
23-
//
2420

2521
package provider
2622

@@ -33,11 +29,12 @@ import (
3329
"google.golang.org/grpc/credentials"
3430

3531
"github.com/arangodb-managed/apis/common/auth"
32+
commonGrpc "github.com/arangodb-managed/apis/common/v1/grpc"
3633
iam "github.com/arangodb-managed/apis/iam/v1"
3734
lh "github.com/arangodb-managed/log-helper"
3835
)
3936

40-
// Client is responsible for connecting to the Oasis API
37+
// Client is responsible for connecting to the Arango Graph API
4138
type Client struct {
4239
ApiKeyID string
4340
ApiKeySecret string
@@ -50,7 +47,7 @@ type Client struct {
5047
log zerolog.Logger
5148
}
5249

53-
// Connect connects to oasis api
50+
// Connect connects to Arango Graph API
5451
func (c *Client) Connect() error {
5552
ctx := context.Background()
5653
c.log = lh.MustNew(lh.DefaultConfig())
@@ -66,18 +63,21 @@ func (c *Client) Connect() error {
6663
c.log.Error().Err(err).Msg("Could not get Auth Token")
6764
return err
6865
}
69-
70-
c.ctxWithToken = auth.WithAccessToken(ctx, token)
66+
// Add Access Token
67+
ctxWithToken := auth.WithAccessToken(ctx, token)
68+
// Add the User Agent as well
69+
ua := commonGrpc.CreateUserAgent("terraform-provider-oasis", currentVersion)
70+
c.ctxWithToken = commonGrpc.WithUserAgent(ctxWithToken, ua)
7171
return nil
7272
}
7373

74-
// mustDialAPI dials the ArangoDB Oasis API
74+
// mustDialAPI dials the Arango Graph API
7575
func (c *Client) mustDialAPI() (*grpc.ClientConn, error) {
7676
// Set up a connection to the server.
7777
tc := credentials.NewTLS(&tls.Config{})
7878
conn, err := grpc.Dial(c.ApiEndpoint+c.ApiPortSuffix, grpc.WithTransportCredentials(tc))
7979
if err != nil {
80-
c.log.Error().Err(err).Msg("Failed to connect to ArangoDB Oasis API")
80+
c.log.Error().Err(err).Msg("Failed to connect to Arango Graph API")
8181
return nil, err
8282
}
8383
return conn, nil

internal/provider.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -27,12 +27,22 @@ import (
2727
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2828
)
2929

30+
var (
31+
// The version of the currently running plugin
32+
currentVersion string
33+
)
34+
3035
func init() {
3136
// Set descriptions to support markdown syntax, this will be used in document generation
3237
// and the language server.
3338
schema.DescriptionKind = schema.StringMarkdown
3439
}
3540

41+
// SetVersionAndBuild stores the given version & build
42+
func SetVersionAndBuild(version, build string) {
43+
currentVersion = version
44+
}
45+
3646
// Provider defines an ArangoDB Oasis Terraform provider.
3747
func Provider() *schema.Provider {
3848
return &schema.Provider{

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -25,7 +25,12 @@ import (
2525
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2626
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
2727

28-
"github.com/arangodb-managed/terraform-provider-oasis/internal"
28+
provider "github.com/arangodb-managed/terraform-provider-oasis/internal"
29+
)
30+
31+
var (
32+
projectVersion = "dev"
33+
projectBuild = "dev"
2934
)
3035

3136
// Examples folder formatting
@@ -35,6 +40,7 @@ import (
3540
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
3641

3742
func main() {
43+
provider.SetVersionAndBuild(projectVersion, projectBuild)
3844
plugin.Serve(&plugin.ServeOpts{
3945
ProviderFunc: func() *schema.Provider {
4046
return provider.Provider()

0 commit comments

Comments
 (0)