-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathalicloud_ram_access_key.rb
57 lines (49 loc) · 1.44 KB
/
alicloud_ram_access_key.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'alicloud_backend'
class AliCloudAccessKey < AliCloudResourceBase
name 'alicloud_access_key'
desc 'Verifies properties of an AliCloud Access Key.'
example <<-EXAMPLE
# Check if the AccessKey is active
describe alicloud_access_key("ACCESS_KEY_ID") do
its('status') { should eq 'Active' }
end
EXAMPLE
attr_reader :access_key_id, :status, :create_date
def initialize(opts = {})
opts = { access_key_id: opts } if opts.is_a?(String)
@opts = opts
super(opts)
validate_parameters(required: %i(access_key_id), allow: %i(user_name))
@opts = opts
catch_alicloud_errors do
params = { "RegionId": opts[:region] }
params[:UserName] = opts[:user_name] if opts.key?(:user_name)
@keys = @alicloud.ram_client.request(
action: 'ListAccessKeys',
params: params,
opts: {
method: 'POST',
},
)['AccessKeys']['AccessKey']
@keys.map do |key|
# rubocop:disable Style/Next
if key['AccessKeyId'] == opts[:access_key_id]
@access_key_id = key['AccessKeyId']
@status = key['Status']
@create_date = key['CreateDate']
break
end
# rubocop:enable Style/Next
end
end
end
def exists?
!@access_key_id.nil?
end
def resource_id
"#{@access_key_id || @opts[:access_key_id]}_#{@opts[:region]}"
end
def to_s
"AliCloud Access Key #{@opts[:access_key_id]}"
end
end