-
Notifications
You must be signed in to change notification settings - Fork 9
/
alicloud_actiontrail_trails.rb
54 lines (47 loc) · 1.82 KB
/
alicloud_actiontrail_trails.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
require 'alicloud_backend'
class AliCloudActionTrailTrails < AliCloudResourceBase
name 'alicloud_actiontrail_trails'
desc 'Verifies settings for AliCloud Audit Trails in bulk.'
example <<-EXAMPLE
describe alicloud_actiontrail_trails do
it { should exist }
end
EXAMPLE
attr_reader :table
def initialize(opts = {})
@opts = opts
# Call the parent class constructor
super(opts)
validate_parameters(required: %i(region))
@table = fetch_data
end
FilterTable.create
.register_column(:names, field: :name)
.register_column(:oss_bucket_names, field: :oss_bucket_name)
.register_column(:oss_key_prefixes, field: :oss_key_prefix)
.register_column(:role_names, field: :role_name)
.register_column(:sls_project_arns, field: :sls_project_arn)
.register_column(:sls_write_role_arns, field: :sls_write_role_arn)
.install_filter_methods_on_resource(self, :table)
def fetch_data
actiontrail_rows = []
catch_alicloud_errors do
@actiontrails = @alicloud.actiontrail_client.request(
action: 'DescribeTrails',
params: {
"RegionId": opts[:region],
},
)['TrailList']
end
return [] if !@actiontrails || @actiontrails.empty?
@actiontrails.each do |actiontrail|
actiontrail_rows += [{ name: actiontrail['Name'],
oss_bucket_name: actiontrail['OssBucketName'],
oss_key_prefix: actiontrail['OssKeyPrefix'],
role_name: actiontrail['RoleName'],
sls_project_arn: actiontrail['SlsProjectArn'],
sls_write_role_arn: actiontrail['SlsWriteRoleArn'] }]
end
@table = actiontrail_rows
end
end