Skip to content

Commit

Permalink
Merge pull request #4 from atlanhq/error-handling-logging
Browse files Browse the repository at this point in the history
DVX-241: Error Handling in Go-sdk
  • Loading branch information
0xquark authored Mar 18, 2024
2 parents 2e56449 + 1cc55b8 commit 7c6f02b
Show file tree
Hide file tree
Showing 16 changed files with 3,457 additions and 353 deletions.
3 changes: 2 additions & 1 deletion atlan/client/atlan_fields.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"atlan-go/atlan"
"atlan-go/atlan/model"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func (sf *SearchableField) HasAnyValue() model.Query {
}

// Order Returns a condition to sort results by the field, in the specified order.
func (sf *SearchableField) Order(order model.SortOrder) model.SortItem {
func (sf *SearchableField) Order(order atlan.SortOrder) model.SortItem {
return model.SortItem{
Field: sf.ElasticFieldName,
Order: order,
Expand Down
4 changes: 1 addition & 3 deletions atlan/client/atlan_tag_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "C"
import (
"atlan-go/atlan/model"
"encoding/json"
"fmt"
"sync"
)

Expand Down Expand Up @@ -87,7 +86,7 @@ func (c *AtlanTagCache) RefreshCache() error {
var atlanTags model.TypeDefResponse
err = json.Unmarshal(response, &atlanTags)
if err != nil {
return fmt.Errorf("error unmarshalling Atlan tags: %v", err)
return AtlanError{ErrorCode: errorCodes[EXPIRED_API_TOKEN]}
}

c.cacheByID = make(map[string]model.AtlanTagDef)
Expand Down Expand Up @@ -119,7 +118,6 @@ func (c *AtlanTagCache) GetIDForName(name string) (string, error) {
// an entry in an audit log that refers to a classification that
// no longer exists)
c.deletedNames[name] = struct{}{}
fmt.Printf("deletedNames: %s\n", c.deletedNames)
}
}

Expand Down
9 changes: 2 additions & 7 deletions atlan/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (ac *AtlanClient) CallAPI(api *API, queryParams map[string]string, requestO

response, err := ac.makeRequest(api.Method, path, params)
if err != nil {
return nil, err
return nil, handleApiError(response)
}

ac.logHTTPStatus(response)
Expand Down Expand Up @@ -219,12 +219,7 @@ func (ac *AtlanClient) logHTTPStatus(response *http.Response) {
ac.logger.Printf("HTTP Status: %s\n", response.Status)
if response.StatusCode < 200 || response.StatusCode >= 300 {
// Read the response body for the error message
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
ac.logger.Printf("Error reading response body: %v\n", err)
} else {
ac.logger.Printf("Error: %s\n", string(bodyBytes))
}
ac.logger.Printf("Error: %s\n", handleApiError(response))
}
}
}
Expand Down
252 changes: 13 additions & 239 deletions atlan/client/constants.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package client

import (
"atlan-go/atlan/model"
"fmt"
"net/http"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -157,239 +153,17 @@ const (
CERTIFICATE_STATUS = "certificateStatus"

// TextAttributes Constants
CLASSIFICATION_NAMES = "__classificationNames"
CLASSIFICATIONS_TEXT = "__classificationsText"
CREATE_TIME_AS_DATE = "__timestamp.date"
DESCRIPTION = "description"
MEANINGS_TEXT = "__meaningsText"
NAME_TEXT = "name"
QUALIFIED_NAME_TEXT = "qualifiedName.text"
PROPAGATED_CLASSIFICATION_NAMES = "__propagatedClassificationNames"
PROPAGATED_TRAIT_NAMES = "__propagatedTraitNames"
SUPER_TYPE_NAMES_TEXT = "__superTypeNames"
TRAIT_NAMES = "__traitNames"
UPDATE_TIME_AS_DATE = "__modificationTimestamp.date"
USER_DESCRIPTION = "userDescription"
ACTIVE model.LiteralState = "ACTIVE"
DELETED model.LiteralState = "DELETED"
PURGED model.LiteralState = "PURGED"
ASCENDING model.SortOrder = "asc"
Descending model.SortOrder = "desc"
)

const (
SINGLE model.Cardinality = "SINGLE"
LIST model.Cardinality = "LIST"
SET model.Cardinality = "SET"
)

// Constants representing tag colors
const (
AtlanTagColorGreen model.AtlanTagColor = "Green"
AtlanTagColorYellow model.AtlanTagColor = "Yellow"
AtlanTagColorRed model.AtlanTagColor = "Red"
AtlanTagColorGray model.AtlanTagColor = "Gray"
)

// Constants representing type categories
const (
AtlanTypeCategoryEnum model.AtlanTypeCategory = "ENUM"
AtlanTypeCategoryStruct model.AtlanTypeCategory = "STRUCT"
AtlanTypeCategoryClassification model.AtlanTypeCategory = "CLASSIFICATION"
AtlanTypeCategoryEntity model.AtlanTypeCategory = "ENTITY"
AtlanTypeCategoryRelationship model.AtlanTypeCategory = "RELATIONSHIP"
AtlanTypeCategoryCustomMetadata model.AtlanTypeCategory = "BUSINESS_METADATA"
)

// AdminOperationType - Enum for admin operation types.
type AdminOperationType string

const (
Create AdminOperationType = "CREATE"
Update AdminOperationType = "UPDATE"
Delete AdminOperationType = "DELETE"
Action AdminOperationType = "ACTION"
)

// AdminResourceType - Enum for admin resource types.
type AdminResourceType string

const (
Realm AdminResourceType = "REALM"
RealmRole AdminResourceType = "REALM_ROLE"
RealmRoleMapping AdminResourceType = "REALM_ROLE_MAPPING"
RealmScopeMapping AdminResourceType = "REALM_SCOPE_MAPPING"
AuthFlow AdminResourceType = "AUTH_FLOW"
AuthExecutionFlow AdminResourceType = "AUTH_EXECUTION_FLOW"
AuthExecution AdminResourceType = "AUTH_EXECUTION"
AuthenticatorConfig AdminResourceType = "AUTHENTICATOR_CONFIG"
RequiredAction AdminResourceType = "REQUIRED_ACTION"
IdentityProvider AdminResourceType = "IDENTITY_PROVIDER"
IdentityProviderMapper AdminResourceType = "IDENTITY_PROVIDER_MAPPER"
ProtocolMapper AdminResourceType = "PROTOCOL_MAPPER"
User AdminResourceType = "USER"
UserLoginFailure AdminResourceType = "USER_LOGIN_FAILURE"
UserSession AdminResourceType = "USER_SESSION"
UserFederationProvider AdminResourceType = "USER_FEDERATION_PROVIDER"
UserFederationMapper AdminResourceType = "USER_FEDERATION_MAPPER"
Group AdminResourceType = "GROUP"
GroupMembership AdminResourceType = "GROUP_MEMBERSHIP"
Client AdminResourceType = "CLIENT"
ClientInitialAccessModel AdminResourceType = "CLIENT_INITIAL_ACCESS_MODEL"
ClientRole AdminResourceType = "CLIENT_ROLE"
ClientRoleMapping AdminResourceType = "CLIENT_ROLE_MAPPING"
ClientScope AdminResourceType = "CLIENT_SCOPE"
ClientScopeMapping AdminResourceType = "CLIENT_SCOPE_MAPPING"
ClientScopeClientMapping AdminResourceType = "CLIENT_SCOPE_CLIENT_MAPPING"
ClusterNode AdminResourceType = "CLUSTER_NODE"
Component AdminResourceType = "COMPONENT"
AuthorizationResourceServer AdminResourceType = "AUTHORIZATION_RESOURCE_SERVER"
AuthorizationResource AdminResourceType = "AUTHORIZATION_RESOURCE"
AuthorizationScope AdminResourceType = "AUTHORIZATION_SCOPE"
AuthorizationPolicy AdminResourceType = "AUTHORIZATION_POLICY"
Custom AdminResourceType = "CUSTOM"
)

// AnnouncementType represents the type of an announcement.
type AnnouncementType string

const (
Information AnnouncementType = "information"
Warning AnnouncementType = "warning"
Issue AnnouncementType = "issue"
)

// AssetSidebarTab represents the tabs available in the asset sidebar.
type AssetSidebarTab string

const (
Overview AssetSidebarTab = "overview"
Columns AssetSidebarTab = "Columns"
Runs AssetSidebarTab = "Runs"
Tasks AssetSidebarTab = "Tasks"
Components AssetSidebarTab = "Components"
Projects AssetSidebarTab = "Projects"
Collections AssetSidebarTab = "Collections"
Usage AssetSidebarTab = "Usage"
Objects AssetSidebarTab = "Objects"
Lineage AssetSidebarTab = "Lineage"
Incidents AssetSidebarTab = "Incidents"
Fields AssetSidebarTab = "Fields"
Visuals AssetSidebarTab = "Visuals"
Visualizations AssetSidebarTab = "Visualizations"
SchemaObjects AssetSidebarTab = "Schema Objects"
Relations AssetSidebarTab = "Relations"
FactDimRelations AssetSidebarTab = "Fact-Dim Relations"
Profile AssetSidebarTab = "Profile"
Assets AssetSidebarTab = "Assets"
Activity AssetSidebarTab = "Activity"
Schedules AssetSidebarTab = "Schedules"
Resources AssetSidebarTab = "Resources"
Queries AssetSidebarTab = "Queries"
Requests AssetSidebarTab = "Requests"
Properties AssetSidebarTab = "Properties"
MonteCarlo AssetSidebarTab = "Monte Carlo"
DbtTest AssetSidebarTab = "dbt Test"
Soda AssetSidebarTab = "Soda"
)

// AtlanComparisonOperator represents comparison operators in Atlan.
type AtlanComparisonOperator string

const (
LT AtlanComparisonOperator = "<"
GT AtlanComparisonOperator = ">"
LTE AtlanComparisonOperator = "<="
GTE AtlanComparisonOperator = ">="
EQ AtlanComparisonOperator = "="
NEQ AtlanComparisonOperator = "!="
In AtlanComparisonOperator = "in"
Like AtlanComparisonOperator = "like"
StartsWith AtlanComparisonOperator = "startsWith"
EndsWith AtlanComparisonOperator = "endsWith"
Contains AtlanComparisonOperator = "contains"
NotContains AtlanComparisonOperator = "not_contains"
ContainsAny AtlanComparisonOperator = "containsAny"
ContainsAll AtlanComparisonOperator = "containsAll"
IsNull AtlanComparisonOperator = "isNull"
NotNull AtlanComparisonOperator = "notNull"
TimeRange AtlanComparisonOperator = "timerange"
NotEmpty AtlanComparisonOperator = "notEmpty"
)

// AtlanConnectionCategory represents the category of a connection in Atlan.
type AtlanConnectionCategory string

const (
Warehouse AtlanConnectionCategory = "warehouse"
BI AtlanConnectionCategory = "bi"
ObjectStore AtlanConnectionCategory = "ObjectStore"
SAAS AtlanConnectionCategory = "SaaS"
Lake AtlanConnectionCategory = "lake"
QueryEngine AtlanConnectionCategory = "queryengine"
ELT AtlanConnectionCategory = "elt"
Database AtlanConnectionCategory = "database"
api AtlanConnectionCategory = "API"
EventBus AtlanConnectionCategory = "eventbus"
DataQuality AtlanConnectionCategory = "data-quality"
SchemaRegistry AtlanConnectionCategory = "schema-registry"
)

// AtlanConnectorType represents connector types with their categories.
type AtlanConnectorType struct {
Value string
Category AtlanConnectionCategory
}

// ConnectorTypes is a map of all connector types for easy lookup.
var ConnectorTypes = map[string]AtlanConnectorType{
"snowflake": {Value: "snowflake", Category: Warehouse},
"tableau": {Value: "tableau", Category: BI},
// Add other connectors here
}

// NewAtlanConnectorType creates a new AtlanConnectorType with the given value and category.
func NewAtlanConnectorType(value string, category AtlanConnectionCategory) AtlanConnectorType {
return AtlanConnectorType{Value: value, Category: category}
}

// ToQualifiedName generates a qualified name for the AtlanConnectorType.
func (a AtlanConnectorType) ToQualifiedName() string {
return fmt.Sprintf("default/%s/%d", a.Value, time.Now().Unix())
}

// GetConnectorTypeFromQualifiedName attempts to extract an AtlanConnectorType from a qualified name.
func GetConnectorTypeFromQualifiedName(qualifiedName string) (AtlanConnectorType, error) {
tokens := strings.Split(qualifiedName, "/")
if len(tokens) > 1 {
if ct, exists := ConnectorTypes[tokens[1]]; exists {
return ct, nil
}
}
return AtlanConnectorType{}, fmt.Errorf("could not determine AtlanConnectorType from %s", qualifiedName)
}

// AtlanCustomAttributePrimitiveType simulates an enum for custom attribute primitive types.
type AtlanCustomAttributePrimitiveType string

const (
String AtlanCustomAttributePrimitiveType = "string"
Integer AtlanCustomAttributePrimitiveType = "int"
Decimal AtlanCustomAttributePrimitiveType = "float"
Boolean AtlanCustomAttributePrimitiveType = "boolean"
Date AtlanCustomAttributePrimitiveType = "date"
Options AtlanCustomAttributePrimitiveType = "enum"
Users AtlanCustomAttributePrimitiveType = "users"
Groups AtlanCustomAttributePrimitiveType = "groups"
URL AtlanCustomAttributePrimitiveType = "url"
SQL AtlanCustomAttributePrimitiveType = "SQL"
)

// AtlanDeleteType simulates an enum for delete types.
type AtlanDeleteType string

const (
Hard AtlanDeleteType = "HARD"
Soft AtlanDeleteType = "SOFT"
Purge AtlanDeleteType = "PURGE"
CLASSIFICATION_NAMES = "__classificationNames"
CLASSIFICATIONS_TEXT = "__classificationsText"
CREATE_TIME_AS_DATE = "__timestamp.date"
DESCRIPTION = "description"
MEANINGS_TEXT = "__meaningsText"
NAME_TEXT = "name"
QUALIFIED_NAME_TEXT = "qualifiedName.text"
PROPAGATED_CLASSIFICATION_NAMES = "__propagatedClassificationNames"
PROPAGATED_TRAIT_NAMES = "__propagatedTraitNames"
SUPER_TYPE_NAMES_TEXT = "__superTypeNames"
TRAIT_NAMES = "__traitNames"
UPDATE_TIME_AS_DATE = "__modificationTimestamp.date"
USER_DESCRIPTION = "userDescription"
)
Loading

0 comments on commit 7c6f02b

Please sign in to comment.