Skip to content

Commit

Permalink
Merge pull request #35 from atlanhq/DVX-482-truncate-the-part-of-the-…
Browse files Browse the repository at this point in the history
…url-after-com-co-etc-in-the-base-url

Dvx 482 Normalize and Truncate the part of the url after `com, co` etc in the base url
  • Loading branch information
0xquark authored Jun 6, 2024
2 parents ad480f2 + fbe9a7d commit 0aa45a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions atlan/assets/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (
func Init() error {
apiKey, baseURL := retrieveAPIConfig()

// Normalize the baseURL
baseURL = normalizeURL(baseURL)

// Configure client and logger
client, logger := configureClient()

Expand All @@ -50,6 +53,9 @@ func Init() error {

// Context creates a new AtlanClient with provided API key and base URL.
func Context(baseURL, apiKey string) (*AtlanClient, error) {
// Normalize the baseURL
baseURL = normalizeURL(baseURL)

// Configure client and logger
client, logger := configureClient()

Expand Down Expand Up @@ -143,6 +149,23 @@ func retrieveAPIConfig() (apiKey, baseURL string) {
return apiKey, baseURL
}

// normalizeURL ensures the URL starts with "https://" and truncates after the domain.
func normalizeURL(rawURL string) string {
// Ensure URL starts with "http://" or "https://"
if !strings.HasPrefix(rawURL, "http://") && !strings.HasPrefix(rawURL, "https://") {
rawURL = "https://" + rawURL
}

// Parse the URL
parsedURL, err := url.Parse(rawURL)
if err != nil {
panic(fmt.Sprintf("Invalid URL: %v", err))
}

// Truncate the URL after the host
return parsedURL.Scheme + "://" + parsedURL.Host
}

// SetLogger enables or disables logging and sets the log level.
func (ac *AtlanClient) SetLogger(enabled bool, level string) {
// Create a new logger configuration
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ func main() {

ctx := assets.NewContext()

//ctx, _ := assets.Context("API_KEY", "BASE_URL")
//ctx, _ := assets.Context("tenet.atlan.com", "xyz")

ctx.SetLogger(true, "debug")

qualifiedname := "default/snowflake/1715371897/RAW/WIDEWORLDIMPORTERS_SALESFORCE/FIVETRAN_API_CALL"
Expand Down

0 comments on commit 0aa45a7

Please sign in to comment.