minimal_pipeline 0.1.4 → 0.1.5
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/minimal_pipeline/ec2.rb +13 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dae73303640fdffd715b9d7f67ea9b9f7ecd855dd0ef75d04e1d46eae07571e
|
4
|
+
data.tar.gz: d0c95d8d34c210e872ab6ae0fe93e8e56d5b3287229e56a04f82a97d690e007b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da91ca383ed709da049eb0b843bfd21066797ed5d0b5ce9126074547c88d03ec7755de2512a4bc51c235069b5b0b7fdb3ac519be99d12ca4fe120e84a58aea9
|
7
|
+
data.tar.gz: c2a9d49ce298448bf6a41131bd7394ee04c231fa0d5918eaf79af51bb6123c8576f372f1e625826175ae091d045388982eb0efed145b4dcd9f60e01a06f00a68
|
data/lib/minimal_pipeline/ec2.rb
CHANGED
@@ -17,15 +17,10 @@ class MinimalPipeline
|
|
17
17
|
class Ec2
|
18
18
|
# Initializes a `Ec2` client
|
19
19
|
# Requires environment variables `AWS_REGION` or `region` to be set.
|
20
|
-
# Also requires `keystore_table` and `keystore_kms_id`
|
21
20
|
def initialize
|
22
21
|
raise 'You must set env variable AWS_REGION or region.' \
|
23
22
|
if ENV['AWS_REGION'].nil? && ENV['region'].nil?
|
24
|
-
raise 'You must set env variable keystore_kms_id.' \
|
25
|
-
if ENV['inventory_store_key'].nil? && ENV['keystore_kms_id'].nil?
|
26
|
-
|
27
23
|
@region = ENV['AWS_REGION'] || ENV['region']
|
28
|
-
@kms_key_id = ENV['keystore_kms_id'] || ENV['inventory_store_key']
|
29
24
|
@client = Aws::EC2::Client.new(region: 'us-east-1')
|
30
25
|
end
|
31
26
|
|
@@ -43,15 +38,18 @@ class MinimalPipeline
|
|
43
38
|
# Create a copy of an existing snapshot
|
44
39
|
#
|
45
40
|
# @param snapshot_id [String] The ID of the snapshot to copy
|
41
|
+
# @param kms_key_id [String] The ID of the KMS key. Omit to use default
|
46
42
|
# @param encrypted [Boolean] Whether or not the volume is encrypted
|
47
43
|
# @return [String] The ID of the newly created snapshot
|
48
|
-
def copy_snapshot(snapshot_id, encrypted = true)
|
49
|
-
|
44
|
+
def copy_snapshot(snapshot_id, kms_key_id = nil, encrypted = true)
|
45
|
+
params = {
|
50
46
|
encrypted: encrypted,
|
51
|
-
kms_key_id: @kms_key_id,
|
52
47
|
source_region: @region,
|
53
48
|
source_snapshot_id: snapshot_id
|
54
|
-
|
49
|
+
}
|
50
|
+
params[:kms_key_id] = kms_key_id if kms_key_id
|
51
|
+
|
52
|
+
new_snapshot_id = @client.copy_snapshot(params).snapshot_id
|
55
53
|
|
56
54
|
puts "new snapshot ID: #{new_snapshot_id}"
|
57
55
|
wait_for_snapshot(new_snapshot_id)
|
@@ -76,8 +74,9 @@ class MinimalPipeline
|
|
76
74
|
#
|
77
75
|
# @param ami_id [String] The ID of the AMI to prepare
|
78
76
|
# @param account_id [String] The ID of the AWS account to prepare
|
77
|
+
# @param kms_key_id [String] The ID of the KMS key. Omit to use default
|
79
78
|
# @return [Array] Block device mappings discovered from the AMI
|
80
|
-
def prepare_snapshots_for_account(ami_id, account_id)
|
79
|
+
def prepare_snapshots_for_account(ami_id, account_id, kms_key_id = nil)
|
81
80
|
images = @client.describe_images(image_ids: [ami_id])
|
82
81
|
block_device_mappings = images.images[0].block_device_mappings
|
83
82
|
new_mappings = []
|
@@ -85,7 +84,7 @@ class MinimalPipeline
|
|
85
84
|
block_device_mappings.each do |mapping|
|
86
85
|
snapshot_id = mapping.ebs.snapshot_id
|
87
86
|
puts "old snapshot ID: #{snapshot_id}"
|
88
|
-
new_snapshot_id = copy_snapshot(snapshot_id)
|
87
|
+
new_snapshot_id = copy_snapshot(snapshot_id, kms_key_id)
|
89
88
|
puts 'modifying new snapshot attribute'
|
90
89
|
unlock_ami_for_account(new_snapshot_id, account_id)
|
91
90
|
puts "new snapshot has been modified for the #{account_id} account"
|
@@ -118,13 +117,14 @@ class MinimalPipeline
|
|
118
117
|
# Copy the snapshots from the original account into the new one
|
119
118
|
#
|
120
119
|
# @params block_device_mappings [Array] Block device mappings with snapshots
|
120
|
+
# @param kms_key_id [String] The ID of the KMS key. Omit to use default
|
121
121
|
# @return [Array] Block device mappings with updated snapshot ids
|
122
|
-
def copy_snapshots_in_new_account(block_device_mappings)
|
122
|
+
def copy_snapshots_in_new_account(block_device_mappings, kms_key_id = nil)
|
123
123
|
new_mappings = []
|
124
124
|
|
125
125
|
block_device_mappings.each do |mapping|
|
126
126
|
snapshot_id = mapping['ebs']['snapshot_id']
|
127
|
-
new_snapshot_id = copy_snapshot(snapshot_id)
|
127
|
+
new_snapshot_id = copy_snapshot(snapshot_id, kms_key_id)
|
128
128
|
mapping['ebs']['snapshot_id'] = new_snapshot_id
|
129
129
|
mapping['ebs'].delete('encrypted')
|
130
130
|
new_mappings << mapping
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimal_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mayowa Aladeojebi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-11-
|
12
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|