stax 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/bin/stax +1 -4
  3. data/lib/stax.rb +33 -3
  4. data/lib/stax/asg.rb +140 -0
  5. data/lib/stax/aws/alb.rb +28 -0
  6. data/lib/stax/aws/asg.rb +34 -0
  7. data/lib/stax/aws/cfn.rb +102 -0
  8. data/lib/stax/aws/dynamodb.rb +27 -0
  9. data/lib/stax/aws/ec2.rb +22 -0
  10. data/lib/stax/aws/ecr.rb +25 -0
  11. data/lib/stax/aws/ecs.rb +54 -0
  12. data/lib/stax/aws/elb.rb +30 -0
  13. data/lib/stax/aws/emr.rb +28 -0
  14. data/lib/stax/aws/iam.rb +19 -0
  15. data/lib/stax/aws/keypair.rb +26 -0
  16. data/lib/stax/aws/kms.rb +19 -0
  17. data/lib/stax/aws/lambda.rb +33 -0
  18. data/lib/stax/aws/logs.rb +25 -0
  19. data/lib/stax/aws/s3.rb +41 -0
  20. data/lib/stax/aws/sdk.rb +21 -0
  21. data/lib/stax/aws/sg.rb +42 -0
  22. data/lib/stax/aws/sqs.rb +30 -0
  23. data/lib/stax/aws/ssm.rb +49 -0
  24. data/lib/stax/aws/sts.rb +31 -0
  25. data/lib/stax/base.rb +92 -4
  26. data/lib/stax/cfer.rb +59 -0
  27. data/lib/stax/cli.rb +13 -4
  28. data/lib/stax/docker.rb +106 -0
  29. data/lib/stax/dsl.rb +15 -0
  30. data/lib/stax/git.rb +61 -0
  31. data/lib/stax/github.rb +25 -0
  32. data/lib/stax/iam.rb +18 -0
  33. data/lib/stax/keypair.rb +75 -0
  34. data/lib/stax/mixin/alb.rb +45 -0
  35. data/lib/stax/mixin/asg.rb +115 -0
  36. data/lib/stax/mixin/dynamodb.rb +62 -0
  37. data/lib/stax/mixin/ec2.rb +37 -0
  38. data/lib/stax/mixin/ecs.rb +114 -0
  39. data/lib/stax/mixin/elb.rb +42 -0
  40. data/lib/stax/mixin/emr.rb +69 -0
  41. data/lib/stax/mixin/keypair.rb +45 -0
  42. data/lib/stax/mixin/kms.rb +30 -0
  43. data/lib/stax/mixin/lambda.rb +76 -0
  44. data/lib/stax/mixin/logs.rb +94 -0
  45. data/lib/stax/mixin/s3.rb +76 -0
  46. data/lib/stax/mixin/sg.rb +95 -0
  47. data/lib/stax/mixin/sqs.rb +49 -0
  48. data/lib/stax/mixin/ssh.rb +52 -0
  49. data/lib/stax/mixin/ssm.rb +137 -0
  50. data/lib/stax/stack.rb +19 -35
  51. data/lib/stax/stack/cfn.rb +24 -0
  52. data/lib/stax/stack/crud.rb +92 -0
  53. data/lib/stax/stack/outputs.rb +24 -0
  54. data/lib/stax/stack/parameters.rb +24 -0
  55. data/lib/stax/stack/resources.rb +35 -0
  56. data/lib/stax/staxfile.rb +41 -0
  57. data/lib/stax/subcommand.rb +12 -0
  58. data/lib/stax/version.rb +1 -1
  59. data/stax.gemspec +6 -13
  60. metadata +105 -9
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,19 @@
1
+ module Stax
2
+ module Aws
3
+ class Iam < Sdk
4
+
5
+ class << self
6
+
7
+ def client
8
+ @_client ||= ::Aws::IAM::Client.new
9
+ end
10
+
11
+ def aliases
12
+ client.list_account_aliases.account_aliases
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -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
@@ -0,0 +1,19 @@
1
+ module Stax
2
+ module Aws
3
+ class Kms < Sdk
4
+
5
+ class << self
6
+
7
+ def client
8
+ @_client ||= ::Aws::KMS::Client.new
9
+ end
10
+
11
+ def describe(id)
12
+ client.describe_key(key_id: id).key_metadata
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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