kitchen-oci 1.28.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kitchen/driver/oci/instance/compute.rb +0 -7
- data/lib/kitchen/driver/oci/instance/dbaas.rb +1 -1
- data/lib/kitchen/driver/oci/instance.rb +2 -53
- data/lib/kitchen/driver/oci/mixin/actions.rb +43 -0
- data/lib/kitchen/driver/oci/mixin/ssh_keys.rb +212 -0
- data/lib/kitchen/driver/oci/models/compute.rb +1 -12
- data/lib/kitchen/driver/oci/models/dbaas.rb +0 -11
- data/lib/kitchen/driver/oci/validations.rb +65 -0
- data/lib/kitchen/driver/oci.rb +6 -39
- data/lib/kitchen/driver/oci_version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106a6d1ccf47752842daaddc79bc644b71bb5ff27da42f1bf30e4271aa2fb946
|
4
|
+
data.tar.gz: 50d21fcc7ab88eb9af0546f3d97c62798621967b96c3190b5ceceee3548c1923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbd4b274c32c38bdb2203fc53ca2218aad402c917c969343bfe05d27436d13be6195399469b30163c3127fe343f4f43d29a6fe2b87f20f233f639dc5b5a0c20c
|
7
|
+
data.tar.gz: 4405307075b1181534c5f55630fd48b76f05ec0c920b8366049c57c71ec4be2e264956a70b274490e1c3b3dc5de38f81f59c739b7526e213ef67bedb5746c77f
|
@@ -81,13 +81,6 @@ module Kitchen
|
|
81
81
|
)
|
82
82
|
end
|
83
83
|
|
84
|
-
# Adds the instance options property to the launch details.
|
85
|
-
def instance_options
|
86
|
-
return if config[:instance_options].empty?
|
87
|
-
|
88
|
-
launch_details.instance_options = OCI::Core::Models::InstanceOptions.new(config[:instance_options])
|
89
|
-
end
|
90
|
-
|
91
84
|
# Adds the source_details property to the launch_details for an instance that is being created from a boot volume.
|
92
85
|
def instance_source_via_boot_volume
|
93
86
|
return unless config[:boot_volume_id]
|
@@ -28,8 +28,10 @@ module Kitchen
|
|
28
28
|
require_relative "models/compute"
|
29
29
|
require_relative "models/dbaas"
|
30
30
|
require_relative "instance/common"
|
31
|
+
require_relative "mixin/ssh_keys"
|
31
32
|
|
32
33
|
include CommonLaunchDetails
|
34
|
+
include Mixin::SshKeys
|
33
35
|
|
34
36
|
def initialize(opts = {})
|
35
37
|
super()
|
@@ -97,59 +99,6 @@ module Kitchen
|
|
97
99
|
!subnet.prohibit_public_ip_on_vnic
|
98
100
|
end
|
99
101
|
|
100
|
-
# Returns the location of the public ssh key.
|
101
|
-
#
|
102
|
-
# @return [String]
|
103
|
-
def public_key_file
|
104
|
-
if config[:ssh_keygen]
|
105
|
-
"#{config[:kitchen_root]}/.kitchen/.ssh/#{config[:instance_name]}_rsa.pub"
|
106
|
-
else
|
107
|
-
config[:ssh_keypath]
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Returns the name of the private key file.
|
112
|
-
#
|
113
|
-
# @return [String]
|
114
|
-
def private_key_file
|
115
|
-
public_key_file.gsub(".pub", "")
|
116
|
-
end
|
117
|
-
|
118
|
-
# Generates an RSA key pair to be used to SSH to the instance and updates the state with the full path to the private key.
|
119
|
-
def gen_key_pair
|
120
|
-
FileUtils.mkdir_p("#{config[:kitchen_root]}/.kitchen/.ssh")
|
121
|
-
rsa_key = OpenSSL::PKey::RSA.new(4096)
|
122
|
-
write_private_key(rsa_key)
|
123
|
-
write_public_key(rsa_key)
|
124
|
-
state.store(:ssh_key, private_key_file)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Writes the private key.
|
128
|
-
#
|
129
|
-
# @param rsa_key [OpenSSL::PKey::RSA] the generated RSA key.
|
130
|
-
def write_private_key(rsa_key)
|
131
|
-
File.open(private_key_file, "wb") { |k| k.write(rsa_key.to_pem) }
|
132
|
-
File.chmod(0600, private_key_file)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Writes the encoded private key as a public key.
|
136
|
-
#
|
137
|
-
# @param rsa_key [OpenSSL::PKey::RSA] the generated RSA key.
|
138
|
-
def write_public_key(rsa_key)
|
139
|
-
File.open(public_key_file, "wb") { |k| k.write("ssh-rsa #{encode_private_key(rsa_key)} #{config[:instance_name]}") }
|
140
|
-
File.chmod(0600, public_key_file)
|
141
|
-
end
|
142
|
-
|
143
|
-
# Encodes the private key.
|
144
|
-
#
|
145
|
-
# @param rsa_key [OpenSSL::PKey::RSA] the generated RSA key.
|
146
|
-
def encode_private_key(rsa_key)
|
147
|
-
prefix = "#{[7].pack("N")}ssh-rsa"
|
148
|
-
exponent = rsa_key.e.to_s(0)
|
149
|
-
modulus = rsa_key.n.to_s(0)
|
150
|
-
["#{prefix}#{exponent}#{modulus}"].pack("m0")
|
151
|
-
end
|
152
|
-
|
153
102
|
# Generates a random password.
|
154
103
|
#
|
155
104
|
# @param special_chars [Array] an array of special characters to include in the random password.
|
@@ -25,6 +25,17 @@ module Kitchen
|
|
25
25
|
#
|
26
26
|
# @author Justin Steele <justin.steele@oracle.com>
|
27
27
|
module Actions
|
28
|
+
# Creates the OCI config and API clients.
|
29
|
+
#
|
30
|
+
# @param action [Symbol] the name of the method that called this method.
|
31
|
+
# @return [Oci::Config, Oci::Api]
|
32
|
+
def auth(action)
|
33
|
+
oci = Oci::Config.new(config)
|
34
|
+
api = Oci::Api.new(oci.config, config)
|
35
|
+
oci.compartment if action == :create
|
36
|
+
[oci, api]
|
37
|
+
end
|
38
|
+
|
28
39
|
# Launches an instance.
|
29
40
|
#
|
30
41
|
# @param state [Hash] (see Kitchen::StateFile)
|
@@ -33,6 +44,8 @@ module Kitchen
|
|
33
44
|
state_details = inst.launch
|
34
45
|
state.merge!(state_details)
|
35
46
|
instance.transport.connection(state).wait_until_ready
|
47
|
+
instance_options(state, inst)
|
48
|
+
are_legacy_imds_endpoints_disbled?(state, inst)
|
36
49
|
end
|
37
50
|
|
38
51
|
# Executes the post script on the instance.
|
@@ -68,6 +81,36 @@ module Kitchen
|
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
84
|
+
# Applies instance options.
|
85
|
+
#
|
86
|
+
# @param state [Hash] (see Kitchen::StateFile)
|
87
|
+
# @param inst [Class] the specific class of instance being rebooted.
|
88
|
+
def instance_options(state, inst)
|
89
|
+
return unless instance_options?
|
90
|
+
|
91
|
+
inst.logger.info("Applying the following instance options:")
|
92
|
+
config[:instance_options].each { |o, v| inst.logger.info("- #{o}: #{v}") }
|
93
|
+
inst.api.compute.update_instance(state[:server_id], OCI::Core::Models::UpdateInstanceDetails.new(instance_options: OCI::Core::Models::InstanceOptions.new(config[:instance_options])))
|
94
|
+
end
|
95
|
+
|
96
|
+
# Attempts to disable IMDSv1 even if not explicitly specified in the config. This is in line with current security guidance from OCI.
|
97
|
+
# Acts as a guard for setting instance options.
|
98
|
+
def instance_options?
|
99
|
+
return false unless config[:instance_type] == "compute"
|
100
|
+
|
101
|
+
config[:instance_options].merge!(are_legacy_imds_endpoints_disabled: true) unless config[:instance_options].key?(:are_legacy_imds_endpoints_disabled)
|
102
|
+
# Basically tell me if there's more stuff in there than `are_legacy_imds_endpoints_disabled: false`. If so, then proceed to setting it.
|
103
|
+
config[:instance_options].reject { |o, v| o == :are_legacy_imds_endpoints_disabled && !v }.any?
|
104
|
+
end
|
105
|
+
|
106
|
+
# Checks if legacy metadata is disabled.
|
107
|
+
def are_legacy_imds_endpoints_disbled?(state, inst)
|
108
|
+
return unless config[:instance_type] == "compute"
|
109
|
+
|
110
|
+
imds = inst.api.compute.get_instance(state[:server_id]).data.instance_options.are_legacy_imds_endpoints_disabled
|
111
|
+
inst.logger.warn("Legacy IMDSv1 endpoint is enabled.") unless imds
|
112
|
+
end
|
113
|
+
|
71
114
|
# Reboots an instance.
|
72
115
|
#
|
73
116
|
# @param state [Hash] (see Kitchen::StateFile)
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Justin Steele (<justin.steele@oracle.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2025, Stephen Pearson
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Driver
|
22
|
+
class Oci
|
23
|
+
module Mixin
|
24
|
+
# SSH key generation mixins.
|
25
|
+
#
|
26
|
+
# @author Justin Steele <justin.steele@oracle.com>
|
27
|
+
module SshKeys
|
28
|
+
# Read in the public ssh key.
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def read_public_key
|
32
|
+
if config[:ssh_keygen]
|
33
|
+
logger.info("Generating public/private #{config[:ssh_keytype]} key pair")
|
34
|
+
generate_keys
|
35
|
+
end
|
36
|
+
File.readlines(public_key_file).first.chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
# The location of the private ssh key.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
def private_key_file
|
43
|
+
public_key_file.gsub(".pub", "")
|
44
|
+
end
|
45
|
+
|
46
|
+
# The location of the public ssh key.
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
def public_key_file
|
50
|
+
if config[:ssh_keygen]
|
51
|
+
"#{config[:kitchen_root]}/.kitchen/.ssh/#{config[:instance_name]}_#{config[:ssh_keytype]}.pub"
|
52
|
+
else
|
53
|
+
config[:ssh_keypath]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Algorithm used when encoding the private and public keys.
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
def algorithm
|
61
|
+
"ssh-#{config[:ssh_keytype]}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Generates the public/private key pair in the format specified in the config.
|
65
|
+
def generate_keys
|
66
|
+
FileUtils.mkdir_p("#{config[:kitchen_root]}/.kitchen/.ssh")
|
67
|
+
extend SshKeys.const_get(config[:ssh_keytype].upcase)
|
68
|
+
generate_key_pair
|
69
|
+
end
|
70
|
+
|
71
|
+
# Mixins required to generate a RSA key pair.
|
72
|
+
#
|
73
|
+
# @author Justin Steele <justin.steele@oracle.com>
|
74
|
+
module RSA
|
75
|
+
# Generates an RSA key pair to be used to SSH to the instance and updates the state with the full path to the private key.
|
76
|
+
def generate_key_pair
|
77
|
+
rsa_key = OpenSSL::PKey::RSA.new(4096)
|
78
|
+
write_private_key(rsa_key)
|
79
|
+
write_public_key(rsa_key)
|
80
|
+
state.store(:ssh_key, private_key_file)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Writes the private key.
|
84
|
+
#
|
85
|
+
# @param rsa_key [OpenSSL::PKey::RSA] the generated RSA key.
|
86
|
+
def write_private_key(rsa_key)
|
87
|
+
File.open(private_key_file, "wb") { |k| k.write(rsa_key.to_pem) }
|
88
|
+
File.chmod(0600, private_key_file)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Writes the encoded private key as a public key.
|
92
|
+
#
|
93
|
+
# @param rsa_key [OpenSSL::PKey::RSA] the generated RSA key.
|
94
|
+
def write_public_key(rsa_key)
|
95
|
+
public_key = ["#{[7].pack("N")}#{algorithm}#{rsa_key.e.to_s(0)}#{rsa_key.n.to_s(0)}"].pack("m0")
|
96
|
+
File.open(public_key_file, "wb") { |k| k.write("#{algorithm} #{public_key} #{config[:instance_name]}") }
|
97
|
+
File.chmod(0600, public_key_file)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Mixins required to generate a ED25519 key pair.
|
102
|
+
#
|
103
|
+
# @author Justin Steele <justin.steele@oracle.com>
|
104
|
+
module ED25519
|
105
|
+
require "ed25519"
|
106
|
+
require "securerandom" unless defined?(SecureRandom)
|
107
|
+
|
108
|
+
# Generates an ED25519 key pair to be used to SSH to the instance and updates the state with the full path to the private key.
|
109
|
+
def generate_key_pair
|
110
|
+
signing_key = Ed25519::SigningKey.generate
|
111
|
+
private_seed = signing_key.to_bytes
|
112
|
+
public_key = signing_key.verify_key.to_bytes
|
113
|
+
write_private_key(public_key, private_seed)
|
114
|
+
write_public_key(public_key)
|
115
|
+
state.store(:ssh_key, private_key_file)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Packs a string as SSH “string” (4-byte len + bytes).
|
119
|
+
#
|
120
|
+
# @param str [String] the portion of the key being packed.
|
121
|
+
# @return [String]
|
122
|
+
def pack_string(str)
|
123
|
+
[str.bytesize].pack("N") + str
|
124
|
+
end
|
125
|
+
|
126
|
+
# Writes the encoded private key.
|
127
|
+
#
|
128
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
129
|
+
# @param private_seed [String] the byte representation of the <code>Ed25519::SigningKey</code>.
|
130
|
+
def write_private_key(public_key, private_seed)
|
131
|
+
private_key = encode_private_key(public_key, private_seed)
|
132
|
+
File.open(private_key_file, "w") { |f| f.write(private_key) }
|
133
|
+
File.chmod(0600, private_key_file)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Writes the encoded public key.
|
137
|
+
#
|
138
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
139
|
+
def write_public_key(public_key)
|
140
|
+
pub_key = encode_public_key(public_key)
|
141
|
+
File.open(public_key_file, "w") { |f| f.write(pub_key) }
|
142
|
+
File.chmod(0600, public_key_file)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Encodes the private key.
|
146
|
+
#
|
147
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
148
|
+
# @param private_seed [String] the byte representation of the <code>Ed25519::SigningKey</code>.
|
149
|
+
# @return [String]
|
150
|
+
def encode_private_key(public_key, private_seed)
|
151
|
+
buf = header(public_key)
|
152
|
+
priv = private_section(public_key, private_seed)
|
153
|
+
padlen = (-priv.bytesize) & 7
|
154
|
+
priv << (1..padlen).to_a.pack("C*")
|
155
|
+
buf << pack_string(priv)
|
156
|
+
b64 = Base64.strict_encode64(buf).scan(/.{1,70}/).join("\n")
|
157
|
+
"-----BEGIN OPENSSH PRIVATE KEY-----\n#{b64}\n-----END OPENSSH PRIVATE KEY-----\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
# "openssh-key-v1" header: magic, cipher/kdf, nkeys, and the public key blob(s).
|
161
|
+
#
|
162
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
163
|
+
# @return [String]
|
164
|
+
def header(public_key)
|
165
|
+
[
|
166
|
+
"openssh-key-v1\0",
|
167
|
+
pack_string("none"), # ciphername
|
168
|
+
pack_string("none"), # kdfname
|
169
|
+
pack_string(""), # kdfoptions
|
170
|
+
[1].pack("N"), # nkeys
|
171
|
+
pack_string(pub_blob(public_key)),
|
172
|
+
].join
|
173
|
+
end
|
174
|
+
|
175
|
+
# Correct private section: checkints, key fields, comment, padding
|
176
|
+
#
|
177
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
178
|
+
# @param private_seed [String] the byte representation of the <code>Ed25519::SigningKey</code>.
|
179
|
+
# @return [String]
|
180
|
+
def private_section(public_key, private_seed)
|
181
|
+
checkint = SecureRandom.random_number(2**32)
|
182
|
+
[
|
183
|
+
[checkint, checkint].pack("N*"),
|
184
|
+
pack_string(algorithm),
|
185
|
+
pack_string(public_key),
|
186
|
+
pack_string(private_seed + public_key),
|
187
|
+
pack_string(config[:instance_name] || ""),
|
188
|
+
].join
|
189
|
+
end
|
190
|
+
|
191
|
+
# Encodes the public key.
|
192
|
+
#
|
193
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
194
|
+
# @return [String]
|
195
|
+
def encode_public_key(public_key)
|
196
|
+
blob = [algorithm.bytesize].pack("N") + algorithm + [public_key.bytesize].pack("N") + public_key
|
197
|
+
[algorithm, Base64.strict_encode64(blob), config[:instance_name]].compact.join(" ")
|
198
|
+
end
|
199
|
+
|
200
|
+
# SSH public key blob: string keytype + string key (32 bytes).
|
201
|
+
#
|
202
|
+
# @param public_key [String] the byte representation of the <code>Ed25519::VerifyKey</code>.
|
203
|
+
# @return [String]
|
204
|
+
def pub_blob(public_key)
|
205
|
+
pack_string(algorithm) + pack_string(public_key)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -210,23 +210,12 @@ module Kitchen
|
|
210
210
|
)
|
211
211
|
end
|
212
212
|
|
213
|
-
# Read in the public ssh key.
|
214
|
-
#
|
215
|
-
# @return [String]
|
216
|
-
def pubkey
|
217
|
-
if config[:ssh_keygen]
|
218
|
-
logger.info("Generating public/private rsa key pair")
|
219
|
-
gen_key_pair
|
220
|
-
end
|
221
|
-
File.readlines(public_key_file).first.chomp
|
222
|
-
end
|
223
|
-
|
224
213
|
# Add our special sauce to the instance metadata to be executed by cloud-init.
|
225
214
|
def metadata
|
226
215
|
md = {}
|
227
216
|
inject_powershell
|
228
217
|
config[:custom_metadata]&.each { |k, v| md.store(k, v) }
|
229
|
-
md.store("ssh_authorized_keys",
|
218
|
+
md.store("ssh_authorized_keys", read_public_key) unless config[:setup_winrm]
|
230
219
|
md.store("user_data", user_data) if user_data?
|
231
220
|
md
|
232
221
|
end
|
@@ -111,17 +111,6 @@ module Kitchen
|
|
111
111
|
def long_hostname_suffix
|
112
112
|
[random_string(25 - hostname_prefix.length), random_string(3)].compact.join("-")
|
113
113
|
end
|
114
|
-
|
115
|
-
# Read in the public ssh key.
|
116
|
-
#
|
117
|
-
# @return [String]
|
118
|
-
def read_public_key
|
119
|
-
if config[:ssh_keygen]
|
120
|
-
logger.info("Generating public/private rsa key pair")
|
121
|
-
gen_key_pair
|
122
|
-
end
|
123
|
-
File.readlines(public_key_file).first.chomp
|
124
|
-
end
|
125
114
|
end
|
126
115
|
end
|
127
116
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Justin Steele (<justin.steele@oracle.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2025, Stephen Pearson
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Driver
|
22
|
+
class Oci
|
23
|
+
# Execute the defined config validations
|
24
|
+
#
|
25
|
+
# @param message [String] the message to be output to explain the validation.
|
26
|
+
# @param driver [Kitchen::Driver] the instance of the driver.
|
27
|
+
# @raise [UserError]
|
28
|
+
def self.validation_error(message, driver)
|
29
|
+
raise UserError, "#{driver.class}<#{driver.instance.name}>#config#{message}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Coerces config values to standardized formats.
|
33
|
+
#
|
34
|
+
# @param instance [Kitchen::Instance]
|
35
|
+
def finalize_config!(instance)
|
36
|
+
super
|
37
|
+
%i{instance_type ssh_keytype}.each do |k|
|
38
|
+
config[k] = config[k].downcase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
validations[:instance_type] = lambda do |attr, val, driver|
|
43
|
+
validation_error("[:#{attr}] #{val} is not a valid instance_type. must be either compute or dbaas.", driver) unless %w{compute dbaas}.include?(val.downcase)
|
44
|
+
end
|
45
|
+
|
46
|
+
validations[:nsg_ids] = lambda do |attr, val, driver|
|
47
|
+
unless val.nil?
|
48
|
+
validation_error("[:#{attr}] list cannot be longer than 5 items", driver) if val.length > 5
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
validations[:volumes] = lambda do |attr, val, driver|
|
53
|
+
val.each do |vol_attr|
|
54
|
+
unless ["iscsi", "paravirtual", nil].include?(vol_attr[:type])
|
55
|
+
validation_error("[:#{attr}][:type] #{vol_attr[:type]} is not a valid volume type for #{vol_attr[:name]}", driver)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
validations[:ssh_keytype] = lambda do |attr, val, driver|
|
61
|
+
validation_error("[:#{attr}] #{val} is not a supported ssh key type.", driver) unless %w{rsa ed25519}.include?(val.downcase)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/kitchen/driver/oci.rb
CHANGED
@@ -34,10 +34,15 @@ module Kitchen
|
|
34
34
|
# @author Stephen Pearson <stephen.pearson@oracle.com>
|
35
35
|
class Oci < Kitchen::Driver::Base
|
36
36
|
require_relative "oci_version"
|
37
|
+
require_relative "oci/validations"
|
37
38
|
require_relative "oci/mixin/actions"
|
38
39
|
require_relative "oci/mixin/models"
|
39
40
|
require_relative "oci/mixin/volumes"
|
40
41
|
|
42
|
+
include Kitchen::Driver::Oci::Mixin::Actions
|
43
|
+
include Kitchen::Driver::Oci::Mixin::Models
|
44
|
+
include Kitchen::Driver::Oci::Mixin::Volumes
|
45
|
+
|
41
46
|
plugin_version Kitchen::Driver::OCI_VERSION
|
42
47
|
kitchen_driver_api_version 2
|
43
48
|
|
@@ -66,6 +71,7 @@ module Kitchen
|
|
66
71
|
default_keypath = File.expand_path(File.join(%w{~ .ssh id_rsa.pub}))
|
67
72
|
default_config :ssh_keypath, default_keypath
|
68
73
|
default_config :ssh_keygen, false
|
74
|
+
default_config :ssh_keytype, "rsa"
|
69
75
|
default_config :post_create_script, nil
|
70
76
|
default_config :proxy_url, nil
|
71
77
|
default_config :user_data, nil
|
@@ -95,28 +101,6 @@ module Kitchen
|
|
95
101
|
# dbaas configs
|
96
102
|
default_config :dbaas, {}
|
97
103
|
|
98
|
-
validations[:instance_type] = lambda do |attr, val, driver|
|
99
|
-
validation_error("[:#{attr}] #{val} is not a valid instance_type. must be either compute or dbaas.", driver) unless %w{compute dbaas}.include?(val.downcase)
|
100
|
-
end
|
101
|
-
|
102
|
-
validations[:nsg_ids] = lambda do |attr, val, driver|
|
103
|
-
unless val.nil?
|
104
|
-
validation_error("[:#{attr}] list cannot be longer than 5 items", driver) if val.length > 5
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
validations[:volumes] = lambda do |attr, val, driver|
|
109
|
-
val.each do |vol_attr|
|
110
|
-
unless ["iscsi", "paravirtual", nil].include?(vol_attr[:type])
|
111
|
-
validation_error("[:#{attr}][:type] #{vol_attr[:type]} is not a valid volume type for #{vol_attr[:name]}", driver)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.validation_error(message, driver)
|
117
|
-
raise UserError, "#{driver.class}<#{driver.instance.name}>#config#{message}"
|
118
|
-
end
|
119
|
-
|
120
104
|
# Creates an instance.
|
121
105
|
# (see Kitchen::Driver::Base#create)
|
122
106
|
#
|
@@ -145,23 +129,6 @@ module Kitchen
|
|
145
129
|
detatch_and_delete_volumes(state, oci, api)
|
146
130
|
terminate(state, inst)
|
147
131
|
end
|
148
|
-
|
149
|
-
private
|
150
|
-
|
151
|
-
include Kitchen::Driver::Oci::Mixin::Actions
|
152
|
-
include Kitchen::Driver::Oci::Mixin::Models
|
153
|
-
include Kitchen::Driver::Oci::Mixin::Volumes
|
154
|
-
|
155
|
-
# Creates the OCI config and API clients.
|
156
|
-
#
|
157
|
-
# @param action [Symbol] the name of the method that called this method.
|
158
|
-
# @return [Oci::Config, Oci::Api]
|
159
|
-
def auth(action)
|
160
|
-
oci = Oci::Config.new(config)
|
161
|
-
api = Oci::Api.new(oci.config, config)
|
162
|
-
oci.compartment if action == :create
|
163
|
-
[oci, api]
|
164
|
-
end
|
165
132
|
end
|
166
133
|
end
|
167
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-oci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Pearson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oci
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: ed25519
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: bundler
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,11 +158,13 @@ files:
|
|
144
158
|
- lib/kitchen/driver/oci/instance/dbaas.rb
|
145
159
|
- lib/kitchen/driver/oci/mixin/actions.rb
|
146
160
|
- lib/kitchen/driver/oci/mixin/models.rb
|
161
|
+
- lib/kitchen/driver/oci/mixin/ssh_keys.rb
|
147
162
|
- lib/kitchen/driver/oci/mixin/volumes.rb
|
148
163
|
- lib/kitchen/driver/oci/models/compute.rb
|
149
164
|
- lib/kitchen/driver/oci/models/dbaas.rb
|
150
165
|
- lib/kitchen/driver/oci/models/iscsi.rb
|
151
166
|
- lib/kitchen/driver/oci/models/paravirtual.rb
|
167
|
+
- lib/kitchen/driver/oci/validations.rb
|
152
168
|
- lib/kitchen/driver/oci_version.rb
|
153
169
|
- tpl/setup_winrm.ps1.erb
|
154
170
|
homepage: https://github.com/stephenpearson/kitchen-oci
|