/
source_googledirectory_resource_sdk.go
123 lines (118 loc) · 4.75 KB
/
source_googledirectory_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
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package provider
import (
"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/pkg/models/shared"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func (r *SourceGoogleDirectoryResourceModel) ToSharedSourceGoogleDirectoryCreateRequest() *shared.SourceGoogleDirectoryCreateRequest {
var credentials *shared.SourceGoogleDirectoryGoogleCredentials
if r.Configuration.Credentials != nil {
var sourceGoogleDirectorySignInViaGoogleOAuth *shared.SourceGoogleDirectorySignInViaGoogleOAuth
if r.Configuration.Credentials.SignInViaGoogleOAuth != nil {
clientID := r.Configuration.Credentials.SignInViaGoogleOAuth.ClientID.ValueString()
clientSecret := r.Configuration.Credentials.SignInViaGoogleOAuth.ClientSecret.ValueString()
refreshToken := r.Configuration.Credentials.SignInViaGoogleOAuth.RefreshToken.ValueString()
sourceGoogleDirectorySignInViaGoogleOAuth = &shared.SourceGoogleDirectorySignInViaGoogleOAuth{
ClientID: clientID,
ClientSecret: clientSecret,
RefreshToken: refreshToken,
}
}
if sourceGoogleDirectorySignInViaGoogleOAuth != nil {
credentials = &shared.SourceGoogleDirectoryGoogleCredentials{
SourceGoogleDirectorySignInViaGoogleOAuth: sourceGoogleDirectorySignInViaGoogleOAuth,
}
}
var sourceGoogleDirectoryServiceAccountKey *shared.SourceGoogleDirectoryServiceAccountKey
if r.Configuration.Credentials.ServiceAccountKey != nil {
credentialsJSON := r.Configuration.Credentials.ServiceAccountKey.CredentialsJSON.ValueString()
email := r.Configuration.Credentials.ServiceAccountKey.Email.ValueString()
sourceGoogleDirectoryServiceAccountKey = &shared.SourceGoogleDirectoryServiceAccountKey{
CredentialsJSON: credentialsJSON,
Email: email,
}
}
if sourceGoogleDirectoryServiceAccountKey != nil {
credentials = &shared.SourceGoogleDirectoryGoogleCredentials{
SourceGoogleDirectoryServiceAccountKey: sourceGoogleDirectoryServiceAccountKey,
}
}
}
configuration := shared.SourceGoogleDirectory{
Credentials: credentials,
}
definitionID := new(string)
if !r.DefinitionID.IsUnknown() && !r.DefinitionID.IsNull() {
*definitionID = r.DefinitionID.ValueString()
} else {
definitionID = nil
}
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.SourceGoogleDirectoryCreateRequest{
Configuration: configuration,
DefinitionID: definitionID,
Name: name,
SecretID: secretID,
WorkspaceID: workspaceID,
}
return &out
}
func (r *SourceGoogleDirectoryResourceModel) 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 *SourceGoogleDirectoryResourceModel) ToSharedSourceGoogleDirectoryPutRequest() *shared.SourceGoogleDirectoryPutRequest {
var credentials *shared.SourceGoogleDirectoryUpdateGoogleCredentials
if r.Configuration.Credentials != nil {
var signInViaGoogleOAuth *shared.SignInViaGoogleOAuth
if r.Configuration.Credentials.SignInViaGoogleOAuth != nil {
clientID := r.Configuration.Credentials.SignInViaGoogleOAuth.ClientID.ValueString()
clientSecret := r.Configuration.Credentials.SignInViaGoogleOAuth.ClientSecret.ValueString()
refreshToken := r.Configuration.Credentials.SignInViaGoogleOAuth.RefreshToken.ValueString()
signInViaGoogleOAuth = &shared.SignInViaGoogleOAuth{
ClientID: clientID,
ClientSecret: clientSecret,
RefreshToken: refreshToken,
}
}
if signInViaGoogleOAuth != nil {
credentials = &shared.SourceGoogleDirectoryUpdateGoogleCredentials{
SignInViaGoogleOAuth: signInViaGoogleOAuth,
}
}
var serviceAccountKey *shared.ServiceAccountKey
if r.Configuration.Credentials.ServiceAccountKey != nil {
credentialsJSON := r.Configuration.Credentials.ServiceAccountKey.CredentialsJSON.ValueString()
email := r.Configuration.Credentials.ServiceAccountKey.Email.ValueString()
serviceAccountKey = &shared.ServiceAccountKey{
CredentialsJSON: credentialsJSON,
Email: email,
}
}
if serviceAccountKey != nil {
credentials = &shared.SourceGoogleDirectoryUpdateGoogleCredentials{
ServiceAccountKey: serviceAccountKey,
}
}
}
configuration := shared.SourceGoogleDirectoryUpdate{
Credentials: credentials,
}
name := r.Name.ValueString()
workspaceID := r.WorkspaceID.ValueString()
out := shared.SourceGoogleDirectoryPutRequest{
Configuration: configuration,
Name: name,
WorkspaceID: workspaceID,
}
return &out
}