acquia-cloud 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 685097e8f39140c8daeca6baa20bf778f29b6dee
4
- data.tar.gz: 204cf2742df26dcf42e7f1421b498bd9f10fa149
3
+ metadata.gz: 378a385311c7673298dbe5778ef1dd8912747e2f
4
+ data.tar.gz: 996ea862278d8dd599eec653229d497fdae48df0
5
5
  SHA512:
6
- metadata.gz: ad543deb62c21a489b45fbee05cd86f7b87234f5238b9fd636bc7ced1b79c29aae9d920c91cfe108672d13bfcee7e717fce937c909ae1bf2e32c42fa27b64756
7
- data.tar.gz: 8c3ab4d962bf59e950a0730c4ddbdb053f275c5561da3577bcb56bdc54dd32bf72053c9f36ada87ace5faa3b2ff7991e46da6b1e66a648446793b2d33e62148c
6
+ metadata.gz: 916d7976911b07dec1549c8076c99e789b927518b78d6570048bc19d56c8af27dfaa5ec0a46467ff38190d4e1366cff7fc1bf7125375c585b7c871755a8ac2b3
7
+ data.tar.gz: 1f16c986fa7637ca0ec76c9fa12912d33d986007ce88363ceaf6076eaf1da0566d606031cf784797f81b5992972f08f70d78fc9926e8ac3f76b7f5c742f2b210
@@ -5,6 +5,8 @@ module Acquia
5
5
  API_VERSION = 'v1'
6
6
  BASE_URL = 'https://cloudapi.acquia.com'
7
7
 
8
+ attr_reader :credentials
9
+
8
10
  def initialize(args = {})
9
11
  @acquia = Faraday.new(:url => 'https://cloudapi.acquia.com') do |client|
10
12
  client.request :url_encoded
@@ -25,11 +27,11 @@ module Acquia
25
27
  args[:credentials] = ENV['ACQUIA_CLOUD_CREDENTIALS']
26
28
  end
27
29
 
28
- credentials = args[:credentials].split(':', 2)
29
- if credentials.length < 2
30
+ @credentials = args[:credentials].split(':', 2)
31
+ if @credentials.length < 2
30
32
  raise 'You must specify both username and API key in credentials.'
31
33
  end
32
- @acquia.basic_auth *credentials
34
+ @acquia.basic_auth *@credentials
33
35
  end
34
36
 
35
37
  def get(url = nil, params = nil, headers = nil, &block)
@@ -14,15 +14,20 @@ module Acquia
14
14
  data['name']
15
15
  end
16
16
 
17
+ def on_environment(environment)
18
+ DatabaseEnvironment.new(@cloud, @site, environment, {'name' => name}).refresh
19
+ end
20
+
17
21
  def copy(from, to)
18
22
  from = standardise_env(from)
19
23
  to = standardise_env(to)
20
- task = @cloud.api.post("#{@url}/db-copy/#{from}/#{to}")
24
+ task = @cloud.api.post("/sites/#{@site}/dbs/#{name}/db-copy/#{from}/#{to}")
21
25
  Task.new @cloud, @site, task
22
26
  end
23
27
 
24
28
  def backup_on(environment)
25
- @cloud.site(@site).environment(environment).backup_database(name)
29
+ task = @cloud.api.post("/sites/#{@site}/envs/#{environment}/dbs/#{name}/backups")
30
+ Task.new @cloud, @site, task
26
31
  end
27
32
 
28
33
  private
