From c54f093cee1bae782888280226db1acb79bcefdd Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Wed, 27 Nov 2024 01:23:02 +0530 Subject: [PATCH 1/3] chore: add x-atlan-client org header and fix: take version no from VERSION file Signed-off-by: Karanjot Singh --- atlan/assets/client.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/atlan/assets/client.go b/atlan/assets/client.go index 3e3fea6..bb44047 100644 --- a/atlan/assets/client.go +++ b/atlan/assets/client.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "log" "net/http" "net/url" "os" @@ -108,13 +109,18 @@ func configureClient() (*http.Client, *logger.Logger) { // defaultRequestParams returns default request parameters. func defaultRequestParams(apiKey string) map[string]interface{} { - VERSION := "0.0" + // Read the version from the VERSION file + VERSION, err := getVersion("VERSION") + if err != nil { + log.Fatalf("Error reading version: %v", err) + } headers := map[string]string{ - "x-atlan-agent": "sdk", - "x-atlan-agent-id": "go", - "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION), + "x-atlan-agent": "sdk", + "x-atlan-agent-id": "go", + "x-atlan-client-origin": "product_sdk", + "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION), } - + fmt.Println(headers) headers["Authorization"] = "Bearer " + apiKey headers["Accept"] = "application/json" headers["Content-type"] = "application/json" @@ -191,6 +197,15 @@ func (ac *AtlanClient) DisableLogging() { ac.SetLogger(false, "") } +// getVersion reads the version number from the specified file +func getVersion(filePath string) (string, error) { + content, err := os.ReadFile(filePath) + if err != nil { + return "", err + } + return strings.TrimSpace(string(content)), nil +} + // Removes authorization from header when using // s3PresignedUrlFileUpload/Download and returns the removed value. func (ac *AtlanClient) removeAuthorization() (string, error) { From c72c747798caf2003c7e3eba7a0e08eaf9cde504 Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Wed, 27 Nov 2024 01:24:19 +0530 Subject: [PATCH 2/3] chore: remove logging statement Signed-off-by: Karanjot Singh --- atlan/assets/client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atlan/assets/client.go b/atlan/assets/client.go index bb44047..64d8a9f 100644 --- a/atlan/assets/client.go +++ b/atlan/assets/client.go @@ -120,7 +120,6 @@ func defaultRequestParams(apiKey string) map[string]interface{} { "x-atlan-client-origin": "product_sdk", "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION), } - fmt.Println(headers) headers["Authorization"] = "Bearer " + apiKey headers["Accept"] = "application/json" headers["Content-type"] = "application/json" @@ -197,7 +196,7 @@ func (ac *AtlanClient) DisableLogging() { ac.SetLogger(false, "") } -// getVersion reads the version number from the specified file +// getVersion reads the version number from the VERSION file func getVersion(filePath string) (string, error) { content, err := os.ReadFile(filePath) if err != nil { From 729746011431d16e398067fbf56b373857f13c84 Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Wed, 27 Nov 2024 01:54:34 +0530 Subject: [PATCH 3/3] enhancement: centralize version handling using go:embed Signed-off-by: Karanjot Singh --- atlan/assets/client.go | 19 ++----------------- VERSION => config/VERSION | 0 config/version.go | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) rename VERSION => config/VERSION (100%) create mode 100644 config/version.go diff --git a/atlan/assets/client.go b/atlan/assets/client.go index 64d8a9f..53fff3d 100644 --- a/atlan/assets/client.go +++ b/atlan/assets/client.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/atlanhq/atlan-go/config" "io" - "log" "net/http" "net/url" "os" @@ -109,21 +109,15 @@ func configureClient() (*http.Client, *logger.Logger) { // defaultRequestParams returns default request parameters. func defaultRequestParams(apiKey string) map[string]interface{} { - // Read the version from the VERSION file - VERSION, err := getVersion("VERSION") - if err != nil { - log.Fatalf("Error reading version: %v", err) - } headers := map[string]string{ "x-atlan-agent": "sdk", "x-atlan-agent-id": "go", "x-atlan-client-origin": "product_sdk", - "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION), + "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", config.Version()), } headers["Authorization"] = "Bearer " + apiKey headers["Accept"] = "application/json" headers["Content-type"] = "application/json" - return map[string]interface{}{ "headers": headers, } @@ -196,15 +190,6 @@ func (ac *AtlanClient) DisableLogging() { ac.SetLogger(false, "") } -// getVersion reads the version number from the VERSION file -func getVersion(filePath string) (string, error) { - content, err := os.ReadFile(filePath) - if err != nil { - return "", err - } - return strings.TrimSpace(string(content)), nil -} - // Removes authorization from header when using // s3PresignedUrlFileUpload/Download and returns the removed value. func (ac *AtlanClient) removeAuthorization() (string, error) { diff --git a/VERSION b/config/VERSION similarity index 100% rename from VERSION rename to config/VERSION diff --git a/config/version.go b/config/version.go new file mode 100644 index 0000000..dbe2e81 --- /dev/null +++ b/config/version.go @@ -0,0 +1,14 @@ +package config + +import ( + _ "embed" + "strings" +) + +//go:embed VERSION +var versionFile string + +// Version returns the SDK version. +func Version() string { + return strings.TrimSpace(versionFile) +}