ccs 1.0.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '069f6dea98ed794eb37b0c890b8a901a97f6ed22f4492848cf638153c2bbe2d7'
4
- data.tar.gz: 1c38f234642b56603be1d0d429e3e3b496c81468a3b1aa9179556970f15bdeae
3
+ metadata.gz: 60d859bd2a81a6b31a609481cd0e1d0c04a2a4721084c044c65089f434ba0028
4
+ data.tar.gz: 499c070bcab5c966055de84266ffc4bfd474dc55e5051f82cc6c25dac5ceb992
5
5
  SHA512:
6
- metadata.gz: 50cdd4ebe25df6cc46486e248906c7ef7b64241eb9f5d1c8c17e6169076e7001d6f265f74fac22639b06ffd06fa69f373ee92014e8a104926ecd73ad5d599e41
7
- data.tar.gz: ae8ed38a5bc330beb2abb97845e189558c2ae45e9dee8d467ce4806634a1361d41fdcbb55e9093788a9dbb49ddc7aea9bedb9273b90a2a7c10a92c68c8b38d27
6
+ metadata.gz: be0fd271a7d744a143bb3a11b55bbde8a5da7ae569eb360f642160bf6fe04ddbbdb66a0f866f1999223c863b0b653dd234b54f56edd69820dab8ae50463e1088
7
+ data.tar.gz: cfcd265804deb742dc684cdd63aaef3d35e76cb9be048e0ddccec01ba28bbe7ab3eaa7523c96d0096d61636bcc71cb45b705d3760565eab70ddee047cfc1be10
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # CCS
2
2
 
3
+ Configuration control system
3
4
 
4
5
  ## Installation
5
6
 
@@ -19,8 +20,59 @@ Or install it yourself as:
19
20
 
20
21
  ## Usage
21
22
 
23
+ ccs cp [OPTIONS] <(LocalPath|STDIN)|(CCSUri|Uri)> <(CCSUri|Uri)|(LocalPath|STDOUT)>
24
+
25
+ Options:
26
+ -a CCS_ACCESS_TOKEN, CCS Access Token
27
+ --access-token
28
+ -s CCS_SECRET_TOKEN, CCS Secret Token
29
+ --secret-token
30
+
31
+
22
32
  ## Example
23
33
 
34
+ Download to STDOUT
35
+
36
+ ccs cp ccs://workspace-name/0.1.0/path/to/file.yml -
37
+ ccs cp http://host.tld:9292/workspace-name/0.1.0/path/to/file.yml -
38
+ ccs cp https://host.tld/workspace-name/0.1.0/path/to/file.yml -
39
+
40
+ Download to local file
41
+
42
+ ccs cp ccs://workspace-name/0.1.0/path/to/file.yml /local/path/to/file.yml
43
+
44
+ Upload local file
45
+
46
+ ccs cp /local/path/to/file.yml ccs://workspace-name/0.1.0/path/to/file.yml
47
+
48
+ Upload content from STDIN
49
+
50
+ echo "{ a: 1 }" | ccs cp - ccs://workspace-name/0.1.0/path/to/file.yml
51
+ cat /local/path/to/file.yml | ccs cp - ccs://workspace-name/0.1.0/path/to/file.yml
52
+
53
+ ## API
54
+
55
+ Upload
56
+
57
+ require 'ccs'
58
+
59
+ destination = 'ccs://workspace-name/0.1.0/path/to/file.yml'
60
+ access_token = ENV.fetch('CCS_ACCESS_TOKEN')
61
+ secret_token = 'MySecretToken'
62
+ content = 'RAILS_ENV=production'
63
+
64
+ Ccs::Document.new(destination, access_token, secret_token).upload(content)
65
+
66
+ Download
67
+
68
+ require 'ccs'
69
+
70
+ source = 'ccs://workspace-name/0.1.0/path/to/file.yml'
71
+ access_token = ENV.fetch('CCS_ACCESS_TOKEN')
72
+ secret_token = 'MySecretToken'
73
+
74
+ Ccs::Document.new(source, access_token, secret_token).download
75
+
24
76
  ## Development
25
77
 
26
78
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/exe/ccs CHANGED
@@ -12,59 +12,73 @@ options = {
12
12
  'secret_token' => ENV['CCS_SECRET_TOKEN']
13
13
  }
14
14
 
15
- option_parser = OptionParser.new
16
- option_parser.banner = 'Usage: ccs [OPTIONS] <(LocalPath|STDIN)|(CCSUri|Uri)> <(CCSUri|Uri)|(LocalPath|STDOUT)>'
17
- option_parser.separator ''
18
- option_parser.separator 'Configuration Control System (CCS)'
19
- option_parser.separator ''
20
- option_parser.separator 'Options:'
15
+ option_parser = OptionParser.new do |option_parser|
16
+ option_parser.banner = 'Usage: ccs [COMMAND [OPTIONS]]'
21
17
 
