ruby_gpg2 0.1.0.pre.1 → 0.1.0.pre.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
  SHA256:
3
- metadata.gz: 4ade0475a49d03d3a98f46df861ee4d432fa76934d8f18beb0fcc9a4e4f5b59e
4
- data.tar.gz: 26c91fff6858bf52e54fe2dd03b7e68041b72742aad1c1aa73bc496b0ef28350
3
+ metadata.gz: a4f00d4cf2494de2e8cdeb3103bf4dc8537db7f150e97971e2e20053a5e026f9
4
+ data.tar.gz: 6f2dab623e1ab6337c341df8e40d2f686119e03b52b29f2a1437d9cb9a05ab1f
5
5
  SHA512:
6
- metadata.gz: 42e3c87539c9df3b6d0385940293705e465cd429102771c7e0548a964d9eab851d55923c58db2774d1715e491075ee493199d8b4eb01e53fb32e907793923178
7
- data.tar.gz: '09543fda6bfd4eb91ed8e164da9d8b760118321bfb0651efca19fc6e4a1bf78af4e401136f44f114409b3a9b1e7b85ce05d887633f8a2130255a9e97839207d3'
6
+ metadata.gz: 24f3299eb68ec2e9c48d992dd4590e4d1c7a00d576b9992f2cf2714c7060067fc12f213067aafce492cad41e68d2d8d7dd8becd86e09c455953ec90646423f09
7
+ data.tar.gz: 465d3bf9bee8cca7bf4049cd823775b45499451ad012c510c3dcb1f7df09af651a177b79015869c833f339fce60927041f08eda4b37f43f15fdb3d88b5e233f4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_gpg2 (0.1.0.pre.1)
4
+ ruby_gpg2 (0.1.0.pre.2)
5
5
  lino (= 1.3.0)
6
6
 
7
7
  GEM
