forked from airbytehq/terraform-provider-airbyte
/
source_hubspot_resource_sdk.go
executable file
·137 lines (129 loc) · 6.01 KB
/
source_hubspot_resource_sdk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package provider
import (
"github.com/ryan-pip/terraform-provider-airbyte/internal/sdk/pkg/models/shared"
"github.com/hashicorp/terraform-plugin-framework/types"
"time"
)
func (r *SourceHubspotResourceModel) ToCreateSDKType() *shared.SourceHubspotCreateRequest {
var credentials shared.SourceHubspotAuthentication
var sourceHubspotAuthenticationOAuth *shared.SourceHubspotAuthenticationOAuth
if r.Configuration.Credentials.SourceHubspotAuthenticationOAuth != nil {
clientID := r.Configuration.Credentials.SourceHubspotAuthenticationOAuth.ClientID.ValueString()
clientSecret := r.Configuration.Credentials.SourceHubspotAuthenticationOAuth.ClientSecret.ValueString()
credentialsTitle := shared.SourceHubspotAuthenticationOAuthAuthType(r.Configuration.Credentials.SourceHubspotAuthenticationOAuth.CredentialsTitle.ValueString())
refreshToken := r.Configuration.Credentials.SourceHubspotAuthenticationOAuth.RefreshToken.ValueString()
sourceHubspotAuthenticationOAuth = &shared.SourceHubspotAuthenticationOAuth{
ClientID: clientID,
ClientSecret: clientSecret,
CredentialsTitle: credentialsTitle,
RefreshToken: refreshToken,
}
}
if sourceHubspotAuthenticationOAuth != nil {
credentials = shared.SourceHubspotAuthentication{
SourceHubspotAuthenticationOAuth: sourceHubspotAuthenticationOAuth,
}
}
var sourceHubspotAuthenticationPrivateApp *shared.SourceHubspotAuthenticationPrivateApp
if r.Configuration.Credentials.SourceHubspotAuthenticationPrivateApp != nil {
accessToken := r.Configuration.Credentials.SourceHubspotAuthenticationPrivateApp.AccessToken.ValueString()
credentialsTitle1 := shared.SourceHubspotAuthenticationPrivateAppAuthType(r.Configuration.Credentials.SourceHubspotAuthenticationPrivateApp.CredentialsTitle.ValueString())
sourceHubspotAuthenticationPrivateApp = &shared.SourceHubspotAuthenticationPrivateApp{
AccessToken: accessToken,
CredentialsTitle: credentialsTitle1,
}
}
if sourceHubspotAuthenticationPrivateApp != nil {
credentials = shared.SourceHubspotAuthentication{
SourceHubspotAuthenticationPrivateApp: sourceHubspotAuthenticationPrivateApp,
}
}
sourceType := shared.SourceHubspotHubspot(r.Configuration.SourceType.ValueString())
startDate, _ := time.Parse(time.RFC3339Nano, r.Configuration.StartDate.ValueString())
configuration := shared.SourceHubspot{
Credentials: credentials,
SourceType: sourceType,
StartDate: startDate,
}
name := r.Name.ValueString()
secretID := new(string)
if !r.SecretID.IsUnknown() && !r.SecretID.IsNull() {
*secretID = r.SecretID.ValueString()
} else {
secretID = nil
}
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceHubspotCreateRequest{
Configuration: configuration,
Name: name,
SecretID: secretID,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceHubspotResourceModel) ToGetSDKType() *shared.SourceHubspotCreateRequest {
out := r.ToCreateSDKType()
return out
}
func (r *SourceHubspotResourceModel) ToUpdateSDKType() *shared.SourceHubspotPutRequest {
var credentials shared.SourceHubspotUpdateAuthentication
var sourceHubspotUpdateAuthenticationOAuth *shared.SourceHubspotUpdateAuthenticationOAuth
if r.Configuration.Credentials.SourceHubspotUpdateAuthenticationOAuth != nil {
clientID := r.Configuration.Credentials.SourceHubspotUpdateAuthenticationOAuth.ClientID.ValueString()
clientSecret := r.Configuration.Credentials.SourceHubspotUpdateAuthenticationOAuth.ClientSecret.ValueString()
credentialsTitle := shared.SourceHubspotUpdateAuthenticationOAuthAuthType(r.Configuration.Credentials.SourceHubspotUpdateAuthenticationOAuth.CredentialsTitle.ValueString())
refreshToken := r.Configuration.Credentials.SourceHubspotUpdateAuthenticationOAuth.RefreshToken.ValueString()
sourceHubspotUpdateAuthenticationOAuth = &shared.SourceHubspotUpdateAuthenticationOAuth{
ClientID: clientID,
ClientSecret: clientSecret,
CredentialsTitle: credentialsTitle,
RefreshToken: refreshToken,
}
}
if sourceHubspotUpdateAuthenticationOAuth != nil {
credentials = shared.SourceHubspotUpdateAuthentication{
SourceHubspotUpdateAuthenticationOAuth: sourceHubspotUpdateAuthenticationOAuth,
}
}
var sourceHubspotUpdateAuthenticationPrivateApp *shared.SourceHubspotUpdateAuthenticationPrivateApp
if r.Configuration.Credentials.SourceHubspotUpdateAuthenticationPrivateApp != nil {
accessToken := r.Configuration.Credentials.SourceHubspotUpdateAuthenticationPrivateApp.AccessToken.ValueString()
credentialsTitle1 := shared.SourceHubspotUpdateAuthenticationPrivateAppAuthType(r.Configuration.Credentials.SourceHubspotUpdateAuthenticationPrivateApp.CredentialsTitle.ValueString())
sourceHubspotUpdateAuthenticationPrivateApp = &shared.SourceHubspotUpdateAuthenticationPrivateApp{
AccessToken: accessToken,
CredentialsTitle: credentialsTitle1,
}
}
if sourceHubspotUpdateAuthenticationPrivateApp != nil {
credentials = shared.SourceHubspotUpdateAuthentication{
SourceHubspotUpdateAuthenticationPrivateApp: sourceHubspotUpdateAuthenticationPrivateApp,
}
}
startDate, _ := time.Parse(time.RFC3339Nano, r.Configuration.StartDate.ValueString())
configuration := shared.SourceHubspotUpdate{
Credentials: credentials,
StartDate: startDate,
}
name := r.Name.ValueString()
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceHubspotPutRequest{
Configuration: configuration,
Name: name,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceHubspotResourceModel) ToDeleteSDKType() *shared.SourceHubspotCreateRequest {
out := r.ToCreateSDKType()
return out
}
func (r *SourceHubspotResourceModel) RefreshFromGetResponse(resp *shared.SourceResponse) {
r.Name = types.StringValue(resp.Name)
r.SourceID = types.StringValue(resp.SourceID)
r.SourceType = types.StringValue(resp.SourceType)
r.WorkspaceID = types.StringValue(resp.WorkspaceID)
}
func (r *SourceHubspotResourceModel) RefreshFromCreateResponse(resp *shared.SourceResponse) {
r.RefreshFromGetResponse(resp)
}