Skip to content

Commit 5d65e33

Browse files
committed
feat: Allow passing API key directly from memory
1 parent 84dfbde commit 5d65e33

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

.web-docs/components/builder/oci/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ based on which authentication method is used.
101101
- `use_instance_principals` (boolean) - Whether to use [Instance
102102
Principals](https://docs.cloud.oracle.com/en-us/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm)
103103
instead of User Principals. If this key is set to true, setting any one of the `access_cfg_file`,
104-
`access_cfg_file_account`, `region`, `tenancy_ocid`, `user_ocid`, `key_file`, `fingerprint`,
104+
`access_cfg_file_account`, `region`, `tenancy_ocid`, `user_ocid`, `key`, `key_file`, `fingerprint`,
105105
`pass_phrase` parameters will cause an invalid configuration error.
106106
Defaults to `false`.
107107

@@ -135,6 +135,9 @@ or configured for the default OCI CLI authenticaton profile.
135135
[OCI config file](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm)
136136
if present. This cannot be used along with the `use_instance_principals` key.
137137

138+
- `key` (string) - The contents of the OCI API signing key. Overrides value provided by the `key_file`.
139+
This cannot be used along with the `use_instance_principals` key.
140+
138141
- `key_file` (string) - Full path and filename of the OCI API signing key. Overrides value provided
139142
by the [OCI config file](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm)
140143
if present. This cannot be used along with the `use_instance_principals` key.

builder/oci/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type Config struct {
9191
TenancyID string `mapstructure:"tenancy_ocid"`
9292
Region string `mapstructure:"region"`
9393
Fingerprint string `mapstructure:"fingerprint"`
94+
Key string `mapstructure:"key"`
9495
KeyFile string `mapstructure:"key_file"`
9596
PassPhrase string `mapstructure:"pass_phrase"`
9697
UsePrivateIP bool `mapstructure:"use_private_ip"`
@@ -211,6 +212,9 @@ func (c *Config) Prepare(raws ...interface{}) error {
211212
if c.Fingerprint != "" {
212213
errs = packersdk.MultiErrorAppend(errs, errors.New("fingerprint"+message))
213214
}
215+
if c.Key != "" {
216+
errs = packersdk.MultiErrorAppend(errs, errors.New("key"+message))
217+
}
214218
if c.KeyFile != "" {
215219
errs = packersdk.MultiErrorAppend(errs, errors.New("key_file"+message))
216220
}
@@ -246,6 +250,7 @@ func (c *Config) Prepare(raws ...interface{}) error {
246250
c.AccessCfgFileAccount = "DEFAULT"
247251
}
248252

253+
// Read API signing key
249254
var keyContent []byte
250255
if c.KeyFile != "" {
251256
path, err := pathing.ExpandUser(c.KeyFile)
@@ -259,7 +264,11 @@ func (c *Config) Prepare(raws ...interface{}) error {
259264
return err
260265
}
261266
}
267+
if c.Key != "" {
268+
keyContent = []byte(c.Key)
269+
}
262270

271+
// Providers
263272
fileProvider, _ := ocicommon.ConfigurationProviderFromFileWithProfile(c.AccessCfgFile, c.AccessCfgFileAccount, c.PassPhrase)
264273
if c.Region == "" {
265274
var region string

builder/oci/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/oci/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ func TestConfig(t *testing.T) {
398398
"tenancy_ocid",
399399
"region",
400400
"fingerprint",
401+
"key",
401402
"key_file",
402403
"pass_phrase",
403404
}

docs/builders/oci.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ based on which authentication method is used.
108108
- `use_instance_principals` (boolean) - Whether to use [Instance
109109
Principals](https://docs.cloud.oracle.com/en-us/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm)
110110
instead of User Principals. If this key is set to true, setting any one of the `access_cfg_file`,
111-
`access_cfg_file_account`, `region`, `tenancy_ocid`, `user_ocid`, `key_file`, `fingerprint`,
111+
`access_cfg_file_account`, `region`, `tenancy_ocid`, `user_ocid`, `key`, `key_file`, `fingerprint`,
112112
`pass_phrase` parameters will cause an invalid configuration error.
113113
Defaults to `false`.
114114

@@ -142,6 +142,9 @@ or configured for the default OCI CLI authenticaton profile.
142142
[OCI config file](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm)
143143
if present. This cannot be used along with the `use_instance_principals` key.
144144

145+
- `key` (string) - The contents of the OCI API signing key. Overrides value provided by the `key_file`.
146+
This cannot be used along with the `use_instance_principals` key.
147+
145148
- `key_file` (string) - Full path and filename of the OCI API signing key. Overrides value provided
146149
by the [OCI config file](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm)
147150
if present. This cannot be used along with the `use_instance_principals` key.

0 commit comments

Comments
 (0)