cifrado 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ # Cifrado 0.1.1 - Sun 03 Mar 2013
2
+
3
+ * saio command improvements
4
+ * flavors: list flavors available
5
+ * images: list images available
6
+ * regions: list regions available
7
+ * Also added --disk-size bootstrap option to tweak the size
8
+ of the disk image created for Swift storage while bootstraping.
9
+ * Bootstrap now prints copy&paste ready configuration for cifrado.
10
+
11
+
12
+ ```
13
+ SLOC Directory SLOC-by-Language (Sorted)
14
+ 2057 lib ruby=1742,sh=315
15
+ 983 tests ruby=983
16
+
17
+
18
+ Totals grouped by language (dominant language first):
19
+ ruby: 2725 (89.64%)
20
+ sh: 315 (10.36%)
21
+
22
+
23
+
24
+
25
+ Total Physical Source Lines of Code (SLOC) = 3,040
26
+ Development Effort Estimate, Person-Years (Person-Months) = 0.64 (7.71)
27
+ (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
28
+ Schedule Estimate, Years (Months) = 0.45 (5.43)
29
+ (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
30
+ Estimated Average Number of Developers (Effort/Schedule) = 1.42
31
+ Total Estimated Cost to Develop = $ 86,828
32
+ (average salary = $56,286/year, overhead = 2.40).
33
+ SLOCCount, Copyright (C) 2001-2004 David A. Wheeler
34
+ SLOCCount is Open Source Software/Free Software, licensed under the GNU GPL.
35
+ ```
36
+
1
37
  # Cifrado 0.1 - Sun 03 Mar 2013
2
38
 
3
39
  * Uploading/downloading files and directories to OpenStack Swift.
data/README.md CHANGED
@@ -28,6 +28,8 @@ OpenStack Swift CLI with built in (GPG) encryption.
28
28
  Cifrado has a built-in help command:
29
29
 