@@ -0,0 +1,79 @@
1
+ require 'acquia/cloud/entity'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module Acquia
6
+ class Cloud
7
+ class DatabaseBackup < Entity
8
+ include Operations::Delete
9
+
10
+ def initialize(cloud, site, environment, database, backup)
11
+ @cloud = cloud
12
+ @site = site
13
+ @environment = environment
14
+ @database = database
15
+ @data = backup
16
+ @url = "/sites/#{@site}/envs/#{@environment}/dbs/#{@database}/backups/#{data['id']}"
17
+ end
18
+
19
+ def id
20
+ data['id']
21
+ end
22
+
23
+ def checksum
24
+ data['checksum']
25
+ end
26
+
27
+ def deleted?
28
+ data['deleted'] != '0'
29
+ end
30
+
31
+ def name
32
+ data['name']
33
+ end
34
+
35
+ def path
36
+ data['path']
37
+ end
38
+
39
+ def started
40
+ Time.at(data['started'].to_i)
41
+ end
42
+
43
+ def completed
44
+ Time.at(data['completed'].to_i)
45
+ end
46
+
47
+ def type
48
+ data['type']
49
+ end
50
+
51
+ def link
52
+ data['link']
53
+ end
54
+
55
+ def download_to(path, &block)
56
+ uri = URI.parse(link)
57
+
58
+ File.open(path, 'wb') do |io|
59
+ https = uri.scheme == 'https'
60
+ Net::HTTP.start(uri.host, uri.port, use_ssl: https) do |http|
61
+ request = Net::HTTP::Get.new uri
62
+ request.basic_auth *@cloud.api.credentials
63
+
64
+ http.request request do |response|
65
+ response.read_body do |chunk|
66
+ io.write chunk
67
+ block.call(response, chunk) if block_given?
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def download(&block)
75
+ download_to(File.basename(path), &block)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,49 @@
1
+ require 'acquia/cloud/entity'
2
+
3
+ module Acquia
4
+ class Cloud
5
+ class DatabaseEnvironment < Database
6
+ def initialize(cloud, site, environment, database)
7
+ @cloud = cloud
8
+ @site = site
9
+ @environment = environment
10
+ @data = database
11
+ @url = "/sites/#{@site}/envs/#{@environment}/dbs/#{@data['name']}"
12
+ end
13
+
14
+ def db_cluster
15
+ data['db_cluster']
16
+ end
17
+
18
+ def host
19
+ data['host']
20
+ end
21
+
22
+ def instance_name
23
+ data['instance_name']
24
+ end
25
+
26
+ def username
27
+ data['username']
28
+ end
29
+
30
+ def password
31
+ data['password']
32
+ end
33
+
34
+ def create_backup
35
+ backup_on(@environment)
36
+ end
37
+
38
+ def backups
39
+ @cloud.api.get("#{@url}/backups").map do |backup|
40
+ DatabaseBackup.new(@cloud, @site, @environment, name, backup)
41
+ end
42
+ end
43
+
44
+ def backup(id)
45
+ DatabaseBackup.new(@cloud, @site, @environment, name, {'id' => id})
46
+ end
47
+ end
48
+ end
49
+ end
@@ -3,6 +3,8 @@ require 'acquia/cloud/entity'
3
3
  module Acquia
4
4
  class Cloud
5
5
  class Domain < Entity
6
+ include Operations::Delete
7
+
6
8
  def initialize(cloud, site, env, domain)
7
9
  @cloud = cloud
8
10
  @site = site
@@ -15,11 +17,7 @@ module Acquia
15
17
  data['name']
16
18
  end
17
19
 
18
- def delete
19
- @cloud.api.delete @url
20
- end
21
-
22
- def purge_varnish
20
+ def purge_varnish!
23
21
  @cloud.api.delete "#{@url}/cache"
24
22
  end
25
23
  end
@@ -1,3 +1,4 @@
1
+ require 'acquia/cloud/operations/delete'
1
2
 
2
3
  module Acquia
3
4
  class Cloud
@@ -44,9 +44,14 @@ module Acquia
44
44
  Task.new(@cloud, @site, task)
45
45
  end
46
46
 
47
- def backup_database(database_name)
48
- task = @cloud.api.post("#{@url}/dbs/#{database_name}/backups")
49
- Task.new @cloud, @site, task
47
+ def databases
48
+ @cloud.api.get("#{@url}/dbs").map do |db|
49
+ DatabaseEnvironment.new(@cloud, @site, name, db)
50
+ end
51
+ end
52
+
53
+ def database(database)
54
+ DatabaseEnvironment.new(@cloud, @site, name, {'name' => database}).refresh
50
55
  end
51
56
 
52
57
  def logstream
@@ -55,7 +60,7 @@ module Acquia
55
60
  end
56
61
 
57
62
  def servers
58
- @cloud.api.get("#{url}/servers").map do |server|
63
+ @cloud.api.get("#{@url}/servers").map do |server|
59
64
  Server.new(@cloud, @site, name, server)
60
65
  end
61
66
  end
@@ -0,0 +1,12 @@
1
+
2
+ module Acquia
3
+ class Cloud
4
+ module Operations
5
+ module Delete
6
+ def delete!
7
+ Task.new @cloud, @site, @cloud.api.delete(@url)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Acquia
2
2
  class Cloud
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
data/lib/acquia/cloud.rb CHANGED
@@ -32,6 +32,8 @@ end
32
32
  errors
33
33
  api
34
34
  database
35
+ database_backup
36
+ database_environment
35
37
  domain
36
38
  environment
37
39
  server
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acquia-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Equiem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -85,12 +85,15 @@ files:
85
85
  - lib/acquia/cloud.rb
86
86
  - lib/acquia/cloud/api.rb
87
87
  - lib/acquia/cloud/database.rb
88
+ - lib/acquia/cloud/database_backup.rb
89
+ - lib/acquia/cloud/database_environment.rb
88
90
  - lib/acquia/cloud/domain.rb
89
91
  - lib/acquia/cloud/entity.rb
90
92
  - lib/acquia/cloud/environment.rb
91
93
  - lib/acquia/cloud/errors.rb
92
94
  - lib/acquia/cloud/logs/source.rb
93
95
  - lib/acquia/cloud/logs/streamer.rb
96
+ - lib/acquia/cloud/operations/delete.rb
94
97
  - lib/acquia/cloud/server.rb
95
98
  - lib/acquia/cloud/site.rb
96
99
  - lib/acquia/cloud/task.rb