Sha256: adca1e5c4de2bff2714cdc5078c7038d99d4f323854a21e577b6790fe4cea102

Contents?: true

Size: 1.79 KB

Versions: 5

Compression:

Stored size: 1.79 KB

Contents

require 'ace-client/niftycloud/computing'
require 'ace-client/niftycloud/rdb'

module Ruboty
  module Niftycloud
    module Actions
      class Base
        NAMESPACE = "niftycloud"

        attr_reader :message

        def initialize(message)
          @message = message
        end

        def accounts
          ENV["NIFTYCLOUD_ACCOUNTS"].split(",").map do |account|
            {
              name: account,
              description: ENV["NIFTYCLOUD_ACCOUNT_#{account}_DESCRIPTION"],
              access_key_id: ENV["NIFTYCLOUD_ACCOUNT_#{account}_ACCESS_KEY_ID"],
              secret_access_key: ENV["NIFTYCLOUD_ACCOUNT_#{account}_SECRET_ACCESS_KEY"],
            }
          end
        end

        def current_account(account=nil)
          message.robot.brain.data[NAMESPACE] ||= {}
          if account
            message.robot.brain.data[NAMESPACE]["current_account"] = account
          else
            name = message.robot.brain.data[NAMESPACE]["current_account"] || ENV["NIFTYCLOUD_DEFAULT_ACCOUNT"]
            accounts.find {|account| account[:name] == name }
          end
        end

        def current_region(region=nil)
          message.robot.brain.data[NAMESPACE] ||= {}
          if region
            message.robot.brain.data[NAMESPACE]["current_region"] = region
          else
            message.robot.brain.data[NAMESPACE]["current_region"] || 'east-1'
          end 
        end

        def computing
          AceClient::Niftycloud::Computing.build_client(
            current_account.merge(endpoint: "#{current_region}.cp.cloud.nifty.com", path: '/api')
          )
        end

        def rdb
          AceClient::Niftycloud::Rdb.build_client(
            current_account.merge(endpoint: "rdb.jp-#{current_region}.api.cloud.nifty.com")
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruboty-niftycloud-0.0.5 lib/ruboty/niftycloud/actions/base.rb
ruboty-niftycloud-0.0.4 lib/ruboty/niftycloud/actions/base.rb
ruboty-niftycloud-0.0.3 lib/ruboty/niftycloud/actions/base.rb
ruboty-niftycloud-0.0.2 lib/ruboty/niftycloud/actions/base.rb
ruboty-niftycloud-0.0.1 lib/ruboty/niftycloud/actions/base.rb