Skip to content

Commit

Permalink
Merge pull request #89 from arangodb-managed/OAS-8698
Browse files Browse the repository at this point in the history
OAS-8698 | Add User-Agent
  • Loading branch information
Robert-Stam authored Nov 15, 2023
2 parents 314f264 + 29fb0b5 commit ccd0518
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/arangodb-managed/terraform-provider-oasis
go 1.20

require (
github.com/arangodb-managed/apis v0.83.1
github.com/arangodb-managed/apis v0.84.3
github.com/arangodb-managed/log-helper v0.2.5
github.com/gogo/protobuf v1.3.2
github.com/hashicorp/terraform-plugin-docs v0.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/arangodb-managed/apis v0.83.1 h1:Os+gxplikZDRFcpuO4Lk60qfrYHj8BInuOj955I3W2o=
github.com/arangodb-managed/apis v0.83.1/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY=
github.com/arangodb-managed/apis v0.84.3 h1:Mk2wFdbIvE0nNp/0sKZ4BV4qBQbIcVVfrIUuFCJyNcY=
github.com/arangodb-managed/apis v0.84.3/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY=
github.com/arangodb-managed/log-helper v0.2.5 h1:Kg3+0bDVFhEgyjMhIbCIj9hejgN2VaD4Cw/JQ4ARsd4=
github.com/arangodb-managed/log-helper v0.2.5/go.mod h1:G17ASSd3Edday3i1QREGefyLJ2TduHxxFsOaqoigurE=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
Expand Down
22 changes: 11 additions & 11 deletions internal/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,6 @@
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Joerg Schad
// Author Gergely Brautigam
// Author Robert Stam
//

package provider

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

"github.com/arangodb-managed/apis/common/auth"
commonGrpc "github.com/arangodb-managed/apis/common/v1/grpc"
iam "github.com/arangodb-managed/apis/iam/v1"
lh "github.com/arangodb-managed/log-helper"
)

// Client is responsible for connecting to the Oasis API
// Client is responsible for connecting to the Arango Graph API
type Client struct {
ApiKeyID string
ApiKeySecret string
Expand All @@ -50,7 +47,7 @@ type Client struct {
log zerolog.Logger
}

// Connect connects to oasis api
// Connect connects to Arango Graph API
func (c *Client) Connect() error {
ctx := context.Background()
c.log = lh.MustNew(lh.DefaultConfig())
Expand All @@ -66,18 +63,21 @@ func (c *Client) Connect() error {
c.log.Error().Err(err).Msg("Could not get Auth Token")
return err
}

c.ctxWithToken = auth.WithAccessToken(ctx, token)
// Add Access Token
ctxWithToken := auth.WithAccessToken(ctx, token)
// Add the User Agent as well
ua := commonGrpc.CreateUserAgent("terraform-provider-oasis", currentVersion)
c.ctxWithToken = commonGrpc.WithUserAgent(ctxWithToken, ua)
return nil
}

// mustDialAPI dials the ArangoDB Oasis API
// mustDialAPI dials the Arango Graph API
func (c *Client) mustDialAPI() (*grpc.ClientConn, error) {
// Set up a connection to the server.
tc := credentials.NewTLS(&tls.Config{})
conn, err := grpc.Dial(c.ApiEndpoint+c.ApiPortSuffix, grpc.WithTransportCredentials(tc))
if err != nil {
c.log.Error().Err(err).Msg("Failed to connect to ArangoDB Oasis API")
c.log.Error().Err(err).Msg("Failed to connect to Arango Graph API")
return nil, err
}
return conn, nil
Expand Down
12 changes: 11 additions & 1 deletion internal/provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -27,12 +27,22 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var (
// The version of the currently running plugin
currentVersion string
)

func init() {
// Set descriptions to support markdown syntax, this will be used in document generation
// and the language server.
schema.DescriptionKind = schema.StringMarkdown
}

// SetVersionAndBuild stores the given version & build
func SetVersionAndBuild(version, build string) {
currentVersion = version
}

// Provider defines an ArangoDB Oasis Terraform provider.
func Provider() *schema.Provider {
return &schema.Provider{
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"

"github.com/arangodb-managed/terraform-provider-oasis/internal"
provider "github.com/arangodb-managed/terraform-provider-oasis/internal"
)

var (
projectVersion = "dev"
projectBuild = "dev"
)

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

func main() {
provider.SetVersionAndBuild(projectVersion, projectBuild)
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() *schema.Provider {
return provider.Provider()
Expand Down

0 comments on commit ccd0518

Please sign in to comment.