From 0a51491658e50420170d8e9826386ef9e3878eeb Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Thu, 2 May 2024 01:09:11 +0530 Subject: [PATCH 1/2] Enable UTM tags in IndexSearch Signed-off-by: Karanjot Singh --- atlan/client/fluent_search.go | 4 + atlan/client/index_search_client.go | 20 +++-- atlan/enums.go | 119 ++++++++++++++++++++++++++++ atlan/model/search.go | 37 +++++---- 4 files changed, 157 insertions(+), 23 deletions(-) diff --git a/atlan/client/fluent_search.go b/atlan/client/fluent_search.go index b3ea62b..3516545 100644 --- a/atlan/client/fluent_search.go +++ b/atlan/client/fluent_search.go @@ -183,6 +183,10 @@ func (fs *FluentSearch) ToRequest() *model.IndexSearchRequest { Aggregation: fs.Aggregations, TrackTotalHits: true, }, + Metadata: model.Metadata{ + SaveSearchLog: true, + UtmTags: []string{atlan.PROJECT_SDK_GO.String()}, + }, } // Add Wheres to Query diff --git a/atlan/client/index_search_client.go b/atlan/client/index_search_client.go index ce9eb7e..4af7fd6 100644 --- a/atlan/client/index_search_client.go +++ b/atlan/client/index_search_client.go @@ -52,10 +52,14 @@ func FindGlossaryByName(glossaryName string) (*model.IndexSearchResponse, error) TrackTotalHits: true, Sort: sortItemsJSON, }, - SuppressLogs: true, - ShowSearchScore: false, - ExcludeMeanings: false, - ExcludeClassifications: false, + SuppressLogs: true, + ShowSearchScore: false, + ExcludeMeanings: false, + ExcludeAtlanTags: false, + Metadata: model.Metadata{ + SaveSearchLog: true, + UtmTags: []string{atlan.PROJECT_SDK_GO.String()}, + }, } iterator := NewIndexSearchIterator(pageSize, request) @@ -98,10 +102,10 @@ func FindCategoryByName(categoryName string, glossaryQualifiedName string) (*mod Query: boolQuery.ToJSON(), TrackTotalHits: true, }, - SuppressLogs: true, - ShowSearchScore: false, - ExcludeMeanings: false, - ExcludeClassifications: false, + SuppressLogs: true, + ShowSearchScore: false, + ExcludeMeanings: false, + ExcludeAtlanTags: false, } iterator := NewIndexSearchIterator(pageSize, request) diff --git a/atlan/enums.go b/atlan/enums.go index 94a3054..1121c53 100644 --- a/atlan/enums.go +++ b/atlan/enums.go @@ -2702,3 +2702,122 @@ func (q *QueryUsernameStrategy) UnmarshalJSON(data []byte) error { return nil } + +type UTMTags struct { + Name string +} + +func (u UTMTags) String() string { + return u.Name +} + +var ( + // PAGE_ entries indicate where the action was taken. + + // Search was made from the home page. + PAGE_HOME = UTMTags{"page_home"} + // Search was made from the assets (discovery) page. + PAGE_ASSETS = UTMTags{"page_assets"} + // Asset was viewed from within a glossary. + PAGE_GLOSSARY = UTMTags{"page_glossary"} + // Asset was viewed from within insights. + PAGE_INSIGHTS = UTMTags{"page_insights"} + + // PROJECT_ entries indicate how (via what application) the action was taken. + + // Search was made via the webapp (UI) + PROJECT_WEBAPP = UTMTags{"project_webapp"} + // Search was made via the Java SDK. + PROJECT_SDK_JAVA = UTMTags{"project_sdk_java"} + // Search was made via the Python SDK. + PROJECT_SDK_PYTHON = UTMTags{"project_sdk_python"} + // Search was made via the Go SDK. + PROJECT_SDK_GO = UTMTags{"project_sdk_go"} + // Search was made via the atlan cli. + PROJECT_SDK_CLI = UTMTags{"project_sdk_cli"} + + // ACTION_ entries dictate the specific action that was taken. + + // Assets were searched. + ACTION_SEARCHED = UTMTags{"action_searched"} + // Search was run through the Cmd-K popup. + ACTION_CMD_K = UTMTags{"action_cmd_k"} + // Search was through changing a filter in the UI (discovery). + ACTION_FILTER_CHANGED = UTMTags{"action_filter_changed"} + // Search was through changing a type filter (pill) in the UI (discovery) + ACTION_ASSET_TYPE_CHANGED = UTMTags{"action_asset_type_changed"} + // Asset was viewed, rather than an explicit search. + ACTION_ASSET_VIEWED = UTMTags{"action_asset_viewed"} + + // Others indicate any special mechanisms used for the action. + + // Search was run using the UI popup searchbar. + UI_POPUP_SEARCHBAR = UTMTags{"ui_popup_searchbar"} + // Search was through a UI filter (discovery). + UI_FILTERS = UTMTags{"ui_filters"} + // View was done via the UI's sidebar. + UI_SIDEBAR = UTMTags{"ui_sidebar"} + // View was done of the full asset profile, not only sidebar. + UI_PROFILE = UTMTags{"ui_profile"} + // Listing of assets, usually by a particular type, in the discovery page. + UI_MAIN_LIST = UTMTags{"ui_main_list"} +) + +func (u UTMTags) MarshalJSON() ([]byte, error) { + return json.Marshal(u.Name) +} + +func (u *UTMTags) UnmarshalJSON(data []byte) error { + var UtmTags string + if err := json.Unmarshal(data, &UtmTags); err != nil { + return err + } + + switch UtmTags { + case "page_home": + *u = PAGE_HOME + switch UtmTags { + case "page_home": + *u = PAGE_HOME + case "page_assets": + *u = PAGE_ASSETS + case "page_glossary": + *u = PAGE_GLOSSARY + case "page_insights": + *u = PAGE_INSIGHTS + case "project_webapp": + *u = PROJECT_WEBAPP + case "project_sdk_java": + *u = PROJECT_SDK_JAVA + case "project_sdk_python": + *u = PROJECT_SDK_PYTHON + case "project_sdk_go": + *u = PROJECT_SDK_GO + case "project_sdk_cli": + *u = PROJECT_SDK_CLI + case "action_searched": + *u = ACTION_SEARCHED + case "action_cmd_k": + *u = ACTION_CMD_K + case "action_filter_changed": + *u = ACTION_FILTER_CHANGED + case "action_asset_type_changed": + *u = ACTION_ASSET_TYPE_CHANGED + case "action_asset_viewed": + *u = ACTION_ASSET_VIEWED + case "ui_popup_searchbar": + *u = UI_POPUP_SEARCHBAR + case "ui_filters": + *u = UI_FILTERS + case "ui_sidebar": + *u = UI_SIDEBAR + case "ui_profile": + *u = UI_PROFILE + case "ui_main_list": + *u = UI_MAIN_LIST + default: + *u = UTMTags{Name: UtmTags} + } + } + return nil +} diff --git a/atlan/model/search.go b/atlan/model/search.go index c7abf9a..576fa70 100644 --- a/atlan/model/search.go +++ b/atlan/model/search.go @@ -411,15 +411,22 @@ type SearchRequest struct { RelationsAttributes []string `json:"relationsAttributes,omitempty"` } +type Metadata struct { + SaveSearchLog bool `json:"saveSearchLog,omitempty"` + UtmTags []string `json:"utmTags,omitempty"` +} + // IndexSearchRequest represents a search request in the Atlas search DSL. type IndexSearchRequest struct { SearchRequest - Dsl Dsl `json:"dsl"` - RelationAttributes []string `json:"relationAttributes,omitempty"` - SuppressLogs bool `json:"suppressLogs"` - ShowSearchScore bool `json:"showSearchScore"` - ExcludeMeanings bool `json:"excludeMeanings"` - ExcludeClassifications bool `json:"excludeClassifications"` + Dsl Dsl `json:"dsl"` + RelationAttributes []string `json:"relationAttributes,omitempty"` + SuppressLogs bool `json:"suppressLogs,omitempty"` + ShowSearchScore bool `json:"showSearchScore,omitempty"` + ExcludeMeanings bool `json:"excludeMeanings,omitempty"` + ExcludeAtlanTags bool `json:"excludeClassifications,omitempty"` + AllowDeletedRelations bool `json:"allowDeletedRelations,omitempty"` + Metadata Metadata `json:"requestMetadata,omitempty"` } // Dsl represents the DSL for the Atlas search request. @@ -445,15 +452,15 @@ type IndexSearchResponse struct { // SearchParameters represents the search parameters in the Atlas search response. type SearchParameters struct { - ShowSearchScore bool `json:"showSearchScore"` - SuppressLogs bool `json:"suppressLogs"` - ExcludeMeanings bool `json:"excludeMeanings"` - ExcludeAtlanTags bool `json:"excludeClassifications"` - AllowDeletedRelations bool `json:"allowDeletedRelations"` - SaveSearchLog bool `json:"saveSearchLog"` - RequestMetadata map[string]interface{} `json:"requestMetadata"` - Dsl Dsl `json:"dsl"` - Query string `json:"query"` + ShowSearchScore bool `json:"showSearchScore"` + SuppressLogs bool `json:"suppressLogs"` + ExcludeMeanings bool `json:"excludeMeanings"` + ExcludeAtlanTags bool `json:"excludeClassifications"` + AllowDeletedRelations bool `json:"allowDeletedRelations"` + SaveSearchLog bool `json:"saveSearchLog"` + RequestMetadata Metadata `json:"requestMetadata"` + Dsl Dsl `json:"dsl"` + Query string `json:"query"` } type SearchAssets struct { From c17dec2e4832aa40208d28538df34fb1f839848a Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Thu, 2 May 2024 22:51:55 +0530 Subject: [PATCH 2/2] Add x-atlan-agent headers Signed-off-by: Karanjot Singh --- atlan/client/client.go | 13 ++++++ main.go | 101 +++++++++++++++++++++++++++++++---------- 2 files changed, 89 insertions(+), 25 deletions(-) diff --git a/atlan/client/client.go b/atlan/client/client.go index 9d7ed84..0d0d532 100644 --- a/atlan/client/client.go +++ b/atlan/client/client.go @@ -58,6 +58,13 @@ func Context(apiKey, baseURL string) (*AtlanClient, error) { logger = log.New(io.Discard, "", 0) // Logger that discards all log output } + VERSION := "0.0" + headers := map[string]string{ + "x-atlan-agent": "sdk", + "x-atlan-agent-id": "go", + "User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION), + } + atlanClient := &AtlanClient{ Session: client, host: baseURL, @@ -82,6 +89,11 @@ func Context(apiKey, baseURL string) (*AtlanClient, error) { }, } + // Merge the provided headers with existing headers + for key, value := range headers { + atlanClient.requestParams["headers"].(map[string]string)[key] = value + } + // Initialize the default atlan client DefaultAtlanClient = atlanClient @@ -213,6 +225,7 @@ func (ac *AtlanClient) makeRequest(method, path string, params map[string]interf req.URL.RawQuery = query } + fmt.Println(req.Header) return ac.Session.Do(req) } diff --git a/main.go b/main.go index 0f2f3f2..55d9761 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" + "github.com/atlanhq/atlan-go/atlan" "github.com/atlanhq/atlan-go/atlan/client" ) @@ -11,35 +12,85 @@ func main() { client.LoggingEnabled = true ctx := client.NewContext() - client.GetCustomMetadataCache().RefreshCache() - id, err := client.GetCustomMetadataCache().GetIDForName("testcmgsdk") - if err != nil { - fmt.Println("Error:", err) - } - name, _ := client.GetCustomMetadataCache().GetNameForID("cvhn5T7YwnsYXiMCKh9PoW") - attrID, _ := client.GetCustomMetadataCache().GetAttrIDForName("testcmgsdk", "gsdk") - attrName, _ := client.GetCustomMetadataCache().GetAttrNameForID("cvhn5T7YwnsYXiMCKh9PoW", "foYi4v02OVjKt0YzcTCKM3") - fmt.Println("ID for name is : ", id) - fmt.Println("Name fo ID is:", name) - fmt.Printf("\nAttrID for name is: %s\n", attrID) - fmt.Printf("\nAttrName for ID is: %s\n", attrName) - - fmt.Println(client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk")) - customMetadata := client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk") - - customMeta, _ := client.NewFluentSearch(). + // Fetch columns of table from Atlan using Qualified Name + qualifiedname := "default/snowflake/1714501359/ANALYTICS/WIDE_WORLD_IMPORTERS/CUSTOMERR/ID" + + columnResult := client.NewFluentSearch(). PageSizes(50). ActiveAssets(). - Where(ctx.Glossary.QUALIFIED_NAME.Eq("fW6NU2lWKaMy5ZyVlGYes")). - IncludeOnResults(customMetadata...). - IncludeOnResults("terms"). - IncludeOnResults("tags"). - Execute() - - for _, entity := range customMeta[0].Entities { - fmt.Println("Entity:", *entity.DisplayName) + Where(ctx.Column.TYPENAME.Eq("Column")). + Where(ctx.Column.QUALIFIED_NAME.Eq(qualifiedname)). + ToRequest() + + columnResult.Metadata.UtmTags = []string{atlan.PROJECT_SDK_CLI.String()} + + iterator := client.NewIndexSearchIterator(columnResult.Size, *columnResult) + + for iterator.HasMoreResults() { + responses, _ := iterator.IteratePages() + for _, response := range responses { + fmt.Println(response) + break + } + break } + /* + if err != nil { + fmt.Printf("Error executing search: %v\n", err) + return + } + + fmt.Println("Search results:", *columnResult[0].Entities[0].Name) + fmt.Println("Search results:", *columnResult[0].Entities[0].QualifiedName) + + + */ + //client.GetAll() + + /* + dc := &client.DataContract{} + dc.Creator("DataContractLatestCertified") + response, err := client.Save() + if err != nil { + fmt.Println(err) + } + fmt.Println("response", response) + + + */ + /* + client.GetCustomMetadataCache().RefreshCache() + id, err := client.GetCustomMetadataCache().GetIDForName("testcmgsdk") + if err != nil { + fmt.Println("Error:", err) + } + name, _ := client.GetCustomMetadataCache().GetNameForID("cvhn5T7YwnsYXiMCKh9PoW") + attrID, _ := client.GetCustomMetadataCache().GetAttrIDForName("testcmgsdk", "gsdk") + attrName, _ := client.GetCustomMetadataCache().GetAttrNameForID("cvhn5T7YwnsYXiMCKh9PoW", "foYi4v02OVjKt0YzcTCKM3") + fmt.Println("ID for name is : ", id) + fmt.Println("Name fo ID is:", name) + fmt.Printf("\nAttrID for name is: %s\n", attrID) + fmt.Printf("\nAttrName for ID is: %s\n", attrName) + + fmt.Println(client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk")) + customMetadata := client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk") + + customMeta, _ := client.NewFluentSearch(). + PageSizes(50). + ActiveAssets(). + Where(ctx.Glossary.QUALIFIED_NAME.Eq("fW6NU2lWKaMy5ZyVlGYes")). + IncludeOnResults(customMetadata...). + IncludeOnResults("terms"). + IncludeOnResults("tags"). + Execute() + + for _, entity := range customMeta[0].Entities { + fmt.Println("Entity:", *entity.AssetDbtJobNextRunHumanized) + } + + + */ /* ctx := client.NewContext() assetQualifiedName := "default/mssql/1711817247/WideWorldImporters/Purchasing/SupplierCategories_Archive"