22
- option_parser.on('-c CONFIGURATION', '--configuration CONFIGURATION', String, 'Path to configuration file') do |v|
23
- options['configuration'] = v
24
- end
18
+ option_parser.separator ''
19
+ option_parser.separator 'Configuration Control System (CCS)'
20
+ option_parser.separator ''
21
+ option_parser.separator 'Commands:'
22
+ option_parser.separator ' cp Copy'
25
23
 
26
- option_parser.on('-a CCS_ACCESS_TOKEN', '--access-token CCS_ACCESS_TOKEN', String, 'CCS Access Token') do |v|
27
- options['access_token'] = v
24
+ option_parser.separator ''
25
+ option_parser.separator format('Version: %<version>s', version: Ccs::VERSION)
28
26
  end
29
27
 
30
- option_parser.on('-s CCS_SECRET_TOKEN', '--secret-token CCS_SECRET_TOKEN', String, 'CCS Secret Token') do |v|
31
- options['secret_token'] = v
32
- end
28
+ case ARGV.shift
29
+ when 'cp'
30
+ option_parser = OptionParser.new do |option_parser|
31
+ option_parser.banner = 'Usage: ccs cp [OPTIONS] <(LocalPath|STDIN)|(CCSUri|Uri)> <(CCSUri|Uri)|(LocalPath|STDOUT)>'
32
+ option_parser.separator ''
33
+ option_parser.separator 'Configuration Control System (CCS) - Copy'
34
+ option_parser.separator ''
35
+ option_parser.separator 'Options:'
33
36
 
34
- option_parser.separator ''
35
- option_parser.separator 'Configure via environment variables'
36
- option_parser.separator ' CCS_ACCESS_TOKEN'
37
- option_parser.separator ' CCS_SECRET_TOKEN'
37
+ option_parser.on('-a CCS_ACCESS_TOKEN', '--access-token CCS_ACCESS_TOKEN', String, 'CCS Access Token') do |v|
38
+ options['access_token'] = v
39
+ end
38
40
 
39
- option_parser.separator ''
40
- option_parser.separator 'Examples:'
41
- option_parser.separator ' Download to STDOUT'
42
- option_parser.separator ' ccs ccs://workspace-name/0.1.0/path/to/file.yml -'
43
- option_parser.separator ' ccs http://host.tld:9292/workspace-name/0.1.0/path/to/file.yml -'
44
- option_parser.separator ' ccs https://host.tld/workspace-name/0.1.0/path/to/file.yml -'
45
- option_parser.separator ' Download to local file'
46
- option_parser.separator ' ccs ccs://workspace-name/0.1.0/path/to/file.yml /local/path/to/file.yml'
47
- option_parser.separator ' Upload local file'
48
- option_parser.separator ' ccs /local/path/to/file.yml ccs://workspace-name/0.1.0/path/to/file.yml'
49
- option_parser.separator ' Upload content from STDIN'
50
- option_parser.separator ' echo "{ a: 1 }" | ccs - ccs://workspace-name/0.1.0/path/to/file.yml'
51
- option_parser.separator ' cat /local/path/to/file.yml | ccs - ccs://workspace-name/0.1.0/path/to/file.yml'
52
- option_parser.separator ''
41
+ option_parser.on('-s CCS_SECRET_TOKEN', '--secret-token CCS_SECRET_TOKEN', String, 'CCS Secret Token') do |v|
42
+ options['secret_token'] = v
43
+ end
53
44
 
54
- option_parser.separator format('Version: %<version>s', version: Ccs::VERSION)
45
+ option_parser.separator ''
46
+ option_parser.separator 'Configure via environment variables:'
47
+ option_parser.separator ' CCS_ACCESS_TOKEN'
48
+ option_parser.separator ' CCS_SECRET_TOKEN'
55
49
 
56
- arguments = option_parser.parse!
50
+ option_parser.separator ''
51
+ option_parser.separator 'Examples:'
52
+ option_parser.separator ' Download to STDOUT'
53
+ option_parser.separator ' ccs cp ccs://workspace-name/0.1.0/path/to/file.yml -'
54
+ option_parser.separator ' ccs cp http://host.tld:9292/workspace-name/0.1.0/path/to/file.yml -'
55
+ option_parser.separator ' ccs cp https://host.tld/workspace-name/0.1.0/path/to/file.yml -'
56
+ option_parser.separator ' Download to local file'
57
+ option_parser.separator ' ccs cp ccs://workspace-name/0.1.0/path/to/file.yml /local/path/to/file.yml'
58
+ option_parser.separator ' Upload local file'
59
+ option_parser.separator ' ccs cp /local/path/to/file.yml ccs://workspace-name/0.1.0/path/to/file.yml'
60
+ option_parser.separator ' Upload content from STDIN'
61
+ option_parser.separator ' echo "{ a: 1 }" | ccs cp - ccs://workspace-name/0.1.0/path/to/file.yml'
62
+ option_parser.separator ' cat /local/path/to/file.yml | ccs cp - ccs://workspace-name/0.1.0/path/to/file.yml'
63
+ option_parser.separator ''
57
64
 
