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

Support for Default tags #16

Merged
merged 9 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions client/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ const (
HeaderClient = "x-infoblox-client"
HeaderSDK = "x-infoblox-sdk"
HeaderAuthorization = "Authorization"
version = "0.1"
sdkIdentifier = "golang-sdk"
)

const version = "0.1"
const sdkIdentifier = "golang-sdk"

// Configuration stores the configuration of the API client
type Configuration struct {
// ClientName is the name of the client using the SDK.
Expand All @@ -43,6 +42,10 @@ type Configuration struct {
// HTTPClient to use for the SDK.
// Optional. The default HTTPClient will be used if not provided.
HTTPClient *http.Client

// Default tags the client can set for objects that has tags support.
// Optional. The default is an empty map.
DefaultTags map[string]string
}

func (c Configuration) internal(basePath string) (*internal.Configuration, error) {
Expand Down Expand Up @@ -83,12 +86,15 @@ func (c Configuration) internal(basePath string) (*internal.Configuration, error

userAgent := fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version)

return &internal.Configuration{
ic := &internal.Configuration{
DefaultHeader: defaultHeaders,
UserAgent: userAgent,
Debug: false,
OperationServers: nil,
Servers: []internal.ServerConfiguration{{URL: cspURL}},
HTTPClient: httpClient,
}, nil
DefaultTags: c.DefaultTags,
}

return ic, nil
}
130 changes: 130 additions & 0 deletions client/configuration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package client

import (
"fmt"
"net/http"
"os"
"reflect"
"testing"

"github.com/infobloxopen/bloxone-go-client/internal"
)

func TestConfiguration_internal(t *testing.T) {
type fields struct {
ClientName string
CSPURL string
APIKey string
HTTPClient *http.Client
DefaultTags map[string]string
}
type args struct {
basePath string
}
tests := []struct {
name string
fields fields
args args
want *internal.Configuration
wantErr bool
}{
{
"empty API key",
fields{
APIKey: "",
},
args{basePath: ""},
nil,
true,
},
{"empty clientName",
fields{
ClientName: "",
},
args{basePath: ""},
nil,
true,
},
{
"empty DefaultTags",
fields{
ClientName: "terraform/v1.1#yug278872h",
APIKey: "12323455",
},
args{basePath: ""},
&internal.Configuration{
DefaultHeader: map[string]string{
HeaderAuthorization: "Token 12323455",
HeaderClient: "terraform/v1.1#yug278872h",
HeaderSDK: sdkIdentifier,
},
Debug: false,
UserAgent: fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version),
Servers: []internal.ServerConfiguration{{URL: "https://csp.infoblox.com"}},
HTTPClient: http.DefaultClient,
DefaultTags: nil,
},
false,
},
{
"DefaultTags provided",
fields{
CSPURL: "https://stage.csp.infoblox.com",
ClientName: "terraformv1.1#yug278872h",
APIKey: "12323455",
DefaultTags: map[string]string{
"site": "A",
"env": "test",
},
},
args{basePath: ""},
&internal.Configuration{
DefaultHeader: map[string]string{
HeaderAuthorization: "Token 12323455",
HeaderClient: "terraformv1.1#yug278872h",
HeaderSDK: sdkIdentifier,
},
Debug: false,
UserAgent: fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version),
Servers: []internal.ServerConfiguration{{URL: "https://stage.csp.infoblox.com"}},
HTTPClient: http.DefaultClient,
DefaultTags: map[string]string{
"site": "A",
"env": "test",
},
},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var curEnvVal string
c := Configuration{
ClientName: tt.fields.ClientName,
CSPURL: tt.fields.CSPURL,
APIKey: tt.fields.APIKey,
HTTPClient: tt.fields.HTTPClient,
DefaultTags: tt.fields.DefaultTags,
}
if c.CSPURL != "" {
curEnvVal = os.Getenv(ENVBloxOneCSPURL)
t.Setenv(ENVBloxOneCSPURL, c.CSPURL)
}

got, err := c.internal(tt.args.basePath)
if (err != nil) != tt.wantErr {
t.Errorf("internal() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("internal() got = %v, want %v", got, tt.want)
}
t.Cleanup(func() {
// Set it to the value prior to executing the test
if c.CSPURL != "" {
t.Setenv(ENVBloxOneCSPURL, curEnvVal)
}
})
})
}
}
25 changes: 16 additions & 9 deletions dns_config/api_acl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions dns_config/api_auth_nsg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading