stax 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/stax +1 -4
- data/lib/stax.rb +33 -3
- data/lib/stax/asg.rb +140 -0
- data/lib/stax/aws/alb.rb +28 -0
- data/lib/stax/aws/asg.rb +34 -0
- data/lib/stax/aws/cfn.rb +102 -0
- data/lib/stax/aws/dynamodb.rb +27 -0
- data/lib/stax/aws/ec2.rb +22 -0
- data/lib/stax/aws/ecr.rb +25 -0
- data/lib/stax/aws/ecs.rb +54 -0
- data/lib/stax/aws/elb.rb +30 -0
- data/lib/stax/aws/emr.rb +28 -0
- data/lib/stax/aws/iam.rb +19 -0
- data/lib/stax/aws/keypair.rb +26 -0
- data/lib/stax/aws/kms.rb +19 -0
- data/lib/stax/aws/lambda.rb +33 -0
- data/lib/stax/aws/logs.rb +25 -0
- data/lib/stax/aws/s3.rb +41 -0
- data/lib/stax/aws/sdk.rb +21 -0
- data/lib/stax/aws/sg.rb +42 -0
- data/lib/stax/aws/sqs.rb +30 -0
- data/lib/stax/aws/ssm.rb +49 -0
- data/lib/stax/aws/sts.rb +31 -0
- data/lib/stax/base.rb +92 -4
- data/lib/stax/cfer.rb +59 -0
- data/lib/stax/cli.rb +13 -4
- data/lib/stax/docker.rb +106 -0
- data/lib/stax/dsl.rb +15 -0
- data/lib/stax/git.rb +61 -0
- data/lib/stax/github.rb +25 -0
- data/lib/stax/iam.rb +18 -0
- data/lib/stax/keypair.rb +75 -0
- data/lib/stax/mixin/alb.rb +45 -0
- data/lib/stax/mixin/asg.rb +115 -0
- data/lib/stax/mixin/dynamodb.rb +62 -0
- data/lib/stax/mixin/ec2.rb +37 -0
- data/lib/stax/mixin/ecs.rb +114 -0
- data/lib/stax/mixin/elb.rb +42 -0
- data/lib/stax/mixin/emr.rb +69 -0
- data/lib/stax/mixin/keypair.rb +45 -0
- data/lib/stax/mixin/kms.rb +30 -0
- data/lib/stax/mixin/lambda.rb +76 -0
- data/lib/stax/mixin/logs.rb +94 -0
- data/lib/stax/mixin/s3.rb +76 -0
- data/lib/stax/mixin/sg.rb +95 -0
- data/lib/stax/mixin/sqs.rb +49 -0
- data/lib/stax/mixin/ssh.rb +52 -0
- data/lib/stax/mixin/ssm.rb +137 -0
- data/lib/stax/stack.rb +19 -35
- data/lib/stax/stack/cfn.rb +24 -0
- data/lib/stax/stack/crud.rb +92 -0
- data/lib/stax/stack/outputs.rb +24 -0
- data/lib/stax/stack/parameters.rb +24 -0
- data/lib/stax/stack/resources.rb +35 -0
- data/lib/stax/staxfile.rb +41 -0
- data/lib/stax/subcommand.rb +12 -0
- data/lib/stax/version.rb +1 -1
- data/stax.gemspec +6 -13
- metadata +105 -9
data/lib/stax/aws/ecs.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Ecs < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::ECS::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def clusters(names)
|
12
|
+
client.describe_clusters(clusters: Array(names)).clusters
|
13
|
+
end
|
14
|
+
|
15
|
+
def services(cluster, services)
|
16
|
+
client.describe_services(cluster: cluster, services: services).services
|
17
|
+
end
|
18
|
+
|
19
|
+
def task_definition(name)
|
20
|
+
client.describe_task_definition(task_definition: name).task_definition
|
21
|
+
end
|
22
|
+
|
23
|
+
def list_tasks(cluster, status = :RUNNING)
|
24
|
+
paginate(:task_arns) do |token|
|
25
|
+
client.list_tasks(cluster: cluster, next_token: token, desired_status: status)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def tasks(cluster, status = :RUNNING)
|
30
|
+
client.describe_tasks(cluster: cluster, tasks: list_tasks(cluster, status)).tasks
|
31
|
+
end
|
32
|
+
|
33
|
+
def list_instances(cluster)
|
34
|
+
paginate(:container_instance_arns) do |token|
|
35
|
+
client.list_container_instances(cluster: cluster, next_token: token)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def instances(cluster)
|
40
|
+
client.describe_container_instances(cluster: cluster, container_instances: list_instances(cluster)).container_instances
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(cluster, task)
|
44
|
+
client.run_task(cluster: cluster, task_definition: task).tasks
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop(cluster, task)
|
48
|
+
client.stop_task(cluster: cluster, task: task).task
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/stax/aws/elb.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Elb < Sdk
|
4
|
+
|
5
|
+
COLORS = {
|
6
|
+
InService: :green,
|
7
|
+
OutOfService: :red,
|
8
|
+
}
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def client
|
13
|
+
@_client ||= ::Aws::ElasticLoadBalancing::Client.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def describe(elb_names)
|
17
|
+
paginate(:load_balancer_descriptions) do |marker|
|
18
|
+
client.describe_load_balancers(load_balancer_names: elb_names, marker: marker)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def instance_health(elb_name)
|
23
|
+
client.describe_instance_health(load_balancer_name: elb_name).instance_states
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/stax/aws/emr.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Emr < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::EMR::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def describe(id)
|
12
|
+
client.describe_cluster(cluster_id: id).cluster
|
13
|
+
end
|
14
|
+
|
15
|
+
def groups(id)
|
16
|
+
## TODO paginate me
|
17
|
+
client.list_instance_groups(cluster_id: id).instance_groups
|
18
|
+
end
|
19
|
+
|
20
|
+
def instances(id, types = nil)
|
21
|
+
## TODO paginate me
|
22
|
+
client.list_instances(cluster_id: id, instance_group_types: types).instances
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/stax/aws/iam.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Keypair < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::EC2::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def describe(names = nil)
|
12
|
+
client.describe_key_pairs(key_names: names).key_pairs
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(name)
|
16
|
+
client.create_key_pair(key_name: name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(name)
|
20
|
+
client.delete_key_pair(key_name: name)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/stax/aws/kms.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Lambda < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::Lambda::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def list
|
12
|
+
paginate(:functions) do |marker|
|
13
|
+
client.list_functions(marker: marker)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def configuration(name)
|
18
|
+
client.get_function_configuration(function_name: name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def code(name)
|
22
|
+
client.get_function(function_name: name).code.location
|
23
|
+
end
|
24
|
+
|
25
|
+
def invoke(opt)
|
26
|
+
client.invoke(opt)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Logs < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::CloudWatchLogs::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def groups(prefix = nil)
|
12
|
+
paginate(:log_groups) do |token|
|
13
|
+
client.describe_log_groups(log_group_name_prefix: prefix, next_token: token)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def streams(opt)
|
18
|
+
client.describe_log_streams(opt).log_streams
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/stax/aws/s3.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class S3 < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::S3::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_buckets
|
12
|
+
client.list_buckets.buckets
|
13
|
+
end
|
14
|
+
|
15
|
+
def bucket_tags(bucket)
|
16
|
+
client.get_bucket_tagging(bucket: bucket).tag_set
|
17
|
+
rescue ::Aws::S3::Errors::NoSuchTagSet
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def bucket_region(bucket)
|
22
|
+
client.get_bucket_location(bucket: bucket).location_constraint
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(opt)
|
26
|
+
client.put_object(opt)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_lifecycle(bucket)
|
30
|
+
client.get_bucket_lifecycle_configuration(bucket: bucket).rules
|
31
|
+
end
|
32
|
+
|
33
|
+
def put_lifecycle(bucket, cfg)
|
34
|
+
client.put_bucket_lifecycle_configuration(bucket: bucket, lifecycle_configuration: cfg)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/stax/aws/sdk.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Sdk
|
4
|
+
|
5
|
+
## universal paginator for aws-sdk calls
|
6
|
+
def self.paginate(thing)
|
7
|
+
token = nil
|
8
|
+
things = []
|
9
|
+
loop do
|
10
|
+
resp = yield(token)
|
11
|
+
things += resp.send(thing)
|
12
|
+
## some apis use marker, some use token
|
13
|
+
token = resp.respond_to?(:next_marker) ? resp.next_marker : resp.next_token
|
14
|
+
break if token.nil?
|
15
|
+
end
|
16
|
+
things
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/stax/aws/sg.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Sg < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::EC2::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def describe(ids)
|
12
|
+
client.describe_security_groups(group_ids: Array(ids)).security_groups
|
13
|
+
end
|
14
|
+
|
15
|
+
def authorize(id, cidr, port = 22)
|
16
|
+
client.authorize_security_group_ingress(
|
17
|
+
group_id: id,
|
18
|
+
ip_protocol: :tcp,
|
19
|
+
from_port: port,
|
20
|
+
to_port: port,
|
21
|
+
cidr_ip: cidr,
|
22
|
+
)
|
23
|
+
rescue ::Aws::EC2::Errors::InvalidPermissionDuplicate => e
|
24
|
+
warn(e.message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def revoke(id, cidr, port = 22)
|
28
|
+
client.revoke_security_group_ingress(
|
29
|
+
group_id: id,
|
30
|
+
ip_protocol: :tcp,
|
31
|
+
from_port: port,
|
32
|
+
to_port: port,
|
33
|
+
cidr_ip: cidr,
|
34
|
+
)
|
35
|
+
rescue ::Aws::EC2::Errors::InvalidPermissionNotFound => e
|
36
|
+
warn(e.message)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/stax/aws/sqs.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Sqs < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::SQS::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(url, attributes = :All)
|
12
|
+
client.get_queue_attributes(queue_url: url, attribute_names: Array(attributes)).attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
def purge(url)
|
16
|
+
client.purge_queue(queue_url: url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def queue_url(name)
|
20
|
+
client.get_queue_url(queue_name: name)&.queue_url
|
21
|
+
end
|
22
|
+
|
23
|
+
def send(opt)
|
24
|
+
client.send_message(opt)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/stax/aws/ssm.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Ssm < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::SSM::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def instances(stack)
|
12
|
+
client.describe_instance_information(filters: [{key: 'tag:aws:cloudformation:stack-name', values: [stack]}]).instance_information_list
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(opt)
|
16
|
+
client.send_command(opt).command
|
17
|
+
end
|
18
|
+
|
19
|
+
def commands
|
20
|
+
client.list_commands.commands
|
21
|
+
end
|
22
|
+
|
23
|
+
def invocation(id)
|
24
|
+
client.list_command_invocations(command_id: id, details: true).command_invocations
|
25
|
+
end
|
26
|
+
|
27
|
+
def parameters(opt)
|
28
|
+
paginate(:parameters) do |token|
|
29
|
+
client.get_parameters_by_path(opt.merge(next_token: token))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(opt)
|
34
|
+
client.get_parameters(opt).parameters
|
35
|
+
end
|
36
|
+
|
37
|
+
def put(opt)
|
38
|
+
client.put_parameter(opt)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(opt)
|
42
|
+
client.delete_parameters(opt).deleted_parameters
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/stax/aws/sts.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Stax
|
2
|
+
module Aws
|
3
|
+
class Sts < Sdk
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def client
|
8
|
+
@_client ||= ::Aws::STS::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def id
|
12
|
+
@_id ||= client.get_caller_identity
|
13
|
+
end
|
14
|
+
|
15
|
+
def account_id
|
16
|
+
id.account
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_id
|
20
|
+
id.user_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_arn
|
24
|
+
id.arn
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|