Sha256: cf7773e4da8440b3777f7e7c22cc0de5251d3b231c2c3fc17f54d6261d9b6624

Contents?: true

Size: 981 Bytes

Versions: 6

Compression:

Stored size: 981 Bytes

Contents

require 'opsworks/resource'

module OpsWorks
  class Permission < Resource
    attr_accessor :id, :stack_id, :iam_user_arn, :ssh, :sudo

    def self.from_collection_response(response)
      response.data[:permissions].map do |hash|
        new(
          id: hash[:permission_id],
          stack_id: hash[:stack_id],
          iam_user_arn: hash[:iam_user_arn],
          sudo: hash[:allow_sudo],
          ssh: hash[:allow_ssh]
        )
      end
    end

    def user
      iam_user_arn.gsub(/^.*user\//, '')
    end

    def ssh?
      ssh
    end

    def sudo?
      sudo
    end

    def update(options = {})
      options[:ssh] = ssh if options[:ssh].nil?
      options[:sudo] = sudo if options[:sudo].nil?

      self.class.client.set_permission(
        stack_id: stack_id,
        iam_user_arn: iam_user_arn,
        allow_ssh: options[:ssh],
        allow_sudo: options[:sudo]
      )
      self.ssh = options[:ssh]
      self.sudo = options[:sudo]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opsworks-cli-0.3.2 lib/opsworks/permission.rb
opsworks-cli-0.3.1 lib/opsworks/permission.rb
opsworks-cli-0.3.0 lib/opsworks/permission.rb
opsworks-cli-0.2.4 lib/opsworks/permission.rb
opsworks-cli-0.2.3 lib/opsworks/permission.rb
opsworks-cli-0.2.2 lib/opsworks/permission.rb