-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0652b1c
Merge branch 'master' of github.com:infobloxopen/bloxone-go-client in…
venkat-iblox 9ccdea9
latest generator changes + make fmt
venkat-iblox 5e1dc48
Update go client to support default tags
venkat-iblox bc2d96d
Removing system tag
venkat-iblox 236508e
go fmt
venkat-iblox f343fb0
PR comments
venkat-iblox 79df307
PR comments
venkat-iblox 5a4033e
Merge branch 'master' of github.com:infobloxopen/bloxone-go-client in…
venkat-iblox 0ce39fc
go fmt
venkat-iblox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,100 @@ | ||
package client | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/infobloxopen/bloxone-go-client/internal" | ||
"github.com/infobloxopen/bloxone-go-client/internal" | ||
) | ||
|
||
const ( | ||
ENVBloxOneCSPURL = "BLOXONE_CSP_URL" | ||
ENVBloxOneAPIKey = "BLOXONE_API_KEY" | ||
ENVBloxOneCSPURL = "BLOXONE_CSP_URL" | ||
ENVBloxOneAPIKey = "BLOXONE_API_KEY" | ||
) | ||
|
||
const ( | ||
HeaderClient = "x-infoblox-client" | ||
HeaderSDK = "x-infoblox-sdk" | ||
HeaderAuthorization = "Authorization" | ||
version = "0.1" | ||
sdkIdentifier = "golang-sdk" | ||
HeaderClient = "x-infoblox-client" | ||
HeaderSDK = "x-infoblox-sdk" | ||
HeaderAuthorization = "Authorization" | ||
version = "0.1" | ||
sdkIdentifier = "golang-sdk" | ||
) | ||
|
||
// Configuration stores the configuration of the API client | ||
type Configuration struct { | ||
// ClientName is the name of the client using the SDK. | ||
// Required. | ||
ClientName string | ||
|
||
// CSPURL is the URL for BloxOne Cloud Services Portal. | ||
// Can also be configured using the `BLOXONE_CSP_URL` environment variable. | ||
// Optional. Default is https://csp.infoblox.com | ||
CSPURL string | ||
|
||
// APIKey for accessing the BloxOne API. | ||
// Can also be configured by using the `BLOXONE_API_KEY` environment variable. | ||
// https://docs.infoblox.com/space/BloxOneCloud/35430405/Configuring+User+API+Keys | ||
// Required. | ||
APIKey string | ||
|
||
// HTTPClient to use for the SDK. | ||
// Optional. The default HTTPClient will be used if not provided. | ||
HTTPClient *http.Client | ||
|
||
// Default global tags the client can set for all requests. | ||
DefaultTags map[string]string | ||
// ClientName is the name of the client using the SDK. | ||
// Required. | ||
ClientName string | ||
|
||
// CSPURL is the URL for BloxOne Cloud Services Portal. | ||
// Can also be configured using the `BLOXONE_CSP_URL` environment variable. | ||
// Optional. Default is https://csp.infoblox.com | ||
CSPURL string | ||
|
||
// APIKey for accessing the BloxOne API. | ||
// Can also be configured by using the `BLOXONE_API_KEY` environment variable. | ||
// https://docs.infoblox.com/space/BloxOneCloud/35430405/Configuring+User+API+Keys | ||
// Required. | ||
APIKey string | ||
|
||
// 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) { | ||
cspURL := "https://csp.infoblox.com" | ||
if v, ok := os.LookupEnv(ENVBloxOneCSPURL); ok { | ||
cspURL = v | ||
} | ||
if len(c.CSPURL) > 0 { | ||
cspURL = c.CSPURL | ||
} | ||
cspURL = cspURL + basePath | ||
|
||
apiKey := "" | ||
if v, ok := os.LookupEnv(ENVBloxOneAPIKey); ok { | ||
apiKey = v | ||
} | ||
if len(c.APIKey) > 0 { | ||
apiKey = c.APIKey | ||
} | ||
if len(apiKey) == 0 { | ||
return nil, errors.New("APIKey is required") | ||
} | ||
|
||
if len(c.ClientName) == 0 { | ||
return nil, errors.New("ClientName is required") | ||
} | ||
|
||
httpClient := c.HTTPClient | ||
if httpClient == nil { | ||
httpClient = http.DefaultClient | ||
} | ||
|
||
defaultHeaders := map[string]string{ | ||
HeaderAuthorization: "Token " + apiKey, | ||
HeaderClient: c.ClientName, | ||
HeaderSDK: sdkIdentifier, | ||
} | ||
|
||
userAgent := fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version) | ||
|
||
ic := &internal.Configuration{ | ||
DefaultHeader: defaultHeaders, | ||
UserAgent: userAgent, | ||
Debug: false, | ||
OperationServers: nil, | ||
Servers: []internal.ServerConfiguration{{URL: cspURL}}, | ||
HTTPClient: httpClient, | ||
DefaultTags: make(map[string]string), | ||
} | ||
// Add default tags set | ||
if c.DefaultTags != nil { | ||
ic.AddDefaultTags(c.DefaultTags) | ||
} | ||
|
||
return ic, nil | ||
cspURL := "https://csp.infoblox.com" | ||
if v, ok := os.LookupEnv(ENVBloxOneCSPURL); ok { | ||
cspURL = v | ||
} | ||
if len(c.CSPURL) > 0 { | ||
cspURL = c.CSPURL | ||
} | ||
cspURL = cspURL + basePath | ||
|
||
apiKey := "" | ||
if v, ok := os.LookupEnv(ENVBloxOneAPIKey); ok { | ||
apiKey = v | ||
} | ||
if len(c.APIKey) > 0 { | ||
apiKey = c.APIKey | ||
} | ||
if len(apiKey) == 0 { | ||
return nil, errors.New("APIKey is required") | ||
} | ||
|
||
if len(c.ClientName) == 0 { | ||
return nil, errors.New("ClientName is required") | ||
} | ||
|
||
httpClient := c.HTTPClient | ||
if httpClient == nil { | ||
httpClient = http.DefaultClient | ||
} | ||
|
||
defaultHeaders := map[string]string{ | ||
HeaderAuthorization: "Token " + apiKey, | ||
HeaderClient: c.ClientName, | ||
HeaderSDK: sdkIdentifier, | ||
} | ||
|
||
userAgent := fmt.Sprintf("bloxone-%s/%s", sdkIdentifier, version) | ||
|
||
ic := &internal.Configuration{ | ||
DefaultHeader: defaultHeaders, | ||
UserAgent: userAgent, | ||
Debug: false, | ||
OperationServers: nil, | ||
Servers: []internal.ServerConfiguration{{URL: cspURL}}, | ||
HTTPClient: httpClient, | ||
DefaultTags: c.DefaultTags, | ||
} | ||
|
||
return ic, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually do
Get...
methods in Go. We can update get generator and fix that in another PR.