Class: Chamber::Commands::Initialize

Inherits:
Base
  • Object
show all
Defined in:
lib/chamber/commands/initialize.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#chamber, #dry_run, #rootpath, #shell

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature:, namespaces: [], **args) ⇒ Initialize

Returns a new instance of Initialize.



22
23
24
25
26
27
28
# File 'lib/chamber/commands/initialize.rb', line 22

def initialize(signature:, namespaces: [], **args)
  super(**args)

  self.basepath   = Chamber.configuration.basepath
  self.namespaces = namespaces
  self.signature  = signature
end

Instance Attribute Details

#basepathObject

Returns the value of attribute basepath.



14
15
16
# File 'lib/chamber/commands/initialize.rb', line 14

def basepath
  @basepath
end

#namespacesObject

Returns the value of attribute namespaces.



14
15
16
# File 'lib/chamber/commands/initialize.rb', line 14

def namespaces
  @namespaces
end

#signatureObject

Returns the value of attribute signature.



14
15
16
# File 'lib/chamber/commands/initialize.rb', line 14

def signature
  @signature
end

Class Method Details

.call(**args) ⇒ Object



18
19
20
# File 'lib/chamber/commands/initialize.rb', line 18

def self.call(**args)
  new(**args).call
end

Instance Method Details

#callObject

rubocop:disable Layout/LineLength, Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/chamber/commands/initialize.rb', line 31

def call
  key_pairs = namespaces.map do |namespace|
    Chamber::KeyPair.new(namespace:     namespace,
                         key_file_path: rootpath)
  end
  key_pairs << Chamber::KeyPair.new(namespace:     nil,
                                    key_file_path: rootpath)

  key_pairs.each { |key_pair| generate_key_pair(key_pair) }

  if signature
    signature_key_pair = Chamber::KeyPair.new(namespace:     'signature',
                                              key_file_path: rootpath)

    generate_key_pair(signature_key_pair)
  end

  append_to_gitignore

  shell.copy_file settings_template_filepath, settings_filepath, skip: true

  shell.say ''
  shell.say '********************************************************************************', :green
  shell.say '                                    Success!', :green
  shell.say '********************************************************************************', :green
  shell.say ''

  if namespaces.empty?
    shell.say '.chamber.pem is your DEFAULT Chamber key.', :yellow
    shell.say ''
    shell.say 'If you would like a key which is used only for a certain environment (such as'
    shell.say 'production), or your local machine, you can rerun the command like so:'
    shell.say ''
    shell.say '$ chamber init --namespaces="production my_machines_hostname"', :yellow
    shell.say ''
    shell.say 'You can find more information about namespace keys here:'
    shell.say ''
    shell.say '  * '
    shell.say 'https://github.com/thekompanee/chamber/wiki/Namespaced-Key-Pairs', :blue
    shell.say ''
    shell.say '--------------------------------------------------------------------------------'
    shell.say ''
  end

  if signature
    shell.say '                                Your Signature Keys'
    shell.say ''
    shell.say 'Your signature keys, which will be used for verification, are located at:'
    shell.say ''
    shell.say '  * Public Key:            '
    shell.say signature_key_pair
                .public_key_filepath
                .relative_path_from(Pathname.pwd),
              :yellow
    shell.say '  * Private Key:           '
    shell.say signature_key_pair
                .unencrypted_private_key_filepath
                .relative_path_from(Pathname.pwd),
              :yellow
    shell.say '  * Encrypted Private Key: '
    shell.say signature_key_pair
                .encrypted_private_key_filepath
                .relative_path_from(Pathname.pwd),
              :yellow
    shell.say '  * Encrypted Passphrase:  '
    shell.say signature_key_pair
                .encrypted_private_key_passphrase_filepath
                .relative_path_from(Pathname.pwd),
              :yellow

    shell.say ''
    shell.say 'The signature private keys should be thought of separately from the other'
    shell.say 'project private keys you generate. They are not required to run the app'
    shell.say 'and should only be given out to *very select* people.'
    shell.say ''
    shell.say 'You can find more information about settings verification here:'
    shell.say ''
    shell.say '  * '
    shell.say 'https://github.com/thekompanee/chamber/wiki/Verifying-Settings', :blue
    shell.say ''
    shell.say '--------------------------------------------------------------------------------'
    shell.say ''
  end

  shell.say '                                Your Encrypted Keys'
  shell.say ''
  shell.say 'You can send your team members any of the file(s) located at:'
  shell.say ''

  key_pairs.each do |key_pair|
    shell.say '  * '
    shell.say key_pair.encrypted_private_key_filepath.relative_path_from(Pathname.pwd), :yellow
  end

  shell.say ''
  shell.say 'and not have to worry about sending them via a secure medium, however do'
  shell.say 'not send the passphrase along with it.  Give it to your team members in'
  shell.say 'person.'
  shell.say ''
  shell.say 'You can learn more about encrypted keys here:'
  shell.say ''
  shell.say '  * '
  shell.say 'https://github.com/thekompanee/chamber/wiki/Keypair-Encryption#the-encrypted-private-key', :blue
  shell.say ''
  shell.say '--------------------------------------------------------------------------------'
  shell.say ''
  shell.say '                                Your Key Passphrases'
  shell.say ''
  shell.say 'The passphrases for your encrypted private key(s) are stored in the'
  shell.say 'following locations:'
  shell.say ''

  key_pairs.each do |key_pair|
    shell.say '  * '
    shell.say key_pair.encrypted_private_key_passphrase_filepath.relative_path_from(Pathname.pwd), :yellow
  end

  shell.say ''
  shell.say 'In order for them to decrypt it (for use with Chamber), they can use something'
  shell.say 'like the following (swapping out the actual key filenames if necessary):'
  shell.say ''
  shell.say "$ cp #{key_pairs[0].encrypted_private_key_filepath.relative_path_from(Pathname.pwd)} #{key_pairs[0].unencrypted_private_key_filepath.relative_path_from(Pathname.pwd)}", :yellow
  shell.say "$ ssh-keygen -p -f #{key_pairs[0].unencrypted_private_key_filepath.relative_path_from(Pathname.pwd)}", :yellow
  shell.say ''
  shell.say 'Enter the passphrase when prompted and leave the new passphrase blank.'
  shell.say ''
  shell.say '--------------------------------------------------------------------------------'
  shell.say ''
end