ccs 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ccs +57 -0
- data/lib/ccs.rb +8 -0
- data/lib/ccs/configuration_file.rb +29 -0
- data/lib/ccs/decrypter.rb +32 -0
- data/lib/ccs/downloader.rb +36 -0
- data/lib/ccs/version.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f41c587aec81ba6914fde371c7645779d220d63
|
4
|
+
data.tar.gz: 01c7949ac8d27300b681841b13b9a51cb9104de3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b49503f5dd0556a88568bad93e9755e47d7bbc851d7855647d291f9771d69492af08f7a51eff302b096fa1ed2ea9f149eb4b5d777aae56659b5b6c7e80d9b3c
|
7
|
+
data.tar.gz: a993d334971f5a8989eff75fad704a6f45d2b8e1ec35b7c07073cd01d05291ec0a64bb2a351d4ba5d07ae1b50497ef6691e7c125a3bba87b94a42e1a71b6597b
|
data/bin/ccs
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ccs'
|
4
|
+
require 'optparse'
|
5
|
+
require 'io/console'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opt|
|
10
|
+
opt.banner = 'Usage: ccs [OPTIONS] <CCSUri> <LocalPath|STDOUT>'
|
11
|
+
opt.separator ''
|
12
|
+
opt.separator 'Options:'
|
13
|
+
|
14
|
+
opt.on('-t TOKEN', '--token TOKEN', String, 'API Token') do |v|
|
15
|
+
options[:token] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opt.on('-d', '--decrypt', 'Ask for passphrase and decrypt') do |v|
|
19
|
+
options[:decrypt] = v
|
20
|
+
end
|
21
|
+
|
22
|
+
opt.on('-h','--help', 'help') do
|
23
|
+
puts opt_parser
|
24
|
+
end
|
25
|
+
|
26
|
+
opt.separator ''
|
27
|
+
opt.separator 'Examples:'
|
28
|
+
opt.separator ' ccs -t 8b5a196e-a116-4c64-8472-f7c6e1c2de3b ccs://0.1.0/path/to/file.yml'
|
29
|
+
opt.separator ' ccs -t 8b5a196e-a116-4c64-8472-f7c6e1c2de3b ccs://0.1.0/path/to/file.yml local/path/to/file.yml'
|
30
|
+
|
31
|
+
opt.separator ''
|
32
|
+
opt.separator format('Version: %s', Ccs::VERSION)
|
33
|
+
end
|
34
|
+
|
35
|
+
arguments = opt_parser.parse!
|
36
|
+
|
37
|
+
if ARGV.empty?
|
38
|
+
puts opt_parser
|
39
|
+
exit(-1)
|
40
|
+
end
|
41
|
+
|
42
|
+
raise OptionParser::MissingArgument if options[:token].nil?
|
43
|
+
raise OptionParser::MissingArgument if arguments[0].nil?
|
44
|
+
|
45
|
+
configuration_file = Ccs::ConfigurationFile.new(arguments[0])
|
46
|
+
destination = arguments[1] ? File.new(arguments[1], 'w') : STDOUT
|
47
|
+
|
48
|
+
json = Ccs::Downloader.new(options[:token], configuration_file).download
|
49
|
+
|
50
|
+
if options[:decrypt]
|
51
|
+
print 'Passphrase: '
|
52
|
+
passphrase = STDIN.noecho(&:gets)
|
53
|
+
|
54
|
+
destination.puts Ccs::Decrypter.new(passphrase.chomp, json['encrypted_content']).decrypt
|
55
|
+
else
|
56
|
+
destination.puts json['encrypted_content']
|
57
|
+
end
|
data/lib/ccs.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ccs
|
2
|
+
class ConfigurationFile
|
3
|
+
def initialize(uri)
|
4
|
+
@uri = uri
|
5
|
+
end
|
6
|
+
|
7
|
+
def version
|
8
|
+
parts[0]
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
parts[1]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_path
|
16
|
+
Pathname.new path
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
format 'ccs://%s/%s', version, path
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parts
|
26
|
+
@parts ||= @uri.sub('ccs://', '').split('/', 2)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Ccs
|
2
|
+
class Decrypter
|
3
|
+
def initialize(passphrase, content)
|
4
|
+
@passphrase = passphrase
|
5
|
+
@content = content
|
6
|
+
end
|
7
|
+
|
8
|
+
def decrypt
|
9
|
+
decryptor.pkcs5_keyivgen(@passphrase, ciphertext_salt, 1)
|
10
|
+
result = decryptor.update(encrypted)
|
11
|
+
result << decryptor.final
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def decryptor
|
17
|
+
@decryptor ||= OpenSSL::Cipher::AES.new(256, :CBC).decrypt
|
18
|
+
end
|
19
|
+
|
20
|
+
def openssl_salted_ciphertext
|
21
|
+
@openssl_salted_ciphertext ||= Base64.strict_decode64 @content
|
22
|
+
end
|
23
|
+
|
24
|
+
def ciphertext_salt
|
25
|
+
openssl_salted_ciphertext[8..15]
|
26
|
+
end
|
27
|
+
|
28
|
+
def encrypted
|
29
|
+
openssl_salted_ciphertext[16..-1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ccs
|
2
|
+
class Downloader
|
3
|
+
def initialize(token, configuration_file)
|
4
|
+
@token = token
|
5
|
+
@configuration_file = configuration_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def download
|
9
|
+
response = http.request(request)
|
10
|
+
|
11
|
+
return unless response.class == Net::HTTPOK
|
12
|
+
|
13
|
+
JSON.parse(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def uri
|
19
|
+
@uri ||= URI format('https://pipello.io/api/v1/ccs/%s/%s', @configuration_file.version, @configuration_file.path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def http
|
23
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
24
|
+
http.use_ssl = uri.scheme == 'https'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def request
|
29
|
+
Net::HTTP::Get.new(uri.path, headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def headers
|
33
|
+
{ 'Authorization' => format('Token token=%s', @token) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ccs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pipello.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,7 +69,8 @@ dependencies:
|
|
69
69
|
description: ''
|
70
70
|
email:
|
71
71
|
- hello@pipello.io
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- ccs
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
@@ -77,7 +78,11 @@ files:
|
|
77
78
|
- CODE_OF_CONDUCT.md
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
81
|
+
- bin/ccs
|
80
82
|
- lib/ccs.rb
|
83
|
+
- lib/ccs/configuration_file.rb
|
84
|
+
- lib/ccs/decrypter.rb
|
85
|
+
- lib/ccs/downloader.rb
|
81
86
|
- lib/ccs/version.rb
|
82
87
|
homepage: https://github.com/pipello/ccs
|
83
88
|
licenses:
|