Skip to content

Commit

Permalink
Add OneLake Data-Lake support and missing Auth fields in connectors (#95
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fivetran-aleksandrboldyrev authored Nov 17, 2023
1 parent 5858c5c commit 57cb9f5
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 16 deletions.
128 changes: 116 additions & 12 deletions connectors/connector_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,43 @@ import "github.com/fivetran/go-fivetran/utils"
// ConnectorAuth builds Connector Management, Auth.
// Ref. https://fivetran.com/docs/rest-api/connectors
type ConnectorAuth struct {
clientAccess *ConnectorAuthClientAccess
refreshToken *string
accessToken *string
realmID *string
clientAccess *ConnectorAuthClientAccess
refreshToken *string
accessToken *string
realmID *string
previousRefreshToken *string
userAccessToken *string
consumerSecret *string
consumerKey *string
oauthToken *string
oauthTokenSecret *string
roleArn *string
awsAccessKey *string
awsSecretKey *string
clientId *string
keyId *string
teamId *string
clientSecret *string
}

type connectorAuthRequest struct {
ClientAccess *connectorAuthClientAccessRequest `json:"client_access,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
AccessToken *string `json:"access_token,omitempty"`
RealmID *string `json:"realm_id,omitempty"`
ClientAccess *connectorAuthClientAccessRequest `json:"client_access,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
AccessToken *string `json:"access_token,omitempty"`
RealmID *string `json:"realm_id,omitempty"`
PreviousRefreshToken *string `json:"previous_refresh_token,omitempty"`
UserAccessToken *string `json:"user_access_token,omitempty"`
ConsumerSecret *string `json:"consumer_secret,omitempty"`
ConsumerKey *string `json:"consumer_key,omitempty"`
OauthToken *string `json:"oauth_token,omitempty"`
OauthTokenSecret *string `json:"oauth_token_secret,omitempty"`
RoleArn *string `json:"role_arn,omitempty"`
AwsAccessKey *string `json:"aws_access_key,omitempty"`
AwsSecretKey *string `json:"aws_secret_key,omitempty"`
ClientId *string `json:"client_id,omitempty"`
KeyId *string `json:"key_id,omitempty"`
TeamId *string `json:"team_id,omitempty"`
ClientSecret *string `json:"client_secret,omitempty"`
}

func (ca *ConnectorAuth) Merge(customAuth *map[string]interface{}) (*map[string]interface{}, error) {
Expand All @@ -33,10 +59,23 @@ func (ca *ConnectorAuth) Request() *connectorAuthRequest {
}

return &connectorAuthRequest{
ClientAccess: clientAccess,
RefreshToken: ca.refreshToken,
AccessToken: ca.accessToken,
RealmID: ca.realmID,
ClientAccess: clientAccess,
RefreshToken: ca.refreshToken,
AccessToken: ca.accessToken,
RealmID: ca.realmID,
PreviousRefreshToken: ca.previousRefreshToken,
UserAccessToken: ca.userAccessToken,
ConsumerSecret: ca.consumerSecret,
ConsumerKey: ca.consumerKey,
OauthToken: ca.oauthToken,
OauthTokenSecret: ca.oauthTokenSecret,
RoleArn: ca.roleArn,
AwsAccessKey: ca.awsAccessKey,
AwsSecretKey: ca.awsSecretKey,
ClientId: ca.clientId,
KeyId: ca.keyId,
TeamId: ca.teamId,
ClientSecret: ca.clientSecret,
}
}

Expand All @@ -59,3 +98,68 @@ func (ca *ConnectorAuth) RealmID(value string) *ConnectorAuth {
ca.realmID = &value
return ca
}

func (ca *ConnectorAuth) PreviousRefreshToken(value string) *ConnectorAuth {
ca.previousRefreshToken = &value
return ca
}

func (ca *ConnectorAuth) UserAccessToken(value string) *ConnectorAuth {
ca.userAccessToken = &value
return ca
}

func (ca *ConnectorAuth) ConsumerSecret(value string) *ConnectorAuth {
ca.consumerSecret = &value
return ca
}

func (ca *ConnectorAuth) ConsumerKey(value string) *ConnectorAuth {
ca.consumerKey = &value
return ca
}

func (ca *ConnectorAuth) OauthToken(value string) *ConnectorAuth {
ca.oauthToken = &value
return ca
}

func (ca *ConnectorAuth) OauthTokenSecret(value string) *ConnectorAuth {
ca.oauthTokenSecret = &value
return ca
}

func (ca *ConnectorAuth) RoleArn(value string) *ConnectorAuth {
ca.roleArn = &value
return ca
}

func (ca *ConnectorAuth) AwsAccessKey(value string) *ConnectorAuth {
ca.awsAccessKey = &value
return ca
}

func (ca *ConnectorAuth) AwsSecretKey(value string) *ConnectorAuth {
ca.awsSecretKey = &value
return ca
}

func (ca *ConnectorAuth) ClientId(value string) *ConnectorAuth {
ca.clientId = &value
return ca
}

func (ca *ConnectorAuth) KeyId(value string) *ConnectorAuth {
ca.keyId = &value
return ca
}

func (ca *ConnectorAuth) TeamId(value string) *ConnectorAuth {
ca.teamId = &value
return ca
}

func (ca *ConnectorAuth) ClientSecret(value string) *ConnectorAuth {
ca.clientSecret = &value
return ca
}
18 changes: 18 additions & 0 deletions destinations/destination_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type DestinationConfig struct {
tenantId *string
clientId *string
secretValue *string
workspaceName *string
lakehouseName *string
}

type destinationConfigRequest struct {
Expand Down Expand Up @@ -78,6 +80,8 @@ type destinationConfigRequest struct {
TenantId *string `json:"tenant_id,omitempty"`
ClientId *string `json:"client_id,omitempty"`
SecretValue *string `json:"secret_value,omitempty"`
WorkspaceName *string `json:"workspace_name,omitempty"`
LakehouseName *string `json:"lakehouse_name,omitempty"`
}

type DestinationConfigResponse struct {
Expand Down Expand Up @@ -119,6 +123,8 @@ type DestinationConfigResponse struct {
TenantId string `json:"tenant_id"`
ClientId string `json:"client_id"`
SecretValue string `json:"secret_value"`
WorkspaceName string `json:"workspace_name"`
LakehouseName string `json:"lakehouse_name"`
}

func (dc *DestinationConfig) Request() *destinationConfigRequest {
Expand Down Expand Up @@ -159,6 +165,8 @@ func (dc *DestinationConfig) Request() *destinationConfigRequest {
TenantId: dc.tenantId,
ClientId: dc.clientId,
SecretValue: dc.secretValue,
WorkspaceName: dc.workspaceName,
LakehouseName: dc.lakehouseName,
}
}

Expand Down Expand Up @@ -345,4 +353,14 @@ func (dc *DestinationConfig) ClientId(value string) *DestinationConfig {
func (dc *DestinationConfig) SecretValue(value string) *DestinationConfig {
dc.secretValue = &value
return dc
}

func (dc *DestinationConfig) WorkspaceName(value string) *DestinationConfig {
dc.workspaceName = &value
return dc
}

func (dc *DestinationConfig) LakehouseName(value string) *DestinationConfig {
dc.lakehouseName = &value
return dc
}
15 changes: 14 additions & 1 deletion examples/connectorCreate-2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ func main() {
connAuth.ClientAccess(connAuthClientAccess).
AccessToken("thisIsAccessToken").
RealmID("thisIsRealmID").
RefreshToken("thisIsRefreshToken")
RefreshToken("thisIsRefreshToken").
PreviousRefreshToken("thisIsPreviousRefreshToken").
UserAccessToken("thisIsUserAccessToken").
ConsumerSecret("thisIsConsumerSecret").
ConsumerKey("thisIsConsumerKey").
OauthToken("thisIsOauthToken").
OauthTokenSecret("thisIsOauthTokenSecret").
RoleArn("thisIsRoleArn").
AwsAccessKey("thisIsAwsAccessKey").
AwsSecretKey("thisIsAwsSecretKey").
ClientId("thisIsClientId").
KeyId("thisIsKeyId").
TeamId("thisIsTeamId").
ClientSecret("thisIsClientSecret")

svc.GroupID("replying_ministry")
svc.Service("google_sheets")
Expand Down
2 changes: 1 addition & 1 deletion examples/destinationCreate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {

svc.GroupID("anyplace_silvery")
svc.Service("snowflake")
svc.Region("US")
svc.Region("GCP_US_EAST4")
svc.TimeZoneOffset("-5")
svc.Config(destConfig)

Expand Down
2 changes: 1 addition & 1 deletion test_utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CreateDbtDestination(t *testing.T) {
destination, err := Client.NewDestinationCreate().
GroupID(PredefinedGroupId).
Service("big_query").
Region("US").
Region("GCP_US_EAST4").
RunSetupTests(true).
TimeZoneOffset("-5").
Config(
Expand Down
14 changes: 13 additions & 1 deletion tests/destination_create_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
TENANT_ID = "tenant_id"
CLIENT_ID = "client_id"
SECRET_VALUE = "secret_value"
WORKSPACE_NAME = "workspace_name"
LAKEHOUSE_NAME = "lakehouse_name"
)

func TestNewDestinationCreateFullMappingMock(t *testing.T) {
Expand Down Expand Up @@ -157,7 +159,9 @@ func prepareDestinationResponse() string {
"container_name": "%v",
"tenant_id": "%v",
"client_id": "%v",
"secret_value": "%v"
"secret_value": "%v",
"workspace_name": "%v",
"lakehouse_name": "%v"
}
}
}`,
Expand Down Expand Up @@ -208,6 +212,8 @@ func prepareDestinationResponse() string {
TENANT_ID,
CLIENT_ID,
SECRET_VALUE,
WORKSPACE_NAME,
LAKEHOUSE_NAME,
)
}

Expand Down Expand Up @@ -248,6 +254,8 @@ func prepareConfig() *destinations.DestinationConfig {
config.TenantId(TENANT_ID)
config.ClientId(CLIENT_ID)
config.SecretValue(SECRET_VALUE)
config.WorkspaceName(WORKSPACE_NAME)
config.LakehouseName(LAKEHOUSE_NAME)

return config
}
Expand Down Expand Up @@ -301,6 +309,8 @@ func assertRequest(t *testing.T, request map[string]interface{}) {
assertKey(t, "tenant_id", config, TENANT_ID)
assertKey(t, "client_id", config, CLIENT_ID)
assertKey(t, "secret_value", config, SECRET_VALUE)
assertKey(t, "workspace_name", config, WORKSPACE_NAME)
assertKey(t, "lakehouse_name", config, LAKEHOUSE_NAME)
}

func assertResponse(t *testing.T, response destinations.DestinationDetailsWithSetupTestsResponse) {
Expand Down Expand Up @@ -358,4 +368,6 @@ func assertResponse(t *testing.T, response destinations.DestinationDetailsWithSe
assertEqual(t, response.Data.Config.TenantId, TENANT_ID)
assertEqual(t, response.Data.Config.ClientId, CLIENT_ID)
assertEqual(t, response.Data.Config.SecretValue, SECRET_VALUE)
assertEqual(t, response.Data.Config.WorkspaceName, WORKSPACE_NAME)
assertEqual(t, response.Data.Config.LakehouseName, LAKEHOUSE_NAME)
}

0 comments on commit 57cb9f5

Please sign in to comment.