@@ -0,0 +1,55 @@
1
+ require 'lino'
2
+
3
+ module RubyGPG2
4
+ module Commands
5
+ class Base
6
+ attr_reader :binary
7
+
8
+ def initialize(binary: nil)
9
+ @binary = binary || RubyGPG2.configuration.binary
10
+ end
11
+
12
+ def stdin
13
+ ''
14
+ end
15
+
16
+ def stdout
17
+ STDOUT
18
+ end
19
+
20
+ def stderr
21
+ STDERR
22
+ end
23
+
24
+ def execute(opts = {})
25
+ builder = instantiate_builder
26
+
27
+ do_before(opts)
28
+ builder = configure_command(builder, opts)
29
+ builder
30
+ .build
31
+ .execute(
32
+ stdin: stdin,
33
+ stdout: stdout,
34
+ stderr: stderr)
35
+ do_after(opts)
36
+ end
37
+
38
+ def instantiate_builder
39
+ Lino::CommandLineBuilder
40
+ .for_command(binary)
41
+ .with_option_separator('=')
42
+ end
43
+
44
+ def do_before(opts)
45
+ end
46
+
47
+ def configure_command(builder, opts)
48
+ builder
49
+ end
50
+
51
+ def do_after(opts)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ require 'lino'
2
+
3
+ require_relative 'base'
4
+ require_relative 'mixins/global_config'
5
+
6
+ module RubyGPG2
7
+ module Commands
8
+ class GenerateKey < Base
9
+ include Mixins::GlobalConfig
10
+
11
+ def configure_command(builder, opts)
12
+ parameter_file_path = opts[:parameter_file_path]
13
+
14
+ builder = builder.with_subcommand('--generate-key')
15
+ builder = super(builder, opts)
16
+ builder = builder.with_argument(parameter_file_path) if parameter_file_path
17
+ builder
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module RubyGPG2
2
+ module Commands
3
+ module Mixins
4
+ module GlobalConfig
5
+ def configure_command(builder, opts)
6
+ batch = opts[:batch].nil? ? true : opts[:batch]
7
+ home_directory = opts[:home_directory]
8
+
9
+ builder = super(builder, opts)
10
+ builder = builder.with_flag('--batch') if batch
11
+ builder = builder.with_option(
12
+ '--homedir', home_directory, quoting: '"') if home_directory
13
+ builder
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'commands/generate_key'
2
+
3
+ module RubyGPG2
4
+ module Commands
5
+
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ module RubyGPG2
2
+ class ParameterFile
3
+ attr_reader(
4
+ :key_type,
5
+ :key_length,
6
+ :subkey_type,
7
+ :subkey_length,
8
+ :owner_name,
9
+ :owner_email,
10
+ :owner_comment,
11
+ :expiry,
12
+ :passphrase)
13
+
14
+ def initialize(opts)
15
+ @key_type = opts.fetch(:key_type, 'RSA')
16
+ @key_length = opts.fetch(:key_length,
17
+ (@key_type.to_s == 'default' ? nil : 2048))
18
+ @subkey_type = opts.fetch(:subkey_type, 'RSA')
19
+ @subkey_length = opts.fetch(:subkey_length,
20
+ ((@subkey_type.nil? || @subkey_type.to_s == 'default') ? nil : 2048))
21
+ @owner_name = opts.fetch(:owner_name, nil)
22
+ @owner_email = opts.fetch(:owner_email, nil)
23
+ @owner_comment = opts.fetch(:owner_comment, nil)
24
+ @expiry = opts.fetch(:expiry, :never)
25
+ @passphrase = opts.fetch(:passphrase, nil)
26
+
27
+ owner_name_present = !@owner_name.nil?
28
+ owner_email_present = !@owner_email.nil?
29
+ missing_count = [
30
+ owner_name_present,
31
+ owner_email_present
32
+ ].count(false)
33
+ missing_names = [
34
+ owner_name_present ? nil : :owner_name,
35
+ owner_email_present ? nil : :owner_email
36
+ ].compact
37
+
38
+ unless missing_count == 0
39
+ raise RuntimeError.new(
40
+ "Missing required parameter#{missing_count > 1 ? 's' : ''}: " +
41
+ "#{missing_names}.")
42
+ end
43
+ end
44
+
45
+ def write_to(path)
46
+ File.open(path, 'w') do |f|
47
+ f.write(to_s)
48
+ end
49
+ end
50
+
51
+ def to_s
52
+ [
53
+ parm("Key-Type", key_type),
54
+ parm("Key-Length", key_length),
55
+ parm("Subkey-Type", subkey_type),
56
+ parm('Subkey-Length', subkey_length),
57
+ parm('Name-Real', owner_name),
58
+ parm('Name-Comment', owner_comment),
59
+ parm('Name-Email', owner_email),
60
+ parm('Expire-Date',
61
+ expiry == :never ? 0 : expiry),
62
+ parm('Passphrase', passphrase),
63
+ ].compact.join("\n") + "\n"
64
+ end
65
+
66
+ private
67
+
68
+ def parm(name, value)
69
+ value ? "#{name}: #{value}" : nil
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyGPG2
2
- VERSION = '0.1.0.pre.1'
2
+ VERSION = '0.1.0.pre.2'
3
3
  end
data/lib/ruby_gpg2.rb CHANGED
@@ -1,4 +1,29 @@
1
1
  require 'ruby_gpg2/version'
2
+ require 'ruby_gpg2/commands'
3
+ require 'ruby_gpg2/parameter_file'
2
4
 
3
5
  module RubyGPG2
6
+ class << self
7
+ attr_writer :configuration
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def configure
14
+ yield(configuration)
15
+ end
16
+
17
+ def reset!
18
+ @configuration = nil
19
+ end
20
+ end
21
+
22
+ class Configuration
23
+ attr_accessor :binary
24
+
25
+ def initialize
26
+ @binary = 'gpg'
27
+ end
28
+ end
4
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_gpg2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.1
4
+ version: 0.1.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-26 00:00:00.000000000 Z
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lino
@@ -159,6 +159,11 @@ files:
159
159
  - config/secrets/rubygems/credentials
160
160
  - go
161
161
  - lib/ruby_gpg2.rb
162
+ - lib/ruby_gpg2/commands.rb
163
+ - lib/ruby_gpg2/commands/base.rb
164
+ - lib/ruby_gpg2/commands/generate_key.rb
165
+ - lib/ruby_gpg2/commands/mixins/global_config.rb
166
+ - lib/ruby_gpg2/parameter_file.rb
162
167
  - lib/ruby_gpg2/version.rb
163
168
  - ruby_gpg2.gemspec
164
169
  - scripts/ci/common/configure-git.sh