Class: ScalingoBackupsManager::Addon
- Inherits:
-
Object
- Object
- ScalingoBackupsManager::Addon
- Defined in:
- lib/scalingo_backups_manager/addon.rb
Constant Summary collapse
- DEFAULT_DATABASE_API_ROOT_URL =
"https://db-api.osc-fr1.scalingo.com"
Instance Attribute Summary collapse
-
#addon ⇒ Object
Returns the value of attribute addon.
-
#application ⇒ Object
Returns the value of attribute application.
-
#config ⇒ Object
Returns the value of attribute config.
-
#sftp_config ⇒ Object
Returns the value of attribute sftp_config.
Class Method Summary collapse
Instance Method Summary collapse
- #backups ⇒ Object
- #client(options: {}) ⇒ Object
- #database_api_url(options: {}) ⇒ Object
-
#initialize(app, addon, config: {}, sftp_config: {}) ⇒ Addon
constructor
A new instance of Addon.
Constructor Details
#initialize(app, addon, config: {}, sftp_config: {}) ⇒ Addon
Returns a new instance of Addon.
17 18 19 20 21 22 23 |
# File 'lib/scalingo_backups_manager/addon.rb', line 17 def initialize(app, addon, config: {}, sftp_config: {}) raise "Application must be set" unless app && app.is_a?(ScalingoBackupsManager::Application) @application = app @addon = addon @sftp_config = sftp_config @config = config end |
Instance Attribute Details
#addon ⇒ Object
Returns the value of attribute addon.
8 9 10 |
# File 'lib/scalingo_backups_manager/addon.rb', line 8 def addon @addon end |
#application ⇒ Object
Returns the value of attribute application.
8 9 10 |
# File 'lib/scalingo_backups_manager/addon.rb', line 8 def application @application end |
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/scalingo_backups_manager/addon.rb', line 8 def config @config end |
#sftp_config ⇒ Object
Returns the value of attribute sftp_config.
8 9 10 |
# File 'lib/scalingo_backups_manager/addon.rb', line 8 def sftp_config @sftp_config end |
Class Method Details
.find(app, id, config: {}, sftp_config: {}) ⇒ Object
12 13 14 15 |
# File 'lib/scalingo_backups_manager/addon.rb', line 12 def self.find(app, id, config: {}, sftp_config: {}) addon = Configuration.client.addons.find(app.id, id).data self.new(app, addon, config: config, sftp_config: sftp_config) end |
Instance Method Details
#backups ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/scalingo_backups_manager/addon.rb', line 54 def backups response = client.authenticated_connection.get("#{database_api_url}/backups").body return [] unless response[:database_backups] && response[:database_backups].size > 0 bcks = [] response[:database_backups].each do |backup| bcks.push ScalingoBackupsManager::Backup.new(self, backup[:id]) end bcks end |
#client(options: {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/scalingo_backups_manager/addon.rb', line 31 def client(options: {}) return @client if @client scalingo = Scalingo::Client.new scalingo.authenticate_with(access_token: ENV["SCALINGO_API_TOKEN"]) response = scalingo.addons.token(application.id, id).data if response.try(:[], :token) bearer_token = response[:token] else raise "An error occured during addon authentication" end addon_cli_config = Scalingo::Client.new addon_cli_config.token = bearer_token @client = Scalingo::API::Client.new(database_api_url(options: ), scalingo: addon_cli_config) end |
#database_api_url(options: {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/scalingo_backups_manager/addon.rb', line 25 def database_api_url(options: {}) return @database_api_url if @database_api_url @database_api_url = "#{options[:database_api_root_url] || DEFAULT_DATABASE_API_ROOT_URL}/api/databases/#{id}" end |