@@ -6,21 +6,18 @@ SPDX-License-Identifier: MPL-2.0
6
6
package spec
7
7
8
8
import (
9
- "context"
10
9
"encoding/base64"
11
10
"encoding/json"
12
11
"fmt"
13
12
14
- "github.com/hashicorp/terraform-plugin-log/tflog"
15
-
16
13
"github.com/go-openapi/strfmt"
17
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18
15
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
19
16
20
17
secretmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/kubernetessecret/cluster"
21
18
)
22
19
23
- func ConstructSpecForClusterScope (ctx context. Context , d * schema.ResourceData ) (spec * secretmodel.VmwareTanzuManageV1alpha1ClusterNamespaceSecretSpec ) {
20
+ func ConstructSpecForClusterScope (d * schema.ResourceData ) (spec * secretmodel.VmwareTanzuManageV1alpha1ClusterNamespaceSecretSpec ) {
24
21
spec = & secretmodel.VmwareTanzuManageV1alpha1ClusterNamespaceSecretSpec {}
25
22
26
23
value , ok := d .GetOk (SpecKey )
@@ -68,25 +65,21 @@ func ConstructSpecForClusterScope(ctx context.Context, d *schema.ResourceData) (
68
65
}
69
66
70
67
if v , ok := specData [OpaqueKey ]; ok {
71
- tflog .Info (ctx , "MAde it to opaque" )
72
68
73
69
opaqueData := common .GetTypeStringMapData (v .(map [string ]interface {}))
74
70
if len (opaqueData ) != 0 {
75
71
spec .SecretType = secretmodel .NewVmwareTanzuManageV1alpha1ClusterNamespaceSecretType (secretmodel .VmwareTanzuManageV1alpha1ClusterNamespaceSecretTypeSECRETTYPEOPAQUE )
76
- tflog .Info (ctx , fmt .Sprintf ("testing %v" , opaqueData ))
77
72
78
- encodedData := getEncodedOpaqueData (ctx , opaqueData )
79
- tflog .Info (ctx , fmt .Sprintf ("%v" , encodedData ))
73
+ encodedData := getEncodedOpaqueData (opaqueData )
80
74
spec .Data = encodedData
81
75
}
82
76
83
77
}
84
78
85
- tflog .Info (ctx , "returning" )
86
79
return spec
87
80
}
88
81
89
- func FlattenSpecForClusterScope (ctx context. Context , spec * secretmodel.VmwareTanzuManageV1alpha1ClusterNamespaceSecretSpec , pass string ) (data []interface {}) {
82
+ func FlattenSpecForClusterScope (spec * secretmodel.VmwareTanzuManageV1alpha1ClusterNamespaceSecretSpec , pass string , opaqueData map [ string ] interface {} ) (data []interface {}) {
90
83
if spec == nil {
91
84
return data
92
85
}
@@ -126,15 +119,8 @@ func FlattenSpecForClusterScope(ctx context.Context, spec *secretmodel.VmwareTan
126
119
}
127
120
128
121
if * spec .SecretType == * secretmodel .NewVmwareTanzuManageV1alpha1ClusterNamespaceSecretType (secretmodel .VmwareTanzuManageV1alpha1ClusterNamespaceSecretTypeSECRETTYPEOPAQUE ) {
129
- tflog .Info (ctx , "secret type opaque" )
130
- secretData := spec .Data
131
- decodedData , err := getDecodedOpaqueData (secretData )
132
- if err != nil {
133
- return data
134
- }
135
- tflog .Info (ctx , fmt .Sprintf ("%v" , decodedData ))
136
122
137
- flattenSpecData [OpaqueKey ] = [] interface {}{ decodedData }
123
+ flattenSpecData [OpaqueKey ] = opaqueData
138
124
}
139
125
140
126
return []interface {}{flattenSpecData }
@@ -169,27 +155,25 @@ func getDecodedSpecData(data strfmt.Base64) (*dockerConfigJSON, error) {
169
155
return dockerConfigJSON , nil
170
156
}
171
157
172
- func getEncodedOpaqueData (ctx context. Context , data map [string ]string ) map [string ]strfmt.Base64 {
158
+ func getEncodedOpaqueData (data map [string ]string ) map [string ]strfmt.Base64 {
173
159
encoded := make (map [string ]strfmt.Base64 )
174
160
175
161
for k , v := range data {
176
- tflog .Info (ctx , v )
177
162
encoded [k ] = strfmt .Base64 (v )
178
- tflog .Info (ctx , string (encoded [k ]))
179
163
}
180
164
181
165
return encoded
182
166
}
183
167
184
- func getDecodedOpaqueData (data map [string ]strfmt.Base64 ) (map [string ]string , error ) {
185
- decoded := make (map [string ]string )
186
- for k , v := range data {
187
- decodedValue , err := base64 .StdEncoding .DecodeString (v .String ())
188
- if err != nil {
189
- return nil , err
190
- }
191
- decoded [k ] = string (decodedValue )
192
- }
193
-
194
- return decoded , nil
195
- }
168
+ // func getDecodedOpaqueData(data map[string]strfmt.Base64) (map[string]string, error) {
169
+ // decoded := make(map[string]string)
170
+ // for k, v := range data {
171
+ // decodedValue, err := base64.StdEncoding.DecodeString(v.String())
172
+ // if err != nil {
173
+ // return nil, err
174
+ // }
175
+ // decoded[k] = string(decodedValue)
176
+ // }
177
+
178
+ // return decoded, nil
179
+ // }
0 commit comments