30
30
  ```
31
+ $ cifrado help
32
+
31
33
  Tasks:
32
34
  cifrado cinema CONTAINER VIDEO # Stream videos from the target container
33
35
  cifrado delete CONTAINER [OBJECT] # Delete specific container or object
@@ -95,12 +97,12 @@ Install the gem:
95
97
  If you already have a Swift installation running,
96
98
  you can use 'cifrado setup' to configure Cifrado for the first time.
97
99
 
98
- Note that it's not strictly required to save the options or running the
99
- setup process. If you do so, you'll not be asked for the username,
100
+ The setup process is optional but highly recommended.
101
+ If you run setup, you won't be asked for the username,
100
102
  password, auth_url and other parameters required to run Cifrado.
101
103
 
102
- The setup command will ask you the OpenStack Swift authentication
103
- information:
104
+ The setup command will ask you for the OpenStack Swift authentication
105
+ parameters:
104
106
 
105
107
  $ cifrado setup
106
108
  Running cifrado setup...
@@ -116,7 +118,7 @@ information:
116
118
  Auth URL: https://identity.example.net/v2.0/tokens
117
119
  Do you want to save these settings? (y/n)
118
120
 
119
- There's an alternative way to setup cifrado and provision a Swift All-In-One
121
+ There's an alternative way to setup Cifrado and provision a Swift All-In-One
120
122
  server for testing and/or personal use. Head over to the Wiki for more
121
123
  details.
122
124
 
@@ -1,20 +1,23 @@
1
1
  module Cifrado
2
- class Saio < Thor
3
- include Cifrado::Utils
2
+ module Plugins
3
+ class Saio < Thor
4
+ include Cifrado::Utils
4
5
 
5
- class_option :provider, :type => :string
6
- class_option :api_key, :type => :string, :required => true
7
- class_option :client_id, :type => :string, :required => true
8
-
9
- private
10
- def service
11
- return @service if @service
12
- client_id = options[:client_id]
13
- api_key = options[:api_key]
14
- @service = Fog::Compute.new :provider => 'DigitalOcean',
15
- :digitalocean_api_key => api_key,
16
- :digitalocean_client_id => client_id
17
- end
6
+ class_option :provider, :type => :string
7
+ class_option :api_key, :type => :string, :required => true
8
+ class_option :client_id, :type => :string, :required => true
9
+
10
+ no_tasks do
11
+ def service
12
+ return @service if @service
13
+ client_id = options[:client_id]
14
+ api_key = options[:api_key]
15
+ @service = Fog::Compute.new :provider => 'DigitalOcean',
16
+ :digitalocean_api_key => api_key,
17
+ :digitalocean_client_id => client_id
18
+ end
19
+ end
18
20
 
21
+ end
19
22
  end
20
23
  end
@@ -1,118 +1,143 @@
1
1
  module Cifrado
2
- class Saio < Thor
3
-
4
- desc 'bootstrap', 'Bootstrap a Swift All-In-One installation'
5
- option :server_name, :type => :string, :default => 'cifrado-saio'
6
- option :ssh_key_name, :type => :string, :required => true
7
- option :save_settings, :type => :boolean
8
- option :bootstrap_debug, :type => :boolean
9
- def bootstrap
10
- require 'shexy'
11
-
12
- Log.level = Logger::DEBUG if options[:bootstrap_debug]
13
-
14
- begin
15
- available_keys = service.list_ssh_keys.body['ssh_keys']
16
- key = available_keys.find { |k| k['name'] == options[:ssh_key_name] }
17
- unless key
18
- raise "SSH key #{options[:ssh_key_name]} not available."
19
- end
2
+ module Plugins
3
+ class Saio < Thor
4
+
5
+ desc 'bootstrap', 'Bootstrap a Swift All-In-One installation'
6
+ option :server_name, :type => :string, :default => 'cifrado-saio'
7
+ option :ssh_key_name, :type => :string, :required => true
8
+ option :save_settings, :type => :boolean
9
+ option :bootstrap_debug, :type => :boolean
10
+ option :disk_size,
11
+ :type => :numeric,
12
+ :default => 15,
13
+ :desc => 'Virtual disk size for Swift (in GB)'
14
+ option :flavor,
15
+ :type => :string,
16
+ :desc => 'Flavor name to use when bootstraping',
17
+ :default => '512MB'
18
+ option :image,
19
+ :type => :string,
20
+ :desc => 'Image name to use when bootstraping',
21
+ :default => 'Ubuntu 12.04 x64 Server'
22
+ option :region,
23
+ :type => :string,
24
+ :desc => 'Region name to use when bootstraping',
25
+ :default => 'New York 1'
26
+ def bootstrap
27
+ require 'shexy'
20
28
 
21
- server_name = options[:server_name]
22
- server = service.servers.find { |s| s.name == server_name }
23
- if server
24
- raise "Server #{server_name} is currently running."
25
- end
29
+ Log.level = Logger::DEBUG if options[:bootstrap_debug]
26
30
 
27
- flavor = service.flavors.find { |f| f.name == '512MB' }
28
- image = service.images.find { |i| i.name == 'Ubuntu 12.04 x64 Server' }
29
- region = service.regions.first
30
- Log.info "Creating server #{server_name}..."
31
- server = service.servers.create :name => options[:server_name],
32
- :image_id => image.id,
33
- :flavor_id => flavor.id,
34
- :region_id => region.id,
35
- :ssh_key_ids => key['id']
36
- Log.info "Server provisioned, waiting for IP..."
37
- server.wait_for(120) { ip_address }
38
- Log.info "Server IP: #{server.ip_address}"
39
-
40
- #
41
- # Copy the provisioning script to the server
42
- #
43
- Shexy.host = server.ip_address
44
- Shexy.user = 'root'
45
- Shexy.flags = { :paranoid => false }
46
- Log.info 'Waiting for SSH...'
47
- Shexy.wait_for_ssh(90)
48
- Log.info 'Bootstraping Swift All-In-One (this may take a while)...'
49
-
50
- if RUBY_VERSION >= '1.9'
51
- secure_random = SecureRandom.hex.encode('UTF-8')
52
- user_password = SecureRandom.hex.encode('UTF-8')
53
- else
54
- user_password = SecureRandom.hex
55
- secure_random = SecureRandom.hex
56
- end
57
-
58
- script = bootstrap_script(user_password)
59
- Shexy.copy_to script, '/root/saio.sh'
31
+ begin
32
+ available_keys = service.list_ssh_keys.body['ssh_keys']
33
+ key = available_keys.find { |k| k['name'] == options[:ssh_key_name] }
34
+ unless key
35
+ raise "SSH key #{options[:ssh_key_name]} not available."
36
+ end
60
37
 
61
- # Provision Swift+Keystone
62
- Shexy.exe '/bin/bash /root/saio.sh' do |out, err|
63
- out.each_line { |l| Log.debug l }
64
- end
38
+ server_name = options[:server_name]
39
+ server = service.servers.find { |s| s.name == server_name }
40
+ if server
41
+ raise "Server #{server_name} is currently running."
42
+ end
43
+
44
+ flavor = service.flavors.find { |f| f.name == options[:flavor] }
45
+ image = service.images.find { |i| i.name == options[:image] }
46
+ region = service.regions.find { |r| r.name == options[:region] }
47
+
48
+ unless image and flavor and region
49
+ raise "The specified image, flavor or region was not found"
50
+ end
51
+
52
+ Log.info "Creating server #{server_name}..."
53
+ server = service.servers.create :name => options[:server_name],
54
+ :image_id => image.id,
55
+ :flavor_id => flavor.id,
56
+ :region_id => region.id,
57
+ :ssh_key_ids => key['id']
58
+ Log.info "Server provisioned, waiting for IP..."
59
+ server.wait_for(120) { ip_address }
60
+ Log.info "Server IP: #{server.ip_address}"
61
+
62
+ #
63
+ # Copy the provisioning script to the server
64
+ #
65
+ Shexy.host = server.ip_address
66
+ Shexy.user = 'root'
67
+ Shexy.flags = { :paranoid => false }
68
+ Log.info 'Waiting for SSH...'
69
+ Shexy.wait_for_ssh(90)
70
+ Log.info 'Bootstraping Swift All-In-One (this may take a while)...'
65
71
 
66
- config = {
67
- :auth_url => "https://#{server.ip_address}:5000/v2.0/tokens",
68
- :username => 'admin',
69
- :tenant => 'admin',
70
- :password => user_password,
71
- :secure_random => secure_random
72
- }
73
-
74
- # Provisioning finished, print details
75
- Log.info
76
- Log.info 'Swift is ready. Login details:'
77
- Log.info
78
- Log.info "auth_url: https://#{server.ip_address}:5000/v2.0/tokens"
79
- Log.info "username: admin"
80
- Log.info "tenant: admin"
81
- Log.info "password: #{user_password}"
82
- Log.info "secure_random: #{secure_random}"
83
- Log.info
84
-
85
- save_settings(config) if options[:save_settings]
86
- rescue Excon::Errors::Found => e
87
- raise "Authentication failed"
72
+ if RUBY_VERSION >= '1.9'
73
+ secure_random = SecureRandom.hex.encode('UTF-8')
74
+ user_password = SecureRandom.hex.encode('UTF-8')
75
+ else
76
+ user_password = SecureRandom.hex
77
+ secure_random = SecureRandom.hex
78
+ end
79
+
80
+ script = bootstrap_script(user_password, options[:disk_size])
81
+ Shexy.copy_to script, '/root/saio.sh'
82
+
83
+ # Provision Swift+Keystone
84
+ Shexy.exe '/bin/bash /root/saio.sh' do |out, err|
85
+ out.each_line { |l| Log.debug l }
86
+ end
87
+
88
+ config = {
89
+ :auth_url => "https://#{server.ip_address}:5000/v2.0/tokens",
90
+ :username => 'admin',
91
+ :tenant => 'admin',
92
+ :password => user_password,
93
+ :secure_random => secure_random
94
+ }
95
+
96
+ # Provisioning finished, print details
97
+ Log.info
98
+ Log.info 'Swift is ready. Login details:'
99
+ Log.info
100
+ Log.info "---"
101
+ Log.info ":auth_url: https://#{server.ip_address}:5000/v2.0/tokens"
102
+ Log.info ":username: admin"
103
+ Log.info ":tenant: admin"
104
+ Log.info ":password: #{user_password}"
105
+ Log.info ":secure_random: #{secure_random}"
106
+ Log.info
107
+
108
+ save_settings(config) if options[:save_settings]
109
+ rescue Excon::Errors::Found => e
110
+ raise "Authentication failed"
111
+ end
112
+ server
88
113
  end
89
- end
90
114
 
91
- private
92
- def save_settings(config)
93
- config_file = File.join(ENV['HOME'], '.config/cifrado/cifradorc')
94
- FileUtils.mkdir_p File.join(ENV['HOME'], '.config/cifrado')
95
- if File.exist?(config_file)
96
- raise 'Cifrado config file exists. Refusing to overwrite.'
97
- else
98
- Log.info "Saving settings to #{config_file} as requested."
99
- File.open config_file, 'w' do |f|
100
- f.puts config.to_yaml
115
+ private
116
+ def save_settings(config)
117
+ config_file = File.join(ENV['HOME'], '.config/cifrado/cifradorc')
118
+ FileUtils.mkdir_p File.join(ENV['HOME'], '.config/cifrado')
119
+ if File.exist?(config_file)
120
+ raise 'Cifrado config file exists. Refusing to overwrite.'
121
+ else
122
+ Log.info "Saving settings to #{config_file} as requested."
123
+ File.open config_file, 'w' do |f|
124
+ f.puts config.to_yaml
125
+ end
101
126
  end
102
127
  end
103
- end
104
128
 
105
- def bootstrap_script(password)
106
- require 'erb'
107
- template = File.join(File.dirname(__FILE__), 'scripts/saio.sh.erb')
108
- result = ERB.new(File.read(template)).result(binding)
109
- tmpfile = "/tmp/#{SecureRandom.hex}"
110
- File.open tmpfile, 'w' do |f|
111
- f.puts result
129
+ def bootstrap_script(password, disk_size = 15)
130
+ require 'erb'
131
+ template = File.join(File.dirname(__FILE__), 'scripts/saio.sh.erb')
132
+ result = ERB.new(File.read(template)).result(binding)
133
+ tmpfile = "/tmp/#{SecureRandom.hex}"
134
+ File.open tmpfile, 'w' do |f|
135
+ f.puts result
136
+ end
137
+ tmpfile
112
138
  end
113
- tmpfile
114
- end
115
139
 
140
+ end
116
141
  end
117
142
  end
118
143
 
@@ -1,16 +1,21 @@
1
1
  module Cifrado
2
- class Saio < Thor
2
+ module Plugins
3
+ class Saio < Thor
3
4
 
4
- desc 'destroy', 'Destroy bootstrapped server'
5
- option :server_name, :type => :string, :default => 'cifrado-saio'
6
- def destroy
7
- s = service.servers.find {|s| s.name == options[:server_name] }
8
- if s
9
- Log.info "Destroying server #{options[:server_name]}."
10
- s.destroy
5
+ desc 'destroy', 'Destroy bootstrapped server'
6
+ option :server_name, :type => :string, :default => 'cifrado-saio'
7
+ def destroy
8
+ s = service.servers.find {|s| s.name == options[:server_name] }
9
+ if s
10
+ Log.info "Destroying server #{options[:server_name]}."
11
+ s.destroy
12
+ true
13
+ else
14
+ false
15
+ end
11
16
  end
12
- end
13
17
 
18
+ end
14
19
  end
15
20
  end
16
21
 
@@ -0,0 +1,17 @@
1
+ module Cifrado
2
+ module Plugins
3
+ class Saio
4
+
5
+ desc 'flavors', 'List image flavors available'
6
+ def flavors
7
+ flavors = service.flavors.all
8
+ flavors.each do |f|
9
+ Log.info "[#{f.id}]".ljust(5) + " #{f.name}"
10
+ end
11
+ flavors
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ module Cifrado
2
+ module Plugins
3
+ class Saio
4
+
5
+ desc 'images', 'List images available'
6
+ def images
7
+ images = service.images.all
8
+ images.each do |i|
9
+ Log.info "[#{i.id}]".ljust(10) + " #{i.name}"
10
+ end
11
+ images
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ module Cifrado
2
+ module Plugins
3
+ class Saio
4
+
5
+ desc 'regions', 'List regions available'
6
+ def regions
7
+ regions = service.regions.all
8
+ service.regions.each do |r|
9
+ Log.info "[#{r.id}]".ljust(10) + " #{r.name}"
10
+ end
11
+ regions
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
@@ -5,7 +5,7 @@ set -e
5
5
  # SETUP VARIABLES
6
6
  #
7
7
  # In GB
8
- SWIFT_DISK_SIZE=15
8
+ SWIFT_DISK_SIZE=<%= disk_size %>
9
9
  # keystone variables
10
10
  PASSWORD=<%= password %>
11
11
  KROLE=admin
@@ -3,9 +3,12 @@ require 'cifrado/cli/saio/base'
3
3
  module Cifrado
4
4
  class CLI
5
5
  desc "saio SUBCOMMAND ...ARGS", "Bootstrap a Swift installation"
6
- subcommand "saio", Saio
6
+ subcommand "saio", Cifrado::Plugins::Saio
7
7
  end
8
8
  end
9
9
 
10
10
  require 'cifrado/cli/saio/bootstrap'
11
11
  require 'cifrado/cli/saio/destroy'
12
+ require 'cifrado/cli/saio/flavors'
13
+ require 'cifrado/cli/saio/images'
14
+ require 'cifrado/cli/saio/regions'
@@ -1,3 +1,3 @@
1
1
  module Cifrado
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
data/tests/helper.rb CHANGED
@@ -11,6 +11,10 @@ unless ENV['DEBUG']
11
11
  Cifrado::Log.level = Logger::ERROR
12
12
  end
13
13
 
14
+ def fog_settings
15
+ YAML.load_file(File.expand_path('~/.fog'))[:default]
16
+ end
17
+
14
18
  def client
15
19
  conf = YAML.load_file File.expand_path("~/.config/cifrado/cifradorc")
16
20
  client = SwiftClient.new :username => conf[:username],
@@ -0,0 +1,35 @@
1
+ Shindo.tests('Cifrado | CLI#saio', ['expensive']) do
2
+
3
+ tests '#bootstrap' do
4
+
5
+ Cifrado::Plugins::Saio.class_options[:api_key] = \
6
+ Thor::Option.parse :api_key, fog_settings[:digitalocean_api_key]
7
+ Cifrado::Plugins::Saio.class_options[:client_id] = \
8
+ Thor::Option.parse :client_id, fog_settings[:digitalocean_client_id]
9
+ cli = Cifrado::Plugins::Saio.new
10
+
11
+ test '512MB image' do
12
+ #
13
+ # FIXME: find a way to test default options
14
+ #
15
+ cli.options = {
16
+ :client_id => fog_settings[:digitalocean_client_id],
17
+ :api_key => fog_settings[:digitalocean_api_key],
18
+ :ssh_key_name => 'personal',
19
+ :server_name => 'cifrado-saio-tests',
20
+ :flavor => '512MB',
21
+ :region => 'New York 1',
22
+ :image => 'Ubuntu 12.04 x64 Server',
23
+ :disk_size => 15,
24
+ }.merge(cli.options)
25
+ @server = cli.bootstrap
26
+ !(cli.service.servers.find { |s| s.name == @server.name }).nil?
27
+ end
28
+
29
+ test 'destroy server' do
30
+ @server.destroy.status == 200
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,14 @@
1
+ Shindo.tests('Cifrado | CLI#saio') do
2
+
3
+ tests '#flavors' do
4
+ test 'list' do
5
+ Cifrado::Plugins::Saio.class_options[:api_key] = \
6
+ Thor::Option.parse :api_key, fog_settings[:digitalocean_api_key]
7
+ Cifrado::Plugins::Saio.class_options[:client_id] = \
8
+ Thor::Option.parse :client_id, fog_settings[:digitalocean_client_id]
9
+ cli = Cifrado::Plugins::Saio.new
10
+ cli.flavors.size > 0
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ Shindo.tests('Cifrado | CLI#saio') do
2
+
3
+ tests '#images' do
4
+ test 'list' do
5
+ Cifrado::Plugins::Saio.class_options[:api_key] = \
6
+ Thor::Option.parse :api_key, fog_settings[:digitalocean_api_key]
7
+ Cifrado::Plugins::Saio.class_options[:client_id] = \
8
+ Thor::Option.parse :client_id, fog_settings[:digitalocean_client_id]
9
+ cli = Cifrado::Plugins::Saio.new
10
+ cli.images.size > 0
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ Shindo.tests('Cifrado | CLI#saio') do
2
+
3
+ tests '#regions' do
4
+ test 'list' do
5
+ Cifrado::Plugins::Saio.class_options[:api_key] = \
6
+ Thor::Option.parse :api_key, fog_settings[:digitalocean_api_key]
7
+ Cifrado::Plugins::Saio.class_options[:client_id] = \
8
+ Thor::Option.parse :client_id, fog_settings[:digitalocean_client_id]
9
+ cli = Cifrado::Plugins::Saio.new
10
+ cli.regions.size > 0
11
+ end
12
+ end
13
+
14
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cifrado
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,7 +37,7 @@ cert_chain:
37
37
  VmpCY252Rk9HWThmMzJoVnE2MTlRaUpWcFY5elJnWWE1TTA1bVdSbXdIQnly
38
38
  YjR5SzBBYgozR3B5dU1NTkJNaz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0t
39
39
  LQo=
40
- date: 2013-03-02 00:00:00.000000000 Z
40
+ date: 2013-03-03 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: excon
@@ -215,6 +215,9 @@ files:
215
215
  - lib/cifrado/cli/saio/base.rb
216
216
  - lib/cifrado/cli/saio/bootstrap.rb
217
217
  - lib/cifrado/cli/saio/destroy.rb
218
+ - lib/cifrado/cli/saio/flavors.rb
219
+ - lib/cifrado/cli/saio/images.rb
220
+ - lib/cifrado/cli/saio/regions.rb
218
221
  - lib/cifrado/cli/saio/scripts/saio.sh.erb
219
222
  - lib/cifrado/cli/set_acl.rb
220
223
  - lib/cifrado/cli/setup.rb
@@ -237,6 +240,10 @@ files:
237
240
  - tests/crypto_services_tests.rb
238
241
  - tests/file_splitter_tests.rb
239
242
  - tests/helper.rb
243
+ - tests/saio/bootstrap_tests.rb
244
+ - tests/saio/flavors_tests.rb
245
+ - tests/saio/images_tests.rb
246
+ - tests/saio/regions_tests.rb
240
247
  - tests/swift_client/create_directory.rb
241
248
  - tests/swift_client/download_tests.rb
242
249
  - tests/swift_client/file_available.rb
metadata.gz.sig CHANGED
Binary file