producer-stdlib 0.1.1 → 0.1.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: 6b7940927a813df413a1093d36ac2f43d3b0a7eb
4
- data.tar.gz: 3d3142a45d079a8adc88fade273d379856ae8f8a
3
+ metadata.gz: b44370b764db68abd79821fa5750a39517758e19
4
+ data.tar.gz: 7b0c215df3b7a0dab360a421e9cc8667017df0a7
5
5
  SHA512:
6
- metadata.gz: 5d70c8a69c99db71468ad3f8cdad6c3906623e01bbb8bbe69582b69a3abc87b629876a7b515169ad9ba54187634ebc8aa2567ae0b6065560d89d1e68ca8dc736
7
- data.tar.gz: a647c621532e4ec772f784ef41f235ea675e6eb06816bafd0f05bc2428eb7ed7fb79f4342f6a9557566b9eaddea9410981780f386818805fa560dea036b3d760
6
+ metadata.gz: d731511a71e3aae3268f51219ae8e12cc6716a052cac4484b6c6013ccf6cd4adeea16ef1ef614559f36a49cef1dc061d9e14d67b92ec94afff58e5d61efd0a36
7
+ data.tar.gz: cf10be4f0a4061c2cb5aa4ff7f814be067598e07912dd0e0cdb2fc843d3f06020c5a47e5d215d24508f836b8ede9da730de3ac7a43366ec9b983ce10fde2a2b5
@@ -11,8 +11,9 @@ module Producer
11
11
  ::Producer::Core::Recipe.compose_macro(*args)
12
12
  end
13
13
 
14
- def define_test(name, &block)
15
- ::Producer::Core::Condition.define_test(name, block)
14
+ def define_test(*args, &block)
15
+ args << block if block
16
+ ::Producer::Core::Condition.define_test(*args)
16
17
  end
17
18
  end
18
19
 
@@ -0,0 +1,39 @@
1
+ require 'openssl'
2
+ require 'securerandom'
3
+
4
+ module Producer
5
+ module STDLib
6
+ module Crypto
7
+ STDLib.define_macro :cert_write do |path, cn, issuer_path, ikey_path|
8
+ name = OpenSSL::X509::Name.parse("CN=#{cn}")
9
+ issuer = OpenSSL::X509::Certificate.new(File.read(issuer_path))
10
+ ikey = OpenSSL::PKey::RSA.new(File.read(ikey_path))
11
+ key = OpenSSL::PKey::RSA.new(4096)
12
+
13
+ cert = OpenSSL::X509::Certificate.new
14
+ cert.serial = SecureRandom.random_number(2 ** 159)
15
+ cert.version = 2
16
+ cert.not_before = Time.now
17
+ cert.not_after = Time.now + 20 * 365 * 86400
18
+ cert.public_key = key.public_key
19
+ cert.subject = name
20
+ cert.issuer = issuer.subject
21
+
22
+ ef = OpenSSL::X509::ExtensionFactory.new
23
+ ef.subject_certificate = cert
24
+ ef.issuer_certificate = issuer
25
+ cert.extensions = [
26
+ ef.create_extension('subjectKeyIdentifier', 'hash'),
27
+ ef.create_extension('basicConstraints', 'CA:FALSE'),
28
+ ef.create_extension(
29
+ 'keyUsage', 'keyEncipherment,dataEncipherment,digitalSignature'
30
+ )
31
+ ]
32
+
33
+ cert.sign ikey, OpenSSL::Digest::SHA512.new
34
+
35
+ file_write path, cert.to_pem + key.to_pem, mode: 0600
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+ require 'producer/stdlib/json/json_eq'
3
+
4
+ module Producer
5
+ module STDLib
6
+ module JSON
7
+ #STDLib.define_test :json_eq do |path, data|
8
+ # file_eq path, ::JSON.generate(data)
9
+ #end
10
+ STDLib.define_test :json_eq, JSONEq
11
+
12
+ STDLib.define_macro :json_write do |path, data|
13
+ file_write path, ::JSON.generate(data)
14
+ end
15
+
16
+ STDLib.define_macro :json_write_once do |path, data|
17
+ condition { no_json_eq path, data }
18
+ json_write path, data
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Producer
2
+ module STDLib
3
+ module JSON
4
+ class JSONEq < Core::Test
5
+ def verify
6
+ return false unless file_content = fs.file_read(arguments.first)
7
+ ::JSON.parse(file_content, symbolize_names: true) == arguments[1]
8
+ rescue ::JSON::ParserError
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,7 @@ module Producer
6
6
  SSH_AUTHORIZED_KEYS_PATH = '.ssh/authorized_keys'.freeze
7
7
  SSH_AUTHORIZED_NO_KEY_FMT =
8
8
  '"ssh_authorize macro cannot find key matching `%s\''
9
+ SSH_KEY_DEFAULT_PATH = '.ssh/id_rsa'
9
10
 
10
11
 
11
12
  STDLib.define_macro :ssh_dir do
@@ -52,6 +53,12 @@ module Producer
52
53
  file_write path, "#{line}\n", mode: 0600
53
54
  end
54
55
  end
56
+
57
+ STDLib.define_macro :ssh_keygen do |path = SSH_KEY_DEFAULT_PATH|
58
+ condition { no_file? path }
59
+
60
+ sh "ssh-keygen -f #{path} -N ''"
61
+ end
55
62
  end
56
63
  end
57
64
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module STDLib
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: producer-core
@@ -38,11 +38,14 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - lib/producer/stdlib.rb
41
+ - lib/producer/stdlib/crypto.rb
41
42
  - lib/producer/stdlib/debian.rb
42
43
  - lib/producer/stdlib/freebsd.rb
43
44
  - lib/producer/stdlib/freebsd/ports.rb
44
45
  - lib/producer/stdlib/fs.rb
45
46
  - lib/producer/stdlib/git.rb
47
+ - lib/producer/stdlib/json.rb
48
+ - lib/producer/stdlib/json/json_eq.rb
46
49
  - lib/producer/stdlib/ssh.rb
47
50
  - lib/producer/stdlib/version.rb
48
51
  - lib/producer/stdlib/yaml.rb