58
- unless options.values.any?
59
- puts option_parser
60
- exit(1)
61
- end
65
+ option_parser.separator format('Version: %<version>s', version: Ccs::VERSION)
66
+ end
62
67
 
63
- options = YAML.safe_load File.read(options.delete('configuration')) if options.key?('configuration')
68
+ arguments = option_parser.parse!
64
69
 
65
- raise OptionParser::MissingArgument, 'access_token' unless options['access_token']
66
- raise OptionParser::MissingArgument, 'secret_token' unless options['secret_token']
67
- raise OptionParser::MissingArgument, 'source' unless arguments.fetch(0, nil)
68
- raise OptionParser::MissingArgument, 'destination' unless arguments.fetch(1, nil)
70
+ unless options.values.any?
71
+ puts option_parser
72
+ exit(1)
73
+ end
69
74
 
70
- exit(1) unless Ccs::Application.new(arguments[0], arguments[1], options['access_token'], options['secret_token']).run
75
+ raise OptionParser::MissingArgument, 'access_token' unless options['access_token']
76
+ raise OptionParser::MissingArgument, 'secret_token' unless options['secret_token']
77
+ raise OptionParser::MissingArgument, 'source' unless arguments.fetch(0, nil)
78
+ raise OptionParser::MissingArgument, 'destination' unless arguments.fetch(1, nil)
79
+
80
+ exit(1) unless Ccs::Commands::Copy.new(arguments[0], arguments[1], options['access_token'], options['secret_token']).call
81
+ else
82
+ puts option_parser
83
+ exit(1)
84
+ end
data/lib/ccs.rb CHANGED
@@ -11,7 +11,7 @@ require 'ccs/encrypter'
11
11
  require 'ccs/decrypter'
12
12
  require 'ccs/uploader'
13
13
  require 'ccs/downloader'
14
- require 'ccs/configuration_file'
15
- require 'ccs/application'
14
+ require 'ccs/document'
15
+ require 'ccs/commands/copy'
16
16
 
17
17
  module Ccs; end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ccs
4
+ module Commands
5
+ class Copy
6
+ def initialize(source, destination, access_token, secret_token)
7
+ @source = source
8
+ @destination = destination
9
+ @access_token = access_token
10
+ @secret_token = secret_token
11
+ end
12
+
13
+ def call
14
+ download? ? download : upload
15
+ end
16
+
17
+ private
18
+
19
+ def download?
20
+ @source.match?(%r{\A(ccs|https?):\/\/})
21
+ end
22
+
23
+ def download
24
+ content = Document.new(@source, @access_token, @secret_token).download
25
+ return unless content
26
+
27
+ (@destination.eql?('-') ? STDOUT : File.new(@destination, 'w')).print content
28
+ end
29
+
30
+ def upload
31
+ content = @source.eql?('-') ? STDIN.read : File.read(@source)
32
+ Document.new(@destination, @access_token, @secret_token).upload(content)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ccs
4
- class ConfigurationFile
4
+ class Document
5
5
  def initialize(uri, access_token, secret_token)
6
6
  @uri = build_uri(uri)
7
7
  @access_token = access_token
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ccs
4
- VERSION = '1.0.1'
4
+ VERSION = '2.0.0'
5
5
  end
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: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tkowalewski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inch
@@ -150,9 +150,9 @@ files:
150
150
  - README.md
151
151
  - exe/ccs
152
152
  - lib/ccs.rb
153
- - lib/ccs/application.rb
154
- - lib/ccs/configuration_file.rb
153
+ - lib/ccs/commands/copy.rb
155
154
  - lib/ccs/decrypter.rb
155
+ - lib/ccs/document.rb
156
156
  - lib/ccs/downloader.rb
157
157
  - lib/ccs/encrypter.rb
158
158
  - lib/ccs/uploader.rb
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ccs
4
- class Application
5
- def initialize(source, destination, access_token, secret_token)
6
- @source = source
7
- @destination = destination
8
- @access_token = access_token
9
- @secret_token = secret_token
10
- end
11
-
12
- def run
13
- download? ? download : upload
14
- end
15
-
16
- private
17
-
18
- def download?
19
- @source.match?(%r{\A(ccs|https?):\/\/})
20
- end
21
-
22
- def download
23
- content = ConfigurationFile.new(@source, @access_token, @secret_token).download
24
- return unless content
25
-
26
- (@destination.eql?('-') ? STDOUT : File.new(@destination, 'w')).print content
27
- end
28
-
29
- def upload
30
- content = @source.eql?('-') ? STDIN.read : File.read(@source)
31
- ConfigurationFile.new(@destination, @access_token, @secret_token).upload(content)
32
- end
33
- end
34
- end