smps 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15e113dabe0eb6b4a7fc8fb7fc3f3c547f5e356c
4
- data.tar.gz: d135671af94168bfd52e42879a704db5f6d9c104
3
+ metadata.gz: 614c0500b77bee06d0fd6502ab14882f13f1ade8
4
+ data.tar.gz: 711c277ba2821f707c130f0168be932b7ed75e8a
5
5
  SHA512:
6
- metadata.gz: 6e60e0396a8fed1ff31d46f7f60f9de7c9dad586c05f7f17d9739420388881a06185ef5267741f142944ab82f51b90c2b91512e40154c507618f433de8f19988
7
- data.tar.gz: 529e4a1fb4b898084d4511636ca92f6564f83dc6cfe6830b5d44cf80dac0f9611abf5907aa4d6162e690f005baa0339f5f08034fcb2a19b21b9963e676ac6967
6
+ metadata.gz: cfca86be7e38de6dab369740706778876d1a7d8299ea9e2c2d5dc8fcd16c01d68535b2918568d7023a31ae0f55e677127db7861d28302e8f596d70beab1d81e6
7
+ data.tar.gz: d418d8e2228a862848e2f3c3b982eecd070e430f521f95a81f0cef463a437e835fbd5b318123ed9e6c014b867f0996a149f73772b0e5f90e806bb0964159630f
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ## [Unreleased]
5
5
 
6
+ ## [0.2.2] - 2017-10-06
7
+ ### Added
8
+ - Parameters for creating / writing SecureString
9
+
6
10
  ## [0.2.1] - 2017-10-05
7
11
  ### Changed
8
12
  - Class structure improvement
data/exe/smps CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'getoptlong'
3
3
  require 'smps'
4
+ require 'net/http'
4
5
 
5
6
  def clidoc
6
7
  puts <<-CLIDOC
@@ -12,25 +13,53 @@ def clidoc
12
13
 
13
14
  -r, --role <rolename>
14
15
  IAM role to use. From ~/.aws/config
16
+ Use this for interactive use on your workstation.
15
17
 
16
18
  -p, --param <param_name>
17
19
  Parameter name.
18
20
 
21
+ -v, --value <new_value>
22
+ Value to assign
23
+
24
+ -t, --type <type>
25
+ Parameter type.
26
+ One of [String StringList SecureString]
27
+
28
+ -k, --key <key_id>
29
+ Key for SecureString encrypting.
30
+
19
31
  -d, --debug [level]:
20
32
  Debug level.
21
33
 
22
34
  CLIDOC
23
35
  end
24
36
 
37
+ def region
38
+ require 'net/http'
39
+ require 'uri'
40
+ require 'json'
41
+
42
+ uri = URI.parse('http://169.254.169.254/latest/dynamic/instance-identity/document')
43
+ response = Net::HTTP.get_response(uri)
44
+
45
+ JSON.parse(response.body)['region']
46
+ end
47
+
25
48
  opts = GetoptLong.new(
26
49
  ['--help', '-h', GetoptLong::NO_ARGUMENT],
27
50
  ['--role', '-r', GetoptLong::REQUIRED_ARGUMENT],
28
51
  ['--param', '-p', GetoptLong::REQUIRED_ARGUMENT],
52
+ ['--value', '-v', GetoptLong::REQUIRED_ARGUMENT],
53
+ ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
54
+ ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT],
29
55
  ['--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT]
30
56
  )
31
57
 
32
58
  role = nil
33
59
  param = nil
60
+ value = nil
61
+ type = nil
62
+ key_id = nil
34
63
  debug = 0
35
64
 
36
65
  opts.each do |opt, arg|
@@ -42,6 +71,12 @@ opts.each do |opt, arg|
42
71
  role = arg
43
72
  when '--param'
44
73
  param = arg
74
+ when '--value'
75
+ value = arg
76
+ when '--type'
77
+ type = arg
78
+ when '--key'
79
+ key_id = arg
45
80
  when '--debug'
46
81
  debug = if arg == ''
47
82
  1
@@ -54,7 +89,7 @@ end
54
89
  if role
55
90
  require 'awssession'
56
91
  require 'aws_config'
57
-
92
+
58
93
  profile_name = role
59
94
  profile = AWSConfig[profile_name]
60
95
  profile['name'] = profile_name
@@ -64,9 +99,12 @@ if role
64
99
 
65
100
  smps = SmPs.new(credentials: awssession.credentials)
66
101
  else
102
+ Aws.config.update(region: region)
67
103
  smps = SmPs.new
68
104
  end
69
105
 
70
- puts smps.parameter(param).to_s
106
+ parameter = smps.parameter(name: param, type: type, key_id: key_id)
107
+ parameter.write!(value) if value
108
+ puts parameter.to_s
71
109
 
72
110
  # vim:set fileencoding=utf8 fileformat=unix filetype=ruby tabstop=2 expandtab:
@@ -17,9 +17,15 @@ class SmPs
17
17
  end
18
18
  end
19
19
 
20
- def parameter(name)
20
+ def parameter(options)
21
+ name = options.fetch(:name)
22
+ type = options[:type]
23
+ key_id = options[:key_id]
21
24
  unless @parameters.key?(name)
22
- @parameters[name] = SmPs::Parameter.new(ssm: ssm_client, name: name)
25
+ @parameters[name] = SmPs::Parameter.new(
26
+ ssm: ssm_client,
27
+ name: name, type: type, key_id: key_id
28
+ )
23
29
  end
24
30
  @parameters[name]
25
31
  end
@@ -5,6 +5,8 @@ class SmPs
5
5
  def initialize(options)
6
6
  @ssm = options[:ssm]
7
7
  @name = options[:name]
8
+ @type = options[:type]
9
+ @key_id = options[:key_id]
8
10
  parameter
9
11
  end
10
12
 
@@ -28,13 +30,12 @@ class SmPs
28
30
  @exists
29
31
  end
30
32
 
31
- def write!(value, type = 'String', description = nil, key_id = nil)
32
- raise ArgumentError unless %w[String StringList SecureString].include? type
33
- true if value == @value
33
+ def write!(value, description = nil)
34
+ return true if value == @value
34
35
  @ssm.put_parameter(
35
- name: @name, description: description,
36
- value: value, type: type,
37
- key_id: key_id, overwrite: @exists,
36
+ name: @name, value: value,
37
+ description: description, type: @type,
38
+ key_id: @key_id, overwrite: @exists,
38
39
  # allowed_pattern: "AllowedPattern",
39
40
  )
40
41
  @value = value
@@ -1,3 +1,3 @@
1
1
  class SmPs
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan - Zipkid - Goethals
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler