Skip to content

Commit 3fd7526

Browse files
chore: mark sensitive, add tests, add diag check
1 parent bfc2299 commit 3fd7526

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

internal/provider/cached_image_resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func (r *CachedImageResource) Schema(ctx context.Context, req resource.SchemaReq
190190
"git_ssh_private_key_base64": schema.StringAttribute{
191191
MarkdownDescription: "(Envbuilder option) Base64 encoded SSH private key to be used for Git authentication.",
192192
Optional: true,
193+
Sensitive: true,
193194
},
194195
"git_username": schema.StringAttribute{
195196
MarkdownDescription: "(Envbuilder option) The username to use for Git authentication. This is optional.",

internal/provider/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ func optionsFromDataModel(data CachedImageResourceModel) (eboptions.Options, dia
156156
}
157157
diags = append(diags, overrideOptionsFromExtraEnv(&opts, extraEnv, providerOpts)...)
158158

159+
if opts.GitSSHPrivateKeyPath != "" && opts.GitSSHPrivateKeyBase64 != "" {
160+
diags.AddError("Cannot set more than one git ssh private key options",
161+
"Both ENVBUILDER_GIT_SSH_PRIVATE_KEY_PATH and ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64 have been set.")
162+
}
163+
159164
return opts, diags
160165
}
161166

internal/provider/provider_internal_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,59 @@ func Test_optionsFromDataModel(t *testing.T) {
211211
},
212212
expectNumErrorDiags: 2,
213213
},
214+
{
215+
name: "errors when git ssh private key path and base64 are set",
216+
data: CachedImageResourceModel{
217+
BuilderImage: basetypes.NewStringValue("envbuilder:latest"),
218+
CacheRepo: basetypes.NewStringValue("localhost:5000/cache"),
219+
GitURL: basetypes.NewStringValue("[email protected]/devcontainer.git"),
220+
GitSSHPrivateKeyPath: basetypes.NewStringValue("/tmp/id_rsa"),
221+
GitSSHPrivateKeyBase64: basetypes.NewStringValue("cHJpdmF0ZUtleQo="),
222+
},
223+
expectOpts: eboptions.Options{
224+
CacheRepo: "localhost:5000/cache",
225+
GitURL: "[email protected]/devcontainer.git",
226+
RemoteRepoBuildMode: true,
227+
GitSSHPrivateKeyPath: "/tmp/id_rsa",
228+
GitSSHPrivateKeyBase64: "cHJpdmF0ZUtleQo=",
229+
},
230+
expectNumErrorDiags: 1,
231+
},
232+
{
233+
name: "extra_env override errors when git ssh private key path and base64 are set",
234+
data: CachedImageResourceModel{
235+
BuilderImage: basetypes.NewStringValue("envbuilder:latest"),
236+
CacheRepo: basetypes.NewStringValue("localhost:5000/cache"),
237+
GitURL: basetypes.NewStringValue("[email protected]/devcontainer.git"),
238+
GitSSHPrivateKeyBase64: basetypes.NewStringValue("cHJpdmF0ZUtleQo="),
239+
ExtraEnv: extraEnvMap(t,
240+
"ENVBUILDER_GIT_SSH_PRIVATE_KEY_PATH", "/tmp/id_rsa",
241+
),
242+
},
243+
expectOpts: eboptions.Options{
244+
CacheRepo: "localhost:5000/cache",
245+
GitURL: "[email protected]/devcontainer.git",
246+
RemoteRepoBuildMode: true,
247+
GitSSHPrivateKeyPath: "/tmp/id_rsa",
248+
GitSSHPrivateKeyBase64: "cHJpdmF0ZUtleQo=",
249+
},
250+
expectNumErrorDiags: 1,
251+
},
252+
{
253+
name: "required only with base64 ssh key",
254+
data: CachedImageResourceModel{
255+
BuilderImage: basetypes.NewStringValue("envbuilder:latest"),
256+
CacheRepo: basetypes.NewStringValue("localhost:5000/cache"),
257+
GitURL: basetypes.NewStringValue("[email protected]/devcontainer.git"),
258+
GitSSHPrivateKeyBase64: basetypes.NewStringValue("cHJpdmF0ZUtleQo="),
259+
},
260+
expectOpts: eboptions.Options{
261+
CacheRepo: "localhost:5000/cache",
262+
GitURL: "[email protected]/devcontainer.git",
263+
RemoteRepoBuildMode: true,
264+
GitSSHPrivateKeyBase64: "cHJpdmF0ZUtleQo=",
265+
},
266+
},
214267
} {
215268
t.Run(tc.name, func(t *testing.T) {
216269
t.Parallel()

0 commit comments

Comments
 (0)