Class: Titantic
- Inherits:
-
Thor
- Object
- Thor
- Titantic
- Defined in:
- lib/titantic/titantic.rb
Instance Method Summary collapse
- #create_vault(vault_name) ⇒ Object
- #delete_vault(vault_name) ⇒ Object
-
#initialize(args = [], options = {}, configs = {}) ⇒ Titantic
constructor
A new instance of Titantic.
- #list_vaults ⇒ Object
- #upload_archive(vault_name, body, options = {}) ⇒ Object
Constructor Details
#initialize(args = [], options = {}, configs = {}) ⇒ Titantic
Returns a new instance of Titantic.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/titantic/titantic.rb', line 8 def initialize(args = [], = {}, configs = {}) super if File.exists?('.titantic') config = YAML.load_file('.titantic') elsif File.exists?(File.join(Dir.home, '.titantic')) config = YAML.load_file(File.join(Dir.home, '.titantic')) else if(ENV['TITANTIC_CONFIG']) File.exists?(ENV['TITANTIC_CONFIG']) config = YAML.load_file(ENV['TITANTIC_CONFIG']) end end unless config puts "Could not load configuration." puts "Titantic configuration is YAML format and must exist in 1 of 3 places" puts "1. in the current directory as a file named '.titantic' " puts "2. in the current user's home directory as a file named '.titantic' " puts "3. as a file path specified by the environment variable 'TITANTIC_CONFIG'" end @glacier = Fog::AWS::Glacier.new config end |
Instance Method Details
#create_vault(vault_name) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/titantic/titantic.rb', line 58 def create_vault(vault_name) begin vault = @glacier.vaults.create :id => vault_name rescue Exception => e print [ status: 'error', error: e.to_s] end print vault.to_json end |
#delete_vault(vault_name) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/titantic/titantic.rb', line 68 def delete_vault(vault_name) vault = @glacier.vaults.get vault_name unless vault print Hash[ status: 'error', error: "Vault #{vault_name} does not exist" ].to_json return end print @glacier.delete_vault(vault_name).data.to_json end |
#list_vaults ⇒ Object
78 79 80 81 |
# File 'lib/titantic/titantic.rb', line 78 def list_vaults response = @glacier.list_vaults print response.data[:body]["VaultList"].collect{ |v| v["VaultName"] }.to_json end |
#upload_archive(vault_name, body, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/titantic/titantic.rb', line 34 def upload_archive(vault_name, body, = {}) vault = @glacier.vaults.get vault_name unless vault print Hash[ status: 'error', error: "Vault #{vault_name} does not exist" ].to_json return end unless File.exists?(body) print Hash[ status: 'error', error: "Archive #{body} does not exist" ].to_json return end body = File.read(body) response = @glacier.create_archive(vault_name, body, ) if response.status == 201 print Hash[ status: 'success' ].to_json return end print [ status: 'error', error: response.headers ].to_json end |