Class: Leeloo::Command

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/leeloo/command.rb

Instance Method Summary collapse

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/leeloo/command.rb', line 15

def run
  program :name, 'leeloo'
  program :version, Leeloo::VERSION
  program :description, [
    "leeloo multipass - #{Leeloo::DESCRIPTION}",
    "\tRun using `leeloo [action]`"
  ].join("\n")
  program :help, 'Author', 'Sylvain Maucourt <[email protected]>'
  program :help, 'GitHub', 'https://github.com/sylvek'
  program :help_formatter, :compact

  default_command :wrapper

  command :wrapper do |c|
    c.action do |args, options|
      unless args == []
        name = args.first
        ctl = SecretController.new(options)
        ctl.read(name)
        ctl.display
      else
        SecretsController.new(options).display
      end
    end
  end

  command :list do |c|
    c.syntax      = 'leeloo list [options]'
    c.description = "Display secrets list of stored on a keystore"
    c.option '--ascii', nil, 'display secrets without unicode tree'
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      SecretsController.new(options).display
    end
  end

  command :search do |c|
    c.syntax      = 'leeloo search name'
    c.description = "Display secrets containing name pattern"
    c.option '--ascii', nil, 'display secrets without unicode tree'
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = SecretsController.new(options)
      ctl.search(name)
      ctl.display
    end
  end

  command :keystore do |c|
    c.syntax      = 'leeloo keystores'
    c.description = "Display current keystores"
    c.option '--ascii', nil, 'display secrets without unicode tree'

    c.action do |args, options|
      KeystoreController.new(options).display
    end
  end

  command "keystore remove" do |c|
    c.syntax      = 'leeloo keystore remove <name>'
    c.description = "remove a keystore (path/to/keystore is not destroyed)"

    c.action do |args, options|args
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = KeystoreController.new(options)
      ctl.remove(name)
      ctl.display
    end
  end

  command "keystore add" do |c|
    c.syntax      = 'leeloo keystore add <name> <path/to/keystore>'
    c.description = "add a keystore"

    c.action do |args, options|
      abort "name or path is missing" unless args.length == 2
      name = args.first
      path = args.last
      ctl = KeystoreController.new(options)
      ctl.add(name, path)
      ctl.display
    end
  end

  command "keystore default" do |c|
    c.syntax      = 'leeloo keystore default name'
    c.description = "set the default keystore"

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = KeystoreController.new(options)
      ctl.set_default(name)
      ctl.display
    end
  end

  command :key do |c|
    c.syntax      = 'leeloo keys'
    c.description = "list keys from this keystore"
    c.option '--ascii', nil, 'display secrets without unicode tree'
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = KeysController.new(options)
      ctl.display
    end
  end

  command "key sync" do |c|
    c.syntax      = 'leeloo keys sync'
    c.description = "synchronize secrets with keys"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = KeysController.new(options)
      ctl.sync
      ctl.display
    end
  end

  command "key add" do |c|
    c.syntax      = 'leeloo key add <email>'
    c.description = "add a dedicated key"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "email is missing" unless args.length == 1
      email = args.first
      ctl = KeysController.new(options)
      ctl.add_key(email)
      ctl.display
    end
  end

  command "key remove" do |c|
    c.syntax      = 'leeloo key remove <email>'
    c.description = "remove a dedicated key"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "email is missing" unless args.length == 1
      email = args.first
      ctl = KeysController.new(options)
      ctl.remove_key(email)
      ctl.display
    end
  end

  command :read do |c|
    c.syntax      = 'leeloo read <name>'
    c.description = "Display a secret from a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'
    c.option '--clipboard', nil, 'copy to clipboard'
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = SecretController.new(options)
      ctl.read(name)
      ctl.display
    end
  end

  command :write do |c|
    c.syntax      = 'leeloo write <name> <secret>'
    c.description = "Write a secret from a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'
    c.option '--generate INTEGER', Integer, 'a number of randomized characters'
    c.option '--stdin', nil, 'secret given by stdin pipe'
    c.option '--clipboard', nil, 'copy to clipboard'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = SecretController.new(options)
      ctl.write(name)
      ctl.display
    end
  end

  command :translate do |c|
    c.syntax      = 'leeloo translate'
    c.description = "translate stdin by replacing key ${my/secret} by the current value"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = TranslateController.new(options)
      ctl.translate
      ctl.display
    end
  end

  command :remove do |c|
    c.syntax      = 'leeloo delete <name>'
    c.description = "Delete a secret from a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = SecretController.new(options)
      ctl.remove(name)
      ctl.display
    end
  end

  command "keystore sync" do |c|
    c.syntax      = 'leeloo sync'
    c.description = "Synchronize a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = KeystoreController.new(options)
      ctl.sync
      ctl.display
    end
  end

  command "keystore export" do |c|
    c.syntax      = 'leeloo export'
    c.description = "Export all secrets from a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = ExportController.new(options)
      ctl.display
    end
  end

  command "keystore init" do |c|
    c.syntax      = 'leeloo init'
    c.description = "Initialize a keystore"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      ctl = KeystoreController.new(options)
      ctl.init
      ctl.display
    end
  end

  command :share do |c|
    c.syntax      = 'leeloo share <name>'
    c.description = "share a secret with someone"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = ShareController.new(options)
      ctl.token(name)
      ctl.display
      ctl.start_server
    end
  end

  command :token do |c|
    c.syntax      = 'leeloo token <name>'
    c.description = "generate an access token for a given secret"
    c.option '--keystore STRING', String, 'a selected keystore'

    c.action do |args, options|
      abort "name is missing" unless args.length == 1
      name = args.first
      ctl = ShareController.new(options)
      ctl.token(name)
      ctl.display
    end
  end

  command :server do |c|
    c.syntax      = 'leeloo server'
    c.description = "start a server access token"

    c.action do |args, options|
      ctl = ShareController.new(options)
      ctl.start_server
    end
  end

end