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 +4 -4
- data/lib/producer/stdlib.rb +3 -2
- data/lib/producer/stdlib/crypto.rb +39 -0
- data/lib/producer/stdlib/json.rb +22 -0
- data/lib/producer/stdlib/json/json_eq.rb +14 -0
- data/lib/producer/stdlib/ssh.rb +7 -0
- data/lib/producer/stdlib/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b44370b764db68abd79821fa5750a39517758e19
|
4
|
+
data.tar.gz: 7b0c215df3b7a0dab360a421e9cc8667017df0a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d731511a71e3aae3268f51219ae8e12cc6716a052cac4484b6c6013ccf6cd4adeea16ef1ef614559f36a49cef1dc061d9e14d67b92ec94afff58e5d61efd0a36
|
7
|
+
data.tar.gz: cf10be4f0a4061c2cb5aa4ff7f814be067598e07912dd0e0cdb2fc843d3f06020c5a47e5d215d24508f836b8ede9da730de3ac7a43366ec9b983ce10fde2a2b5
|
data/lib/producer/stdlib.rb
CHANGED
@@ -11,8 +11,9 @@ module Producer
|
|
11
11
|
::Producer::Core::Recipe.compose_macro(*args)
|
12
12
|
end
|
13
13
|
|
14
|
-
def define_test(
|
15
|
-
|
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
|
data/lib/producer/stdlib/ssh.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|