/
source_bingads_resource_sdk.go
188 lines (183 loc) · 6.97 KB
/
source_bingads_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package provider
import (
"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/pkg/models/shared"
customTypes "github.com/airbytehq/terraform-provider-airbyte/internal/sdk/pkg/types"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func (r *SourceBingAdsResourceModel) ToSharedSourceBingAdsCreateRequest() *shared.SourceBingAdsCreateRequest {
var accountNames []shared.SourceBingAdsAccountNames = nil
for _, accountNamesItem := range r.Configuration.AccountNames {
name := accountNamesItem.Name.ValueString()
operator := shared.SourceBingAdsOperator(accountNamesItem.Operator.ValueString())
accountNames = append(accountNames, shared.SourceBingAdsAccountNames{
Name: name,
Operator: operator,
})
}
clientID := r.Configuration.ClientID.ValueString()
clientSecret := new(string)
if !r.Configuration.ClientSecret.IsUnknown() && !r.Configuration.ClientSecret.IsNull() {
*clientSecret = r.Configuration.ClientSecret.ValueString()
} else {
clientSecret = nil
}
var customReports []shared.SourceBingAdsCustomReportConfig = nil
for _, customReportsItem := range r.Configuration.CustomReports {
name1 := customReportsItem.Name.ValueString()
reportAggregation := new(string)
if !customReportsItem.ReportAggregation.IsUnknown() && !customReportsItem.ReportAggregation.IsNull() {
*reportAggregation = customReportsItem.ReportAggregation.ValueString()
} else {
reportAggregation = nil
}
var reportColumns []string = nil
for _, reportColumnsItem := range customReportsItem.ReportColumns {
reportColumns = append(reportColumns, reportColumnsItem.ValueString())
}
reportingObject := shared.SourceBingAdsReportingDataObject(customReportsItem.ReportingObject.ValueString())
customReports = append(customReports, shared.SourceBingAdsCustomReportConfig{
Name: name1,
ReportAggregation: reportAggregation,
ReportColumns: reportColumns,
ReportingObject: reportingObject,
})
}
developerToken := r.Configuration.DeveloperToken.ValueString()
lookbackWindow := new(int64)
if !r.Configuration.LookbackWindow.IsUnknown() && !r.Configuration.LookbackWindow.IsNull() {
*lookbackWindow = r.Configuration.LookbackWindow.ValueInt64()
} else {
lookbackWindow = nil
}
refreshToken := r.Configuration.RefreshToken.ValueString()
reportsStartDate := new(customTypes.Date)
if !r.Configuration.ReportsStartDate.IsUnknown() && !r.Configuration.ReportsStartDate.IsNull() {
reportsStartDate = customTypes.MustNewDateFromString(r.Configuration.ReportsStartDate.ValueString())
} else {
reportsStartDate = nil
}
tenantID := new(string)
if !r.Configuration.TenantID.IsUnknown() && !r.Configuration.TenantID.IsNull() {
*tenantID = r.Configuration.TenantID.ValueString()
} else {
tenantID = nil
}
configuration := shared.SourceBingAds{
AccountNames: accountNames,
ClientID: clientID,
ClientSecret: clientSecret,
CustomReports: customReports,
DeveloperToken: developerToken,
LookbackWindow: lookbackWindow,
RefreshToken: refreshToken,
ReportsStartDate: reportsStartDate,
TenantID: tenantID,
}
definitionID := new(string)
if !r.DefinitionID.IsUnknown() && !r.DefinitionID.IsNull() {
*definitionID = r.DefinitionID.ValueString()
} else {
definitionID = nil
}
name2 := 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.SourceBingAdsCreateRequest{
Configuration: configuration,
DefinitionID: definitionID,
Name: name2,
SecretID: secretID,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceBingAdsResourceModel) RefreshFromSharedSourceResponse(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 *SourceBingAdsResourceModel) ToSharedSourceBingAdsPutRequest() *shared.SourceBingAdsPutRequest {
var accountNames []shared.AccountNames = nil
for _, accountNamesItem := range r.Configuration.AccountNames {
name := accountNamesItem.Name.ValueString()
operator := shared.Operator(accountNamesItem.Operator.ValueString())
accountNames = append(accountNames, shared.AccountNames{
Name: name,
Operator: operator,
})
}
clientID := r.Configuration.ClientID.ValueString()
clientSecret := new(string)
if !r.Configuration.ClientSecret.IsUnknown() && !r.Configuration.ClientSecret.IsNull() {
*clientSecret = r.Configuration.ClientSecret.ValueString()
} else {
clientSecret = nil
}
var customReports []shared.CustomReportConfig = nil
for _, customReportsItem := range r.Configuration.CustomReports {
name1 := customReportsItem.Name.ValueString()
reportAggregation := new(string)
if !customReportsItem.ReportAggregation.IsUnknown() && !customReportsItem.ReportAggregation.IsNull() {
*reportAggregation = customReportsItem.ReportAggregation.ValueString()
} else {
reportAggregation = nil
}
var reportColumns []string = nil
for _, reportColumnsItem := range customReportsItem.ReportColumns {
reportColumns = append(reportColumns, reportColumnsItem.ValueString())
}
reportingObject := shared.ReportingDataObject(customReportsItem.ReportingObject.ValueString())
customReports = append(customReports, shared.CustomReportConfig{
Name: name1,
ReportAggregation: reportAggregation,
ReportColumns: reportColumns,
ReportingObject: reportingObject,
})
}
developerToken := r.Configuration.DeveloperToken.ValueString()
lookbackWindow := new(int64)
if !r.Configuration.LookbackWindow.IsUnknown() && !r.Configuration.LookbackWindow.IsNull() {
*lookbackWindow = r.Configuration.LookbackWindow.ValueInt64()
} else {
lookbackWindow = nil
}
refreshToken := r.Configuration.RefreshToken.ValueString()
reportsStartDate := new(customTypes.Date)
if !r.Configuration.ReportsStartDate.IsUnknown() && !r.Configuration.ReportsStartDate.IsNull() {
reportsStartDate = customTypes.MustNewDateFromString(r.Configuration.ReportsStartDate.ValueString())
} else {
reportsStartDate = nil
}
tenantID := new(string)
if !r.Configuration.TenantID.IsUnknown() && !r.Configuration.TenantID.IsNull() {
*tenantID = r.Configuration.TenantID.ValueString()
} else {
tenantID = nil
}
configuration := shared.SourceBingAdsUpdate{
AccountNames: accountNames,
ClientID: clientID,
ClientSecret: clientSecret,
CustomReports: customReports,
DeveloperToken: developerToken,
LookbackWindow: lookbackWindow,
RefreshToken: refreshToken,
ReportsStartDate: reportsStartDate,
TenantID: tenantID,
}
name2 := r.Name.ValueString()
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceBingAdsPutRequest{
Configuration: configuration,
Name: name2,
WorkspaceID: workspaceID,
}
return &out
}