From 0fbb7a4977ddb3617ae93b6f315f8eaa2efb6ac0 Mon Sep 17 00:00:00 2001 From: Aslan Brooke Date: Mon, 5 Sep 2016 14:52:13 -0700 Subject: [PATCH] Restructure project and add new spec testing approach. --- .gitignore | 0 .travis.yml | 0 Gemfile | 0 Gemfile.lock | 21 +- Gemfile.lock.windows | 11 +- LICENSE | 0 README.md | 0 Rakefile | 0 feature/cloud_trail/cloud_trail.feature | 0 feature/compute/assoc_security_group.feature | 0 feature/compute/compute.feature | 0 feature/compute/secondary_ip.feature | 0 feature/compute/view.feature | 0 feature/compute/view_images.feature | 0 feature/elasticip/elasticip.feature | 0 feature/elasticip/view.feature | 0 feature/hosted_zone/view.feature | 0 feature/hosted_zone/view_record.feature | 0 .../instance_registration.feature | 0 feature/load_balancer/listener.feature | 0 feature/load_balancer/load_balancer.feature | 0 feature/load_balancer/view.feature | 0 feature/route_table/assoc_subnet.feature | 0 feature/route_table/route_propagation.feature | 0 feature/route_table/route_table.feature | 0 feature/route_table/route_to_gateway.feature | 0 feature/route_table/route_to_instance.feature | 0 feature/route_table/view.feature | 0 feature/s3/bucket.feature | 0 feature/security_group/ingress_cidr.feature | 0 feature/security_group/ingress_group.feature | 0 feature/security_group/security_group.feature | 0 feature/security_group/view.feature | 0 feature/step_definitions/gzip_steps.rb | 0 feature/subnet/subnet.feature | 0 feature/subnet/view.feature | 0 feature/support/env.rb | 0 lib/zaws/command/bucket.rb | 0 lib/zaws/command/cloud_trail.rb | 0 lib/zaws/command/compute.rb | 2 +- lib/zaws/command/config.rb | 0 lib/zaws/command/elasticip.rb | 0 lib/zaws/command/hosted_zone.rb | 0 lib/zaws/command/iam.rb | 2 +- lib/zaws/command/load_balancer.rb | 0 lib/zaws/command/nessus.rb | 16 +- lib/zaws/command/route_table.rb | 0 lib/zaws/command/security_group.rb | 0 lib/zaws/command/subnet.rb | 2 +- lib/zaws/command/vpc.rb | 2 +- lib/zaws/{ => external}/awscli/awscli.rb | 8 +- lib/zaws/{ => external}/awscli/commands.rb | 0 .../{ => external}/awscli/commands/ec2.rb | 0 .../awscli/commands/ec2/CreateSubnet.rb | 0 .../awscli/commands/ec2/CreateTags.rb | 0 .../awscli/commands/ec2/CreateVPC.rb | 0 .../awscli/commands/ec2/DescribeInstances.rb | 2 +- .../awscli/commands/ec2/DescribeSubnet.rb | 0 .../awscli/commands/ec2/DescribeVPCs.rb} | 0 .../ec2/DescribeVpcPeeringConnections.rb | 0 .../awscli/commands/ec2/RunInstances.rb | 0 .../awscli/commands/ec2/StopInstances.rb | 0 .../{ => external}/awscli/commands/iam.rb | 0 .../awscli/commands/iam/GetPolicy.rb | 0 .../awscli/commands/iam/GetPolicyVersion.rb | 0 .../awscli/commands/iam/GetRolePolicy.rb | 0 lib/zaws/{ => external}/awscli/credentials.rb | 0 lib/zaws/{ => external}/awscli/data.rb | 0 lib/zaws/{ => external}/awscli/data/ec2.rb | 2 +- .../awscli/data/ec2/instance.rb | 8 +- .../{ => external}/awscli/data/ec2/subnet.rb | 0 .../{ => external}/awscli/data/ec2/vpc.rb | 0 lib/zaws/{ => external}/awscli/data/iam.rb | 0 .../{ => external}/awscli/data/iam/policy.rb | 0 .../awscli/data/iam/policyDocument.rb | 0 .../awscli/data/iam/policyVersion.rb | 0 .../awscli/data/iam/role_policy.rb | 0 .../external/awscli/generators/api/aws/aws.rb | 44 +++ .../awscli/generators/api/ec2/create_tags.rb | 38 +++ .../generators/api/ec2/describe_instances.rb | 31 ++ .../api/ec2/describe_security_groups.rb | 31 ++ .../generators/api/ec2/describe_subnets.rb | 31 ++ .../awscli/generators/api/ec2/filter.rb | 54 ++++ .../api/ec2/modify_instance_attribute.rb | 43 +++ .../generators/api/ec2/network_interfaces.rb | 65 +++++ .../awscli/generators/result/ec2/instances.rb | 53 ++++ .../result/ec2/network_interfaces.rb | 47 +++ .../generators/result/ec2/security_groups.rb | 65 +++++ .../awscli/generators/result/ec2/subnets.rb | 77 +++++ .../awscli/generators/result/ec2/tags.rb | 34 +++ lib/zaws/{ => external}/awscli/regions.rb | 0 .../{ => external}/nessusapi/data/agents.rb | 0 .../{ => external}/nessusapi/data/scanners.rb | 0 .../{ => external}/nessusapi/nessusapi.rb | 0 lib/zaws/{ => external}/nessusapi/reources.rb | 0 .../nessusapi/resources/agents.rb | 0 .../nessusapi/resources/agents/list.rb | 0 .../nessusapi/resources/scanners.rb | 0 .../nessusapi/resources/scanners/list.rb | 0 .../newrelicapi/data/servers.rb | 0 .../newrelicapi/newrelic_client.rb | 0 .../newrelicapi/newrelic_creds.rb | 0 .../{ => external}/newrelicapi/newrelicapi.rb | 0 .../newrelicapi/resources/servers.rb | 0 .../newrelicapi/resources/servers/list.rb | 0 .../{ => external}/sumoapi/data/collectors.rb | 0 .../{ => external}/sumoapi/data/sources.rb | 0 .../sumoapi/resources/collectors.rb | 0 .../sumoapi/resources/collectors/list.rb | 0 .../sumoapi/resources/sources.rb | 0 .../sumoapi/resources/sources/list.rb | 0 .../{ => external}/sumoapi/sumo_client.rb | 0 lib/zaws/{ => external}/sumoapi/sumo_creds.rb | 0 lib/zaws/{ => external}/sumoapi/sumoapi.rb | 0 lib/zaws/{repository => helper}/filestore.rb | 5 +- lib/zaws/helper/output.rb | 0 lib/zaws/helper/shell.rb | 0 lib/zaws/helper/zfile.rb | 0 lib/zaws/{controllers => services}/ai.rb | 0 lib/zaws/{controllers => services}/aws.rb | 0 lib/zaws/{controllers => services}/chef.rb | 0 lib/zaws/{controllers => services}/config.rb | 0 lib/zaws/services/ec2/compute.rb | 4 +- lib/zaws/{controllers => services}/nessus.rb | 0 lib/zaws/services/nessus/agents.rb | 6 +- lib/zaws/services/nessus/scanners.rb | 6 +- .../{controllers => services}/newrelic.rb | 0 lib/zaws/{controllers => services}/sumo.rb | 0 lib/zaws/{controllers => services}/vmware.rb | 0 spec/spec_helper.rb | 0 spec/zaws/awscli/data/ec2/instance_spec.rb | 5 +- .../awscli/data/iam/policyDocument_spec.rb | 0 spec/zaws/awscli/data/iam/role_policy_spec.rb | 0 spec/zaws/awscli/get_aws_version_spec.rb | 2 +- .../instance_id_by_external_id_spec.rb | 4 +- spec/zaws/ec2/compute/management_spec.rb | 275 ++++++++++-------- spec/zaws/ec2/compute/network_spec.rb | 152 +++++----- spec/zaws/ec2/compute/node_spec.rb | 6 +- spec/zaws/ec2/compute/storage_spec.rb | 6 +- spec/zaws/ec2/security_group_spec.rb | 114 +++----- spec/zaws/ec2/subnet_spec.rb | 14 +- spec/zaws/ec2/vpc_spec.rb | 2 +- spec/zaws/elb/load_balancer_spec.rb | 2 +- spec/zaws/helper/option/absent_spec.rb | 0 spec/zaws/helper/option/exclusive_spec.rb | 0 spec/zaws/helper/option/exists_spec.rb | 0 spec/zaws/helper/option/minimum_spec.rb | 0 .../helper/output/binary_nagios_check_spec.rb | 0 spec/zaws/helper/output/colorize_spec.rb | 0 spec/zaws/helper/output/opt_exclusive_spec.rb | 0 spec/zaws/helper/output/opt_minimum_spec.rb | 0 spec/zaws/helper/output/opt_required_spec.rb | 0 .../output/transform_cloudtrail_spec.rb | 0 spec/zaws/helper/shell/if_then_spec.rb | 0 spec/zaws/iam/policy_spec.rb | 2 +- spec/zaws/iam/role_policy_spec.rb | 2 +- spec/zaws/nessus/scanners.json | 0 157 files changed, 949 insertions(+), 347 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .travis.yml mode change 100644 => 100755 Gemfile mode change 100644 => 100755 Gemfile.lock mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 Rakefile mode change 100644 => 100755 feature/cloud_trail/cloud_trail.feature mode change 100644 => 100755 feature/compute/assoc_security_group.feature mode change 100644 => 100755 feature/compute/compute.feature mode change 100644 => 100755 feature/compute/secondary_ip.feature mode change 100644 => 100755 feature/compute/view.feature mode change 100644 => 100755 feature/compute/view_images.feature mode change 100644 => 100755 feature/elasticip/elasticip.feature mode change 100644 => 100755 feature/elasticip/view.feature mode change 100644 => 100755 feature/hosted_zone/view.feature mode change 100644 => 100755 feature/hosted_zone/view_record.feature mode change 100644 => 100755 feature/load_balancer/instance_registration.feature mode change 100644 => 100755 feature/load_balancer/listener.feature mode change 100644 => 100755 feature/load_balancer/load_balancer.feature mode change 100644 => 100755 feature/load_balancer/view.feature mode change 100644 => 100755 feature/route_table/assoc_subnet.feature mode change 100644 => 100755 feature/route_table/route_propagation.feature mode change 100644 => 100755 feature/route_table/route_table.feature mode change 100644 => 100755 feature/route_table/route_to_gateway.feature mode change 100644 => 100755 feature/route_table/route_to_instance.feature mode change 100644 => 100755 feature/route_table/view.feature mode change 100644 => 100755 feature/s3/bucket.feature mode change 100644 => 100755 feature/security_group/ingress_cidr.feature mode change 100644 => 100755 feature/security_group/ingress_group.feature mode change 100644 => 100755 feature/security_group/security_group.feature mode change 100644 => 100755 feature/security_group/view.feature mode change 100644 => 100755 feature/step_definitions/gzip_steps.rb mode change 100644 => 100755 feature/subnet/subnet.feature mode change 100644 => 100755 feature/subnet/view.feature mode change 100644 => 100755 feature/support/env.rb mode change 100644 => 100755 lib/zaws/command/bucket.rb mode change 100644 => 100755 lib/zaws/command/cloud_trail.rb mode change 100644 => 100755 lib/zaws/command/config.rb mode change 100644 => 100755 lib/zaws/command/elasticip.rb mode change 100644 => 100755 lib/zaws/command/hosted_zone.rb mode change 100644 => 100755 lib/zaws/command/iam.rb mode change 100644 => 100755 lib/zaws/command/load_balancer.rb mode change 100644 => 100755 lib/zaws/command/route_table.rb mode change 100644 => 100755 lib/zaws/command/security_group.rb rename lib/zaws/{ => external}/awscli/awscli.rb (83%) rename lib/zaws/{ => external}/awscli/commands.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/ec2.rb (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/CreateSubnet.rb (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/CreateTags.rb (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/CreateVPC.rb (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/DescribeInstances.rb (92%) rename lib/zaws/{ => external}/awscli/commands/ec2/DescribeSubnet.rb (100%) rename lib/zaws/{awscli/commands/ec2/DescribeVpcs.rb => external/awscli/commands/ec2/DescribeVPCs.rb} (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/DescribeVpcPeeringConnections.rb (100%) rename lib/zaws/{ => external}/awscli/commands/ec2/RunInstances.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/ec2/StopInstances.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/iam.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/iam/GetPolicy.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/iam/GetPolicyVersion.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/commands/iam/GetRolePolicy.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/credentials.rb (100%) rename lib/zaws/{ => external}/awscli/data.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/data/ec2.rb (95%) rename lib/zaws/{ => external}/awscli/data/ec2/instance.rb (95%) rename lib/zaws/{ => external}/awscli/data/ec2/subnet.rb (100%) rename lib/zaws/{ => external}/awscli/data/ec2/vpc.rb (100%) rename lib/zaws/{ => external}/awscli/data/iam.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/data/iam/policy.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/data/iam/policyDocument.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/data/iam/policyVersion.rb (100%) mode change 100644 => 100755 rename lib/zaws/{ => external}/awscli/data/iam/role_policy.rb (100%) mode change 100644 => 100755 create mode 100755 lib/zaws/external/awscli/generators/api/aws/aws.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/create_tags.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/describe_instances.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/describe_security_groups.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/describe_subnets.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/filter.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/modify_instance_attribute.rb create mode 100755 lib/zaws/external/awscli/generators/api/ec2/network_interfaces.rb create mode 100755 lib/zaws/external/awscli/generators/result/ec2/instances.rb create mode 100755 lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb create mode 100755 lib/zaws/external/awscli/generators/result/ec2/security_groups.rb create mode 100755 lib/zaws/external/awscli/generators/result/ec2/subnets.rb create mode 100755 lib/zaws/external/awscli/generators/result/ec2/tags.rb rename lib/zaws/{ => external}/awscli/regions.rb (100%) rename lib/zaws/{ => external}/nessusapi/data/agents.rb (100%) rename lib/zaws/{ => external}/nessusapi/data/scanners.rb (100%) rename lib/zaws/{ => external}/nessusapi/nessusapi.rb (100%) rename lib/zaws/{ => external}/nessusapi/reources.rb (100%) rename lib/zaws/{ => external}/nessusapi/resources/agents.rb (100%) rename lib/zaws/{ => external}/nessusapi/resources/agents/list.rb (100%) rename lib/zaws/{ => external}/nessusapi/resources/scanners.rb (100%) rename lib/zaws/{ => external}/nessusapi/resources/scanners/list.rb (100%) rename lib/zaws/{ => external}/newrelicapi/data/servers.rb (100%) rename lib/zaws/{ => external}/newrelicapi/newrelic_client.rb (100%) rename lib/zaws/{ => external}/newrelicapi/newrelic_creds.rb (100%) rename lib/zaws/{ => external}/newrelicapi/newrelicapi.rb (100%) rename lib/zaws/{ => external}/newrelicapi/resources/servers.rb (100%) rename lib/zaws/{ => external}/newrelicapi/resources/servers/list.rb (100%) rename lib/zaws/{ => external}/sumoapi/data/collectors.rb (100%) rename lib/zaws/{ => external}/sumoapi/data/sources.rb (100%) rename lib/zaws/{ => external}/sumoapi/resources/collectors.rb (100%) rename lib/zaws/{ => external}/sumoapi/resources/collectors/list.rb (100%) rename lib/zaws/{ => external}/sumoapi/resources/sources.rb (100%) rename lib/zaws/{ => external}/sumoapi/resources/sources/list.rb (100%) rename lib/zaws/{ => external}/sumoapi/sumo_client.rb (100%) rename lib/zaws/{ => external}/sumoapi/sumo_creds.rb (100%) rename lib/zaws/{ => external}/sumoapi/sumoapi.rb (100%) rename lib/zaws/{repository => helper}/filestore.rb (87%) mode change 100644 => 100755 lib/zaws/helper/output.rb mode change 100644 => 100755 lib/zaws/helper/shell.rb mode change 100644 => 100755 lib/zaws/helper/zfile.rb rename lib/zaws/{controllers => services}/ai.rb (100%) rename lib/zaws/{controllers => services}/aws.rb (100%) rename lib/zaws/{controllers => services}/chef.rb (100%) rename lib/zaws/{controllers => services}/config.rb (100%) rename lib/zaws/{controllers => services}/nessus.rb (100%) rename lib/zaws/{controllers => services}/newrelic.rb (100%) rename lib/zaws/{controllers => services}/sumo.rb (100%) rename lib/zaws/{controllers => services}/vmware.rb (100%) mode change 100644 => 100755 spec/spec_helper.rb mode change 100644 => 100755 spec/zaws/awscli/data/iam/policyDocument_spec.rb mode change 100644 => 100755 spec/zaws/awscli/data/iam/role_policy_spec.rb mode change 100644 => 100755 spec/zaws/awscli/get_aws_version_spec.rb mode change 100644 => 100755 spec/zaws/helper/option/absent_spec.rb mode change 100644 => 100755 spec/zaws/helper/option/exclusive_spec.rb mode change 100644 => 100755 spec/zaws/helper/option/exists_spec.rb mode change 100644 => 100755 spec/zaws/helper/option/minimum_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/binary_nagios_check_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/colorize_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/opt_exclusive_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/opt_minimum_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/opt_required_spec.rb mode change 100644 => 100755 spec/zaws/helper/output/transform_cloudtrail_spec.rb mode change 100644 => 100755 spec/zaws/helper/shell/if_then_spec.rb create mode 100755 spec/zaws/nessus/scanners.json diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 diff --git a/Gemfile.lock b/Gemfile.lock old mode 100644 new mode 100755 index 36dac4e..3ae155e --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,6 @@ PATH remote: . specs: zaws (0.0.6) - excon json (~> 1.5.0) mixlib-shellout (~> 1.1.0) netaddr (~> 1.5.0) @@ -35,21 +34,15 @@ GEM multi_test (>= 0.1.1) diff-lcs (1.2.5) docile (1.1.5) - excon (0.49.0) ffi (1.9.3) - ffi (1.9.3-x86-mingw32) gherkin (2.12.2) multi_json (~> 1.3) - gherkin (2.12.2-x86-mingw32) - multi_json (~> 1.3) json (1.5.5) mime-types (2.3) mixlib-shellout (1.1.0) - mixlib-shellout (1.1.0-x86-mingw32) - win32-process (~> 0.6.5) multi_json (1.7.9) multi_test (0.1.1) - netaddr (1.5.1) + netaddr (1.5.0) rake (10.1.0) rest-client (1.6.7) mime-types (>= 1.16) @@ -70,18 +63,9 @@ GEM tins (~> 1.0) thor (0.18.1) tins (1.3.0) - win32-api (1.5.3-x86-mingw32) - win32-process (0.6.6) - windows-pr (>= 1.2.2) - windows-api (0.4.4) - win32-api (>= 1.4.5) - windows-pr (1.2.4) - win32-api (>= 1.4.5) - windows-api (>= 0.4.0) PLATFORMS ruby - x86-mingw32 DEPENDENCIES aruba (~> 0.5.4) @@ -92,3 +76,6 @@ DEPENDENCIES rake rspec (~> 2.14.1) zaws! + +BUNDLED WITH + 1.10.6 \ No newline at end of file diff --git a/Gemfile.lock.windows b/Gemfile.lock.windows index 1fcbddb..36dac4e 100755 --- a/Gemfile.lock.windows +++ b/Gemfile.lock.windows @@ -2,6 +2,7 @@ PATH remote: . specs: zaws (0.0.6) + excon json (~> 1.5.0) mixlib-shellout (~> 1.1.0) netaddr (~> 1.5.0) @@ -32,11 +33,9 @@ GEM gherkin (~> 2.12) multi_json (>= 1.7.5, < 2.0) multi_test (>= 0.1.1) - debase (0.2.1) - debase-ruby_core_source - debase-ruby_core_source (0.8.2) diff-lcs (1.2.5) docile (1.1.5) + excon (0.49.0) ffi (1.9.3) ffi (1.9.3-x86-mingw32) gherkin (2.12.2) @@ -50,7 +49,7 @@ GEM win32-process (~> 0.6.5) multi_json (1.7.9) multi_test (0.1.1) - netaddr (1.5.0) + netaddr (1.5.1) rake (10.1.0) rest-client (1.6.7) mime-types (>= 1.16) @@ -62,8 +61,6 @@ GEM rspec-expectations (2.14.5) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.6) - ruby-debug-ide (0.6.0) - rake (>= 0.8.1) simplecov (0.8.2) docile (~> 1.1.0) multi_json @@ -92,8 +89,6 @@ DEPENDENCIES bundler coveralls cucumber (~> 1.3.14) - debase rake rspec (~> 2.14.1) - ruby-debug-ide zaws! diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 diff --git a/feature/cloud_trail/cloud_trail.feature b/feature/cloud_trail/cloud_trail.feature old mode 100644 new mode 100755 diff --git a/feature/compute/assoc_security_group.feature b/feature/compute/assoc_security_group.feature old mode 100644 new mode 100755 diff --git a/feature/compute/compute.feature b/feature/compute/compute.feature old mode 100644 new mode 100755 diff --git a/feature/compute/secondary_ip.feature b/feature/compute/secondary_ip.feature old mode 100644 new mode 100755 diff --git a/feature/compute/view.feature b/feature/compute/view.feature old mode 100644 new mode 100755 diff --git a/feature/compute/view_images.feature b/feature/compute/view_images.feature old mode 100644 new mode 100755 diff --git a/feature/elasticip/elasticip.feature b/feature/elasticip/elasticip.feature old mode 100644 new mode 100755 diff --git a/feature/elasticip/view.feature b/feature/elasticip/view.feature old mode 100644 new mode 100755 diff --git a/feature/hosted_zone/view.feature b/feature/hosted_zone/view.feature old mode 100644 new mode 100755 diff --git a/feature/hosted_zone/view_record.feature b/feature/hosted_zone/view_record.feature old mode 100644 new mode 100755 diff --git a/feature/load_balancer/instance_registration.feature b/feature/load_balancer/instance_registration.feature old mode 100644 new mode 100755 diff --git a/feature/load_balancer/listener.feature b/feature/load_balancer/listener.feature old mode 100644 new mode 100755 diff --git a/feature/load_balancer/load_balancer.feature b/feature/load_balancer/load_balancer.feature old mode 100644 new mode 100755 diff --git a/feature/load_balancer/view.feature b/feature/load_balancer/view.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/assoc_subnet.feature b/feature/route_table/assoc_subnet.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/route_propagation.feature b/feature/route_table/route_propagation.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/route_table.feature b/feature/route_table/route_table.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/route_to_gateway.feature b/feature/route_table/route_to_gateway.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/route_to_instance.feature b/feature/route_table/route_to_instance.feature old mode 100644 new mode 100755 diff --git a/feature/route_table/view.feature b/feature/route_table/view.feature old mode 100644 new mode 100755 diff --git a/feature/s3/bucket.feature b/feature/s3/bucket.feature old mode 100644 new mode 100755 diff --git a/feature/security_group/ingress_cidr.feature b/feature/security_group/ingress_cidr.feature old mode 100644 new mode 100755 diff --git a/feature/security_group/ingress_group.feature b/feature/security_group/ingress_group.feature old mode 100644 new mode 100755 diff --git a/feature/security_group/security_group.feature b/feature/security_group/security_group.feature old mode 100644 new mode 100755 diff --git a/feature/security_group/view.feature b/feature/security_group/view.feature old mode 100644 new mode 100755 diff --git a/feature/step_definitions/gzip_steps.rb b/feature/step_definitions/gzip_steps.rb old mode 100644 new mode 100755 diff --git a/feature/subnet/subnet.feature b/feature/subnet/subnet.feature old mode 100644 new mode 100755 diff --git a/feature/subnet/view.feature b/feature/subnet/view.feature old mode 100644 new mode 100755 diff --git a/feature/support/env.rb b/feature/support/env.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/bucket.rb b/lib/zaws/command/bucket.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/cloud_trail.rb b/lib/zaws/command/cloud_trail.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/compute.rb b/lib/zaws/command/compute.rb index a2c7969..7a3aaa5 100755 --- a/lib/zaws/command/compute.rb +++ b/lib/zaws/command/compute.rb @@ -13,7 +13,7 @@ class Compute < Thor def initialize(*args) super shellout=ZAWS::Helper::Shell.new - awscli = ZAWS::AWSCLI.new(shellout) + awscli = ZAWS::AWSCLI.new(shellout,false) @aws = ZAWS::AWS.new(shellout, awscli) @out = $stdout @print_exit_code = false diff --git a/lib/zaws/command/config.rb b/lib/zaws/command/config.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/elasticip.rb b/lib/zaws/command/elasticip.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/hosted_zone.rb b/lib/zaws/command/hosted_zone.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/iam.rb b/lib/zaws/command/iam.rb old mode 100644 new mode 100755 index f429ff5..20a8905 --- a/lib/zaws/command/iam.rb +++ b/lib/zaws/command/iam.rb @@ -12,7 +12,7 @@ class IAM < Thor def initialize(*args) super shellout=ZAWS::Helper::Shell.new - awscli = ZAWS::AWSCLI.new(shellout) + awscli = ZAWS::AWSCLI.new(shellout,false) @aws = ZAWS::AWS.new(shellout,awscli) @out = $stdout @print_exit_code = false diff --git a/lib/zaws/command/load_balancer.rb b/lib/zaws/command/load_balancer.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/nessus.rb b/lib/zaws/command/nessus.rb index 74ac992..a68b9fd 100755 --- a/lib/zaws/command/nessus.rb +++ b/lib/zaws/command/nessus.rb @@ -4,6 +4,8 @@ module ZAWS module Command class Nessus < Thor class_option :verbose, :type => :boolean, :desc => "Verbose outout", :aliases => :d, :default => false + class_option :home, :type => :string, :default => ENV['HOME'], :desc => 'Home directory location for credentials file' + class_option :viewtype, :type => :string, :desc => "View type, json or table", :banner => "", :aliases => :w, :default => "table" attr_accessor :nessus attr_accessor :out @@ -16,21 +18,21 @@ def initialize(*args) @nessus = ZAWS::Controllers::Nessus.new(shellout, nessusapi) @out = $stdout @print_exit_code = false + @params= { + 'home' => options[:home] + } end desc "view_scanners", "View scanners." - option :viewtype, :type => :string, :desc => "View type, json or table", :banner => "", :aliases => :w, :default => "table" - option :home, :type => :string, :default => ENV['HOME'], :desc => 'Home directory location for credentials file' def view_scanners - @nessus.scanners.view(options[:home], @out, (options[:verbose] ? @out : nil)) + @out.puts(@nessus.scanners.view(@params)); end - desc "view_agents", "View scanners." - option :viewtype, :type => :string, :desc => "View type, json or table", :banner => "", :aliases => :w, :default => "table" - option :home, :type => :string, :default => ENV['HOME'], :desc => 'Home directory location for credentials file' + desc "view_agents", "View agents." option :scanner, :type => :string, :default => '1', :desc => 'scanner id' def view_agents - @nessus.agents.view(options[:home],options[:scanner], @out, (options[:verbose] ? @out : nil)) + @params['scanner']=options[:scanner] + @out.puts(@nessus.agents.view(params)); end end end diff --git a/lib/zaws/command/route_table.rb b/lib/zaws/command/route_table.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/security_group.rb b/lib/zaws/command/security_group.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/command/subnet.rb b/lib/zaws/command/subnet.rb index 621a8dd..d4d6324 100755 --- a/lib/zaws/command/subnet.rb +++ b/lib/zaws/command/subnet.rb @@ -13,7 +13,7 @@ class Subnet < Thor def initialize(*args) super shellout=ZAWS::Helper::Shell.new - awscli = ZAWS::AWSCLI.new(shellout) + awscli = ZAWS::AWSCLI.new(shellout,false) @aws = ZAWS::AWS.new(shellout, awscli) @out = $stdout @print_exit_code = false diff --git a/lib/zaws/command/vpc.rb b/lib/zaws/command/vpc.rb index 32af822..f9b2e08 100755 --- a/lib/zaws/command/vpc.rb +++ b/lib/zaws/command/vpc.rb @@ -13,7 +13,7 @@ class VPC < Thor def initialize(*args) super shellout=ZAWS::Helper::Shell.new - awscli = ZAWS::AWSCLI.new(shellout) + awscli = ZAWS::AWSCLI.new(shellout,false) @aws = ZAWS::AWS.new(shellout, awscli) @out = $stdout @print_exit_code = false diff --git a/lib/zaws/awscli/awscli.rb b/lib/zaws/external/awscli/awscli.rb similarity index 83% rename from lib/zaws/awscli/awscli.rb rename to lib/zaws/external/awscli/awscli.rb index ac696ac..69f37e8 100755 --- a/lib/zaws/awscli/awscli.rb +++ b/lib/zaws/external/awscli/awscli.rb @@ -4,18 +4,20 @@ module ZAWS class AWSCLI attr_accessor :home - def initialize(shellout) + def initialize(shellout,keep_filestore_empty=false) @shellout=shellout + @keep_filestore_empty=keep_filestore_empty end def filestore - @filestore ||= ZAWS::Repository::Filestore.new() + @filestore ||= ZAWS::Repository::Filestore.new(@keep_filestore_empty) + @filestore.timeout = 600 + return @filestore if @keep_filestore_empty @home ||= ENV['HOME'] @filestore.location="#{@home}/.awsdata" unless File.directory?(@filestore.location) FileUtils.mkdir_p(@filestore.location) end - @filestore.timeout = 600 return @filestore end diff --git a/lib/zaws/awscli/commands.rb b/lib/zaws/external/awscli/commands.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands.rb rename to lib/zaws/external/awscli/commands.rb diff --git a/lib/zaws/awscli/commands/ec2.rb b/lib/zaws/external/awscli/commands/ec2.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2.rb rename to lib/zaws/external/awscli/commands/ec2.rb diff --git a/lib/zaws/awscli/commands/ec2/CreateSubnet.rb b/lib/zaws/external/awscli/commands/ec2/CreateSubnet.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/CreateSubnet.rb rename to lib/zaws/external/awscli/commands/ec2/CreateSubnet.rb diff --git a/lib/zaws/awscli/commands/ec2/CreateTags.rb b/lib/zaws/external/awscli/commands/ec2/CreateTags.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/CreateTags.rb rename to lib/zaws/external/awscli/commands/ec2/CreateTags.rb diff --git a/lib/zaws/awscli/commands/ec2/CreateVPC.rb b/lib/zaws/external/awscli/commands/ec2/CreateVPC.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/CreateVPC.rb rename to lib/zaws/external/awscli/commands/ec2/CreateVPC.rb diff --git a/lib/zaws/awscli/commands/ec2/DescribeInstances.rb b/lib/zaws/external/awscli/commands/ec2/DescribeInstances.rb similarity index 92% rename from lib/zaws/awscli/commands/ec2/DescribeInstances.rb rename to lib/zaws/external/awscli/commands/ec2/DescribeInstances.rb index 4c00e58..978227c 100755 --- a/lib/zaws/awscli/commands/ec2/DescribeInstances.rb +++ b/lib/zaws/external/awscli/commands/ec2/DescribeInstances.rb @@ -16,7 +16,7 @@ def execute(region, view, filters={}, textout=nil, verbose=nil,profile=nil) comline = comline + " --profile #{profile}" if profile comline = comline + " --filter" if filters.length > 0 filters.each do |key, item| - comline = comline + " 'Name=#{key},Values=#{item}'" + comline = comline + " \"Name=#{key},Values=#{item}\"" end unless @awscli.data_ec2.instance.load_cached(comline, verbose) @awscli.data_ec2.instance.load(comline, @shellout.cli(comline, verbose), verbose) diff --git a/lib/zaws/awscli/commands/ec2/DescribeSubnet.rb b/lib/zaws/external/awscli/commands/ec2/DescribeSubnet.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/DescribeSubnet.rb rename to lib/zaws/external/awscli/commands/ec2/DescribeSubnet.rb diff --git a/lib/zaws/awscli/commands/ec2/DescribeVpcs.rb b/lib/zaws/external/awscli/commands/ec2/DescribeVPCs.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/DescribeVpcs.rb rename to lib/zaws/external/awscli/commands/ec2/DescribeVPCs.rb diff --git a/lib/zaws/awscli/commands/ec2/DescribeVpcPeeringConnections.rb b/lib/zaws/external/awscli/commands/ec2/DescribeVpcPeeringConnections.rb similarity index 100% rename from lib/zaws/awscli/commands/ec2/DescribeVpcPeeringConnections.rb rename to lib/zaws/external/awscli/commands/ec2/DescribeVpcPeeringConnections.rb diff --git a/lib/zaws/awscli/commands/ec2/RunInstances.rb b/lib/zaws/external/awscli/commands/ec2/RunInstances.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/ec2/RunInstances.rb rename to lib/zaws/external/awscli/commands/ec2/RunInstances.rb diff --git a/lib/zaws/awscli/commands/ec2/StopInstances.rb b/lib/zaws/external/awscli/commands/ec2/StopInstances.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/ec2/StopInstances.rb rename to lib/zaws/external/awscli/commands/ec2/StopInstances.rb diff --git a/lib/zaws/awscli/commands/iam.rb b/lib/zaws/external/awscli/commands/iam.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/iam.rb rename to lib/zaws/external/awscli/commands/iam.rb diff --git a/lib/zaws/awscli/commands/iam/GetPolicy.rb b/lib/zaws/external/awscli/commands/iam/GetPolicy.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/iam/GetPolicy.rb rename to lib/zaws/external/awscli/commands/iam/GetPolicy.rb diff --git a/lib/zaws/awscli/commands/iam/GetPolicyVersion.rb b/lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/iam/GetPolicyVersion.rb rename to lib/zaws/external/awscli/commands/iam/GetPolicyVersion.rb diff --git a/lib/zaws/awscli/commands/iam/GetRolePolicy.rb b/lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/commands/iam/GetRolePolicy.rb rename to lib/zaws/external/awscli/commands/iam/GetRolePolicy.rb diff --git a/lib/zaws/awscli/credentials.rb b/lib/zaws/external/awscli/credentials.rb similarity index 100% rename from lib/zaws/awscli/credentials.rb rename to lib/zaws/external/awscli/credentials.rb diff --git a/lib/zaws/awscli/data.rb b/lib/zaws/external/awscli/data.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data.rb rename to lib/zaws/external/awscli/data.rb diff --git a/lib/zaws/awscli/data/ec2.rb b/lib/zaws/external/awscli/data/ec2.rb similarity index 95% rename from lib/zaws/awscli/data/ec2.rb rename to lib/zaws/external/awscli/data/ec2.rb index 0f65daf..e880e16 100755 --- a/lib/zaws/awscli/data/ec2.rb +++ b/lib/zaws/external/awscli/data/ec2.rb @@ -18,7 +18,7 @@ def subnet end def instance - @_Instance ||= (ZAWS::AWSCLI::Data::EC2::Instance.new(@shellout, self)) + @_Instance ||= (ZAWS::AWSCLI::Data::EC2::Instance.new(@shellout, self.filestore)) return @_Instance end diff --git a/lib/zaws/awscli/data/ec2/instance.rb b/lib/zaws/external/awscli/data/ec2/instance.rb similarity index 95% rename from lib/zaws/awscli/data/ec2/instance.rb rename to lib/zaws/external/awscli/data/ec2/instance.rb index f7a7fc7..6d5d9c0 100755 --- a/lib/zaws/awscli/data/ec2/instance.rb +++ b/lib/zaws/external/awscli/data/ec2/instance.rb @@ -4,9 +4,9 @@ class Data class EC2 class Instance - def initialize(shellout, ec2) + def initialize(shellout, filestore) @shellout=shellout - @ec2=ec2 + @filestore=filestore @instance_hash=nil end @@ -15,7 +15,7 @@ def validJSON end def load_cached(command,verbose) - fileinstances = @ec2.filestore.retrieve("instance",command) + fileinstances = @filestore.retrieve("instance",command) if fileinstances.nil? return false else @@ -31,7 +31,7 @@ def load(command, data, verbose,cache=true) begin @instance_hash =JSON.parse(data) create_lookup_hashes() - @ec2.filestore.store("instance",@instance_raw_data,Time.now + @ec2.filestore.timeout,command) if cache + @filestore.store("instance",@instance_raw_data,Time.now + @filestore.timeout,command) if cache rescue JSON::ParserError => e end end diff --git a/lib/zaws/awscli/data/ec2/subnet.rb b/lib/zaws/external/awscli/data/ec2/subnet.rb similarity index 100% rename from lib/zaws/awscli/data/ec2/subnet.rb rename to lib/zaws/external/awscli/data/ec2/subnet.rb diff --git a/lib/zaws/awscli/data/ec2/vpc.rb b/lib/zaws/external/awscli/data/ec2/vpc.rb similarity index 100% rename from lib/zaws/awscli/data/ec2/vpc.rb rename to lib/zaws/external/awscli/data/ec2/vpc.rb diff --git a/lib/zaws/awscli/data/iam.rb b/lib/zaws/external/awscli/data/iam.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data/iam.rb rename to lib/zaws/external/awscli/data/iam.rb diff --git a/lib/zaws/awscli/data/iam/policy.rb b/lib/zaws/external/awscli/data/iam/policy.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data/iam/policy.rb rename to lib/zaws/external/awscli/data/iam/policy.rb diff --git a/lib/zaws/awscli/data/iam/policyDocument.rb b/lib/zaws/external/awscli/data/iam/policyDocument.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data/iam/policyDocument.rb rename to lib/zaws/external/awscli/data/iam/policyDocument.rb diff --git a/lib/zaws/awscli/data/iam/policyVersion.rb b/lib/zaws/external/awscli/data/iam/policyVersion.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data/iam/policyVersion.rb rename to lib/zaws/external/awscli/data/iam/policyVersion.rb diff --git a/lib/zaws/awscli/data/iam/role_policy.rb b/lib/zaws/external/awscli/data/iam/role_policy.rb old mode 100644 new mode 100755 similarity index 100% rename from lib/zaws/awscli/data/iam/role_policy.rb rename to lib/zaws/external/awscli/data/iam/role_policy.rb diff --git a/lib/zaws/external/awscli/generators/api/aws/aws.rb b/lib/zaws/external/awscli/generators/api/aws/aws.rb new file mode 100755 index 0000000..097dafb --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/aws/aws.rb @@ -0,0 +1,44 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class AWS + class AWS + def initialize + @subcommand=nil + @output=nil + @region=nil + self + end + + def with_output(output) + @output=output + self + end + + def with_region(region) + @region=region + self + end + + def with_subcommand(subcommand) + @subcommand=subcommand + self + end + + def get_command + command = "aws " + command = "#{command}--output #{@output} " if @output + command = "#{command}--region #{@region} " if @region + command = "#{command}#{@subcommand.get_command}" if @subcommand + return command.strip + end + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/create_tags.rb b/lib/zaws/external/awscli/generators/api/ec2/create_tags.rb new file mode 100755 index 0000000..f9a4fdb --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/create_tags.rb @@ -0,0 +1,38 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class CreateTags + def initialize + @resource + @tags + self + end + + def resource(resource) + @resource=resource + self + end + + def tags(tags) + @tags=tags.get_tags_array + self + end + + def get_command + command = "ec2 create-tags" + command = "#{command} --resources #{@resource}" if @resource + command = "#{command} --tags \"Key=#{@tags[0]['Key']},Value=#{@tags[0]['Value']}\" " if @tags + return command + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/describe_instances.rb b/lib/zaws/external/awscli/generators/api/ec2/describe_instances.rb new file mode 100755 index 0000000..0d4434b --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/describe_instances.rb @@ -0,0 +1,31 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class DescribeInstances + def initialize + @filter=nil + self + end + + def filter(filter) + @filter=filter + self + end + + def get_command + command = "ec2 describe-instances" + command = "#{command} #{@filter.get_command}" if @filter + return command + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/describe_security_groups.rb b/lib/zaws/external/awscli/generators/api/ec2/describe_security_groups.rb new file mode 100755 index 0000000..81d4757 --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/describe_security_groups.rb @@ -0,0 +1,31 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class DescribeSecurityGroups + def initialize + @filter=nil + self + end + + def filter(filter) + @filter=filter + self + end + + def get_command + command = "ec2 describe-security-groups" + command = "#{command} #{@filter.get_command}" if @filter + return command + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/describe_subnets.rb b/lib/zaws/external/awscli/generators/api/ec2/describe_subnets.rb new file mode 100755 index 0000000..864d848 --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/describe_subnets.rb @@ -0,0 +1,31 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class DescribeSubnets + def initialize + @filter=nil + self + end + + def filter(filter) + @filter=filter + self + end + + def get_command + command = "ec2 describe-subnets" + command = "#{command} #{@filter.get_command}" if @filter + return command + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/filter.rb b/lib/zaws/external/awscli/generators/api/ec2/filter.rb new file mode 100755 index 0000000..266e552 --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/filter.rb @@ -0,0 +1,54 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class Filter + def initialize + @group_name=nil + @vpc_id=nil + @tags=nil + self + end + + def group_name(group_name) + @group_name=group_name + self + end + + def vpc_id(vpc_id) + @vpc_id=vpc_id + self + end + + def tags(tags) + @tags=tags.get_tags_array + self + end + + def get_command + command ="" + + if !@vpc_id.nil? or !@group_name.nil? + command = "--filter " + command = "#{command}\"Name=vpc-id,Values=#{@vpc_id}\" " if @vpc_id + command = "#{command}\"Name=group-name,Values=#{@group_name}\" " if @group_name + if @tags + @tags.each do |x| + command = "#{command}\"Name=tag:#{x['Key']},Values=#{x['Value']}\" " if @tags + end + end + end + + return command + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/api/ec2/modify_instance_attribute.rb b/lib/zaws/external/awscli/generators/api/ec2/modify_instance_attribute.rb new file mode 100755 index 0000000..528ccf4 --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/modify_instance_attribute.rb @@ -0,0 +1,43 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class ModifyInstanceAttribute + def initialize + self + end + + def source_dest_check() + @source_dest_check=true + self + end + + def no_source_dest_check() + @no_source_dest_check=true + self + end + + def instance_id(id) + @instance_id=id + self + end + + def get_command + command = "ec2 modify-instance-attribute " + command = "#{command}--instance-id=#{@instance_id} " if @instance_id + command = "#{command}--no-source-dest-check " if @no_source_dest_check + command = "#{command}--source-dest-check " if @source_dest_check + return command + end + + end + end + end + end + end + end +end + + diff --git a/lib/zaws/external/awscli/generators/api/ec2/network_interfaces.rb b/lib/zaws/external/awscli/generators/api/ec2/network_interfaces.rb new file mode 100755 index 0000000..5b3d467 --- /dev/null +++ b/lib/zaws/external/awscli/generators/api/ec2/network_interfaces.rb @@ -0,0 +1,65 @@ +module ZAWS + class External + class AWSCLI + class Generators + class API + class EC2 + class NetworkInterfaces + def initialize + @net= {} + @net["NetworkInterfaces"]= [] + self + end + + def add_group(network_interface_number, group) + resize_network_interface_array(network_interface_number) + if not @net["NetworkInterfaces"][network_interface_number]["Groups"] + @net["NetworkInterfaces"][network_interface_number]["Groups"] = [] + end + @net["NetworkInterfaces"][network_interface_number]["Groups"] << group + self + end + + def private_ip_address(network_interface_number, ip) + resize_network_interface_array(network_interface_number) + @net["NetworkInterfaces"][network_interface_number]["PrivateIpAddress"] = ip + self + end + + def device_index(network_interface_number, index) + resize_network_interface_array(network_interface_number) + @net["NetworkInterfaces"][network_interface_number]["DeviceIndex"] = index + self + end + + def subnet_id(network_interface_number, id) + resize_network_interface_array(network_interface_number) + @net["NetworkInterfaces"][network_interface_number]["SubnetId"] = id + self + end + + def resize_network_interface_array(index) + while index > @net["NetworkInterfaces"].length-1 + @net["NetworkInterfaces"].push({}) + end + end + + def get_json + @net.to_json + end + + def get_network_interfaces_array + @net["NetworkInterfaces"] + end + + def get_network_interfaces_array_to_json + @net["NetworkInterfaces"].to_json + end + + end + end + end + end + end + end +end diff --git a/lib/zaws/external/awscli/generators/result/ec2/instances.rb b/lib/zaws/external/awscli/generators/result/ec2/instances.rb new file mode 100755 index 0000000..80c6b09 --- /dev/null +++ b/lib/zaws/external/awscli/generators/result/ec2/instances.rb @@ -0,0 +1,53 @@ +module ZAWS + class External + class AWSCLI + class Generators + class Result + class EC2 + class Instances + def initialize + @res= {} + @res["Reservations"]= [] + @res["Reservations"] << { "Instances" => [] } + self + end + + def instance_id(instance_number, id) + resize_instances_array(instance_number) + @res["Reservations"][0]["Instances"][instance_number]["InstanceId"]=id + self + end + + def security_groups(instance_number,groups) + @res["Reservations"][0]["Instances"][instance_number]["SecurityGroups"]=groups.get_security_groups_array + self + end + + def network_interfaces(instance_number,interfaces) + @res["Reservations"][0]["Instances"][instance_number]["NetworkInterfaces"]=interfaces.get_network_interfaces_array + self + end + + def tags(instance_number,tags) + @res["Reservations"][0]["Instances"][instance_number]["Tags"]=tags.get_tags_array + self + end + + def resize_instances_array(index) + while index > @res["Reservations"][0]["Instances"].length-1 + @res["Reservations"][0]["Instances"].push({}) + end + end + + def get_json + @res.to_json + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb b/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb new file mode 100755 index 0000000..4b2d73d --- /dev/null +++ b/lib/zaws/external/awscli/generators/result/ec2/network_interfaces.rb @@ -0,0 +1,47 @@ +module ZAWS + class External + class AWSCLI + class Generators + class Result + class EC2 + class NetworkInterfaces + def initialize + @net= {} + @net["NetworkInterfaces"]= [] + self + end + + def network_interface_id(network_interface_number, id) + resize_network_interface_array(network_interface_number) + @net["NetworkInterfaces"][network_interface_number]["NetworkInterfaceId"]=id + self + end + + def groups(network_interface_number, groups) + resize_network_interface_array(network_interface_number) + @net["NetworkInterfaces"][network_interface_number]["Groups"]=groups.get_security_groups_array + self + end + + def resize_network_interface_array(index) + while index > @net["NetworkInterfaces"].length-1 + @net["NetworkInterfaces"].push({}) + end + end + + def get_json + @net.to_json + end + + def get_network_interfaces_array + @net["NetworkInterfaces"] + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb b/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb new file mode 100755 index 0000000..85f07b8 --- /dev/null +++ b/lib/zaws/external/awscli/generators/result/ec2/security_groups.rb @@ -0,0 +1,65 @@ +module ZAWS + class External + class AWSCLI + class Generators + class Result + class EC2 + class SecurityGroups + def initialize + @sgroups= {} + @sgroups["SecurityGroups"]= [] + self + end + + def group_name(security_group_number, name) + resize_security_groups_array(security_group_number) + @sgroups["SecurityGroups"][security_group_number]["GroupName"]=name + self + end + + def group_id(security_group_number, id) + resize_security_groups_array(security_group_number) + @sgroups["SecurityGroups"][security_group_number]["GroupId"]=id + self + end + + def vpc_id(security_group_number, id) + resize_security_groups_array(security_group_number) + @sgroups["SecurityGroups"][security_group_number]["VpcId"]=id + self + end + + def owner_id(security_group_number, id) + resize_security_groups_array(security_group_number) + @sgroups["SecurityGroups"][security_group_number]["OwnerId"]=id + self + end + + def description(security_group_number, description) + resize_security_groups_array(security_group_number) + @sgroups["SecurityGroups"][security_group_number]["Description"]=description + self + end + + def resize_security_groups_array(index) + while index > @sgroups["SecurityGroups"].length-1 + @sgroups["SecurityGroups"].push({}) + end + end + + def get_json + @sgroups.to_json + end + + def get_security_groups_array + @sgroups["SecurityGroups"] + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/result/ec2/subnets.rb b/lib/zaws/external/awscli/generators/result/ec2/subnets.rb new file mode 100755 index 0000000..983de89 --- /dev/null +++ b/lib/zaws/external/awscli/generators/result/ec2/subnets.rb @@ -0,0 +1,77 @@ +module ZAWS + class External + class AWSCLI + class Generators + class Result + class EC2 + class Subnets + def initialize + @subnets= {} + @subnets["Subnets"]= [] + self + end + + def vpc_id(subnet_number, vpc_id) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["VpcId"]=vpc_id + self + end + + def cidr_block(subnet_number, cidr) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["CidrBlock"]=cidr + self + end + + def map_public_ip_on_launch(subnet_number, cidr) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["MapPublicIpOnLaunch"]=cidr + self + end + + def default_for_az(subnet_number, default) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["DefaultForAz"]=default + self + end + + def state(subnet_number, state) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["State"]=state + self + end + + def available_ip_address_count(subnet_number, count) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["AvailableIpAddressCount"]=count + self + end + + def subnet_id(subnet_number, id) + resize_subnets_array(subnet_number) + @subnets["Subnets"][subnet_number]["SubnetId"]=id + self + end + + def resize_subnets_array(index) + while index > @subnets["Subnets"].length-1 + @subnets["Subnets"].push({}) + end + end + + def get_json + @subnets.to_json + end + + def get_subnets_array + @subnets["Subnets"] + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/external/awscli/generators/result/ec2/tags.rb b/lib/zaws/external/awscli/generators/result/ec2/tags.rb new file mode 100755 index 0000000..747cae0 --- /dev/null +++ b/lib/zaws/external/awscli/generators/result/ec2/tags.rb @@ -0,0 +1,34 @@ +module ZAWS + class External + class AWSCLI + class Generators + class Result + class EC2 + class Tags + def initialize + @tags= {} + @tags["Tags"]= [] + self + end + + def add(key, value) + @tags["Tags"] << { "Value"=>value,"Key"=>key } + self + end + + def get_json + @tags.to_json + end + + def get_tags_array + @tags["Tags"] + end + + end + end + end + end + end + end +end + diff --git a/lib/zaws/awscli/regions.rb b/lib/zaws/external/awscli/regions.rb similarity index 100% rename from lib/zaws/awscli/regions.rb rename to lib/zaws/external/awscli/regions.rb diff --git a/lib/zaws/nessusapi/data/agents.rb b/lib/zaws/external/nessusapi/data/agents.rb similarity index 100% rename from lib/zaws/nessusapi/data/agents.rb rename to lib/zaws/external/nessusapi/data/agents.rb diff --git a/lib/zaws/nessusapi/data/scanners.rb b/lib/zaws/external/nessusapi/data/scanners.rb similarity index 100% rename from lib/zaws/nessusapi/data/scanners.rb rename to lib/zaws/external/nessusapi/data/scanners.rb diff --git a/lib/zaws/nessusapi/nessusapi.rb b/lib/zaws/external/nessusapi/nessusapi.rb similarity index 100% rename from lib/zaws/nessusapi/nessusapi.rb rename to lib/zaws/external/nessusapi/nessusapi.rb diff --git a/lib/zaws/nessusapi/reources.rb b/lib/zaws/external/nessusapi/reources.rb similarity index 100% rename from lib/zaws/nessusapi/reources.rb rename to lib/zaws/external/nessusapi/reources.rb diff --git a/lib/zaws/nessusapi/resources/agents.rb b/lib/zaws/external/nessusapi/resources/agents.rb similarity index 100% rename from lib/zaws/nessusapi/resources/agents.rb rename to lib/zaws/external/nessusapi/resources/agents.rb diff --git a/lib/zaws/nessusapi/resources/agents/list.rb b/lib/zaws/external/nessusapi/resources/agents/list.rb similarity index 100% rename from lib/zaws/nessusapi/resources/agents/list.rb rename to lib/zaws/external/nessusapi/resources/agents/list.rb diff --git a/lib/zaws/nessusapi/resources/scanners.rb b/lib/zaws/external/nessusapi/resources/scanners.rb similarity index 100% rename from lib/zaws/nessusapi/resources/scanners.rb rename to lib/zaws/external/nessusapi/resources/scanners.rb diff --git a/lib/zaws/nessusapi/resources/scanners/list.rb b/lib/zaws/external/nessusapi/resources/scanners/list.rb similarity index 100% rename from lib/zaws/nessusapi/resources/scanners/list.rb rename to lib/zaws/external/nessusapi/resources/scanners/list.rb diff --git a/lib/zaws/newrelicapi/data/servers.rb b/lib/zaws/external/newrelicapi/data/servers.rb similarity index 100% rename from lib/zaws/newrelicapi/data/servers.rb rename to lib/zaws/external/newrelicapi/data/servers.rb diff --git a/lib/zaws/newrelicapi/newrelic_client.rb b/lib/zaws/external/newrelicapi/newrelic_client.rb similarity index 100% rename from lib/zaws/newrelicapi/newrelic_client.rb rename to lib/zaws/external/newrelicapi/newrelic_client.rb diff --git a/lib/zaws/newrelicapi/newrelic_creds.rb b/lib/zaws/external/newrelicapi/newrelic_creds.rb similarity index 100% rename from lib/zaws/newrelicapi/newrelic_creds.rb rename to lib/zaws/external/newrelicapi/newrelic_creds.rb diff --git a/lib/zaws/newrelicapi/newrelicapi.rb b/lib/zaws/external/newrelicapi/newrelicapi.rb similarity index 100% rename from lib/zaws/newrelicapi/newrelicapi.rb rename to lib/zaws/external/newrelicapi/newrelicapi.rb diff --git a/lib/zaws/newrelicapi/resources/servers.rb b/lib/zaws/external/newrelicapi/resources/servers.rb similarity index 100% rename from lib/zaws/newrelicapi/resources/servers.rb rename to lib/zaws/external/newrelicapi/resources/servers.rb diff --git a/lib/zaws/newrelicapi/resources/servers/list.rb b/lib/zaws/external/newrelicapi/resources/servers/list.rb similarity index 100% rename from lib/zaws/newrelicapi/resources/servers/list.rb rename to lib/zaws/external/newrelicapi/resources/servers/list.rb diff --git a/lib/zaws/sumoapi/data/collectors.rb b/lib/zaws/external/sumoapi/data/collectors.rb similarity index 100% rename from lib/zaws/sumoapi/data/collectors.rb rename to lib/zaws/external/sumoapi/data/collectors.rb diff --git a/lib/zaws/sumoapi/data/sources.rb b/lib/zaws/external/sumoapi/data/sources.rb similarity index 100% rename from lib/zaws/sumoapi/data/sources.rb rename to lib/zaws/external/sumoapi/data/sources.rb diff --git a/lib/zaws/sumoapi/resources/collectors.rb b/lib/zaws/external/sumoapi/resources/collectors.rb similarity index 100% rename from lib/zaws/sumoapi/resources/collectors.rb rename to lib/zaws/external/sumoapi/resources/collectors.rb diff --git a/lib/zaws/sumoapi/resources/collectors/list.rb b/lib/zaws/external/sumoapi/resources/collectors/list.rb similarity index 100% rename from lib/zaws/sumoapi/resources/collectors/list.rb rename to lib/zaws/external/sumoapi/resources/collectors/list.rb diff --git a/lib/zaws/sumoapi/resources/sources.rb b/lib/zaws/external/sumoapi/resources/sources.rb similarity index 100% rename from lib/zaws/sumoapi/resources/sources.rb rename to lib/zaws/external/sumoapi/resources/sources.rb diff --git a/lib/zaws/sumoapi/resources/sources/list.rb b/lib/zaws/external/sumoapi/resources/sources/list.rb similarity index 100% rename from lib/zaws/sumoapi/resources/sources/list.rb rename to lib/zaws/external/sumoapi/resources/sources/list.rb diff --git a/lib/zaws/sumoapi/sumo_client.rb b/lib/zaws/external/sumoapi/sumo_client.rb similarity index 100% rename from lib/zaws/sumoapi/sumo_client.rb rename to lib/zaws/external/sumoapi/sumo_client.rb diff --git a/lib/zaws/sumoapi/sumo_creds.rb b/lib/zaws/external/sumoapi/sumo_creds.rb similarity index 100% rename from lib/zaws/sumoapi/sumo_creds.rb rename to lib/zaws/external/sumoapi/sumo_creds.rb diff --git a/lib/zaws/sumoapi/sumoapi.rb b/lib/zaws/external/sumoapi/sumoapi.rb similarity index 100% rename from lib/zaws/sumoapi/sumoapi.rb rename to lib/zaws/external/sumoapi/sumoapi.rb diff --git a/lib/zaws/repository/filestore.rb b/lib/zaws/helper/filestore.rb similarity index 87% rename from lib/zaws/repository/filestore.rb rename to lib/zaws/helper/filestore.rb index 9d9edc7..dd3f216 100755 --- a/lib/zaws/repository/filestore.rb +++ b/lib/zaws/helper/filestore.rb @@ -8,10 +8,12 @@ class Filestore attr_accessor :location attr_accessor :timeout - def initialize() + def initialize(empty=false) + @empty=empty end def store(key,value,expires,command=nil) + return if @empty storage = {} storage['value']=value storage['expires']=expires.strftime('%s') @@ -27,6 +29,7 @@ def store(key,value,expires,command=nil) end def retrieve(key,command=nil) + return if @empty if command.nil? filename=key else diff --git a/lib/zaws/helper/output.rb b/lib/zaws/helper/output.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/helper/shell.rb b/lib/zaws/helper/shell.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/helper/zfile.rb b/lib/zaws/helper/zfile.rb old mode 100644 new mode 100755 diff --git a/lib/zaws/controllers/ai.rb b/lib/zaws/services/ai.rb similarity index 100% rename from lib/zaws/controllers/ai.rb rename to lib/zaws/services/ai.rb diff --git a/lib/zaws/controllers/aws.rb b/lib/zaws/services/aws.rb similarity index 100% rename from lib/zaws/controllers/aws.rb rename to lib/zaws/services/aws.rb diff --git a/lib/zaws/controllers/chef.rb b/lib/zaws/services/chef.rb similarity index 100% rename from lib/zaws/controllers/chef.rb rename to lib/zaws/services/chef.rb diff --git a/lib/zaws/controllers/config.rb b/lib/zaws/services/config.rb similarity index 100% rename from lib/zaws/controllers/config.rb rename to lib/zaws/services/config.rb diff --git a/lib/zaws/services/ec2/compute.rb b/lib/zaws/services/ec2/compute.rb index e8623a4..db4e2d5 100755 --- a/lib/zaws/services/ec2/compute.rb +++ b/lib/zaws/services/ec2/compute.rb @@ -167,9 +167,9 @@ def assoc_security_group(region, textout, verbose, vpcid, externalid, sgroup) end def tag_resource(region, resourceid, externalid, verbose=nil) - comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags Key=externalid,Value=#{externalid}" + comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags \"Key=externalid,Value=#{externalid}\"" tag_creation=@shellout.cli(comline, verbose) - comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags Key=Name,Value=#{externalid}" + comline="aws --output json --region #{region} ec2 create-tags --resources #{resourceid} --tags \"Key=Name,Value=#{externalid}\"" tag_creation=@shellout.cli(comline, verbose) end diff --git a/lib/zaws/controllers/nessus.rb b/lib/zaws/services/nessus.rb similarity index 100% rename from lib/zaws/controllers/nessus.rb rename to lib/zaws/services/nessus.rb diff --git a/lib/zaws/services/nessus/agents.rb b/lib/zaws/services/nessus/agents.rb index 65cd1f8..b48a1eb 100755 --- a/lib/zaws/services/nessus/agents.rb +++ b/lib/zaws/services/nessus/agents.rb @@ -8,9 +8,9 @@ def initialize(shellout, nessus) @nessus=nessus end - def view(home,scanner,out,verbose=nil) - @nessus.nessusapi.home=home - out.puts(@nessus.nessusapi.data_agents.view(scanner,verbose).to_yaml) + def view(params) + @nessus.nessusapi.home=params['home'] + @nessus.nessusapi.data_agents.view(params['scanner'],nil).to_yaml end end diff --git a/lib/zaws/services/nessus/scanners.rb b/lib/zaws/services/nessus/scanners.rb index 2e85658..c95e832 100755 --- a/lib/zaws/services/nessus/scanners.rb +++ b/lib/zaws/services/nessus/scanners.rb @@ -8,9 +8,9 @@ def initialize(shellout, nessus) @nessus=nessus end - def view(home,out,verbose=nil) - @nessus.nessusapi.home=home - @nessus.nessusapi.data_scanners.view(verbose) + def view(params) + @nessus.nessusapi.home=params['home'] + @nessus.nessusapi.data_scanners.view(nil).to_yaml end end diff --git a/lib/zaws/controllers/newrelic.rb b/lib/zaws/services/newrelic.rb similarity index 100% rename from lib/zaws/controllers/newrelic.rb rename to lib/zaws/services/newrelic.rb diff --git a/lib/zaws/controllers/sumo.rb b/lib/zaws/services/sumo.rb similarity index 100% rename from lib/zaws/controllers/sumo.rb rename to lib/zaws/services/sumo.rb diff --git a/lib/zaws/controllers/vmware.rb b/lib/zaws/services/vmware.rb similarity index 100% rename from lib/zaws/controllers/vmware.rb rename to lib/zaws/services/vmware.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/awscli/data/ec2/instance_spec.rb b/spec/zaws/awscli/data/ec2/instance_spec.rb index 46e8424..9b491c8 100755 --- a/spec/zaws/awscli/data/ec2/instance_spec.rb +++ b/spec/zaws/awscli/data/ec2/instance_spec.rb @@ -61,13 +61,16 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @data_instance = ZAWS::AWSCLI::Data::EC2::Instance.new(@shellout, nil) + @filestore=double('ZAWS::Repository::Filestore') + @data_instance = ZAWS::AWSCLI::Data::EC2::Instance.new(@shellout, @filestore) } describe '#names_by_ids' do context 'the name/id data is loaded' do it 'returns instance ids as list of strings' do + expect(@filestore).to receive(:timeout).with(any_args).and_return(0) + expect(@filestore).to receive(:store).with(any_args) @data_instance.load(nil, vap_describe_instance, nil) expect(@data_instance.names_by_ids(vap_list_instance_ids)).to eq(var_list_instance_names) end diff --git a/spec/zaws/awscli/data/iam/policyDocument_spec.rb b/spec/zaws/awscli/data/iam/policyDocument_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/awscli/data/iam/role_policy_spec.rb b/spec/zaws/awscli/data/iam/role_policy_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/awscli/get_aws_version_spec.rb b/spec/zaws/awscli/get_aws_version_spec.rb old mode 100644 new mode 100755 index 8810c51..ea2d7ab --- a/spec/zaws/awscli/get_aws_version_spec.rb +++ b/spec/zaws/awscli/get_aws_version_spec.rb @@ -7,7 +7,7 @@ textout=double('outout') shellout=double('ZAWS::Helper::Shell') expect(shellout).to receive(:cli).with("aws --version",nil).and_return("aws-cli/1.2.13 Python/2.7.5 Linux/3.10.0-123.el7.x86_64") - awscli=ZAWS::AWSCLI.new(shellout) + awscli=ZAWS::AWSCLI.new(shellout,true) expect(awscli.version).to eq('aws-cli/1.2.13') end diff --git a/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb b/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb index e153731..2b174a6 100755 --- a/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb +++ b/spec/zaws/ec2/compute/instance_id_by_external_id_spec.rb @@ -5,7 +5,7 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout,true)) } describe "#instance_id_by_external_id" do @@ -17,7 +17,7 @@ ] } eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'",nil).and_return(compute_instances) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-instances --filter \"Name=vpc-id,Values=my_vpc_id\" \"Name=tag:externalid,Values=my_instance\"",nil).and_return(compute_instances) instanceid = @aws.ec2.compute.instance_id_by_external_id('us-west-1','my_instance','my_vpc_id',nil,nil) expect(instanceid).to eq("i-XXXXXXX") end diff --git a/spec/zaws/ec2/compute/management_spec.rb b/spec/zaws/ec2/compute/management_spec.rb index 6e77161..8f1e5fd 100755 --- a/spec/zaws/ec2/compute/management_spec.rb +++ b/spec/zaws/ec2/compute/management_spec.rb @@ -2,19 +2,19 @@ describe ZAWS::Services::EC2::Compute do - let(:vap_region) {"us-west-1"} - let(:vap_role) {"my_role"} - let(:vap_policy) {"my_policy"} + let(:vap_region) { "us-west-1" } + let(:vap_role) { "my_role" } + let(:vap_policy) { "my_policy" } - let(:vap_my_instance_id1) {"i-abcdefg1"} - let(:vap_my_instance_name1) {"my-name1"} - let(:vap_my_instance_id2) {"i-abcdefg2"} - let(:vap_my_instance_name2) {"my-name2"} - let(:vap_my_instance_id3) {"i-abcdefg3"} - let(:vap_my_instance_name3) {"my-name3"} + let(:vap_my_instance_id1) { "i-abcdefg1" } + let(:vap_my_instance_name1) { "my-name1" } + let(:vap_my_instance_id2) { "i-abcdefg2" } + let(:vap_my_instance_name2) { "my-name2" } + let(:vap_my_instance_id3) { "i-abcdefg3" } + let(:vap_my_instance_name3) { "my-name3" } - let(:vap_policy_arn) {"arn:aws:iam::123456789abc:policy/#{vap_policy}"} - let(:vap_policy_version) {"v2"} + let(:vap_policy_arn) { "arn:aws:iam::123456789abc:policy/#{vap_policy}" } + let(:vap_policy_version) { "v2" } let(:var_policy_doc) { <<-eos { @@ -76,36 +76,35 @@ eos } - - let(:options) { {:region => vap_region,:viewtype => 'json'}} + let(:options) { {:region => vap_region, :viewtype => 'json'} } let(:options_policy_arn) { {:region => vap_region, - :viewtype => 'json', - :policy_arn => vap_policy_arn, - :verbose => nil}} + :viewtype => 'json', + :policy_arn => vap_policy_arn, + :verbose => nil} } let(:options_start_name) { {:region => vap_region, - :name => vap_my_instance_name1, + :name => vap_my_instance_name1, :verbose => nil, - :skipruncheck => true}} + :skipruncheck => true} } let(:options_stop_name) { {:region => vap_region, - :name => vap_my_instance_name2, - :verbose => nil, - :skipruncheck => 0}} + :name => vap_my_instance_name2, + :verbose => nil, + :skipruncheck => 0} } let(:options_set_interval) { {:region => vap_region, - :name => vap_my_instance_name2, - :viewtype => 'json', - :policy_arn => vap_policy_arn, - :verbose => nil, - :overridebasetime => 0}} + :name => vap_my_instance_name2, + :viewtype => 'json', + :policy_arn => vap_policy_arn, + :verbose => nil, + :overridebasetime => 0} } let(:options_interval_cron) { {:region => vap_region, - :viewtype => 'json', - :policy_arn => vap_policy_arn, - :verbose => nil, - :overridebasetime => 3601}} + :viewtype => 'json', + :policy_arn => vap_policy_arn, + :verbose => nil, + :overridebasetime => 3601} } let(:var_policy) { <<-eos { @@ -128,10 +127,10 @@ }, "PolicyName": "testStopStart" } - eos - } + eos + } - let(:var_describe_instance) { <<-eos + let(:var_describe_instance) { <<-eos { "Reservations": [ { @@ -210,130 +209,156 @@ ] } - eos - } + eos + } - let(:vap_list_instance_ids) {"i-abcdefg1\ni-abcdefg2"} - let(:var_list_instance_names) {"my-name1\nmy-name2"} - let(:interval_val) {"0:3600:test@test.com"} + let(:vap_list_instance_ids) { "i-abcdefg1\ni-abcdefg2" } + let(:var_list_instance_names) { "my-name1\nmy-name2" } + let(:interval_val) { "0:3600:test@test.com" } before(:each) { - @textout=double('outout') + @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @command_compute = ZAWS::Command::Compute.new([],options,{}); - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @command_compute = ZAWS::Command::Compute.new([], options, {}); + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,true)) @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true + @command_compute.out=@textout + @command_compute.print_exit_code = true } describe "#instance_id_by_external_id" do - it "provides an instance id when you give it a external id" do - - compute_instances = <<-eos - { "Reservations": [ - { "Instances" : [ {"InstanceId": "i-XXXXXXX","Tags": [ { "Value": "my_instance","Key": "externalid" } ] } ] } - ] } - eos - - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'",nil).and_return(compute_instances) - instanceid = @aws.ec2.compute.instance_id_by_external_id('us-west-1','my_instance','my_vpc_id',nil,nil) - expect(instanceid).to eq("i-XXXXXXX") - end + it "provides an instance id when you give it a external id" do + + tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new + tags = tags.add("externalid", "my_instance") + instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new + instances = instances.instance_id(0, "i-XXXXXXX") + instances = instances.tags(0, tags) + compute_instances=instances.get_json + + filter=ZAWS::External::AWSCLI::Generators::API::EC2::Filter.new + desc_instances = ZAWS::External::AWSCLI::Generators::API::EC2::DescribeInstances.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + desc_instances = desc_instances.filter(filter.vpc_id("my_vpc_id").tags(tags)) + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(desc_instances) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(compute_instances) + instanceid = @aws.ec2.compute.instance_id_by_external_id('us-west-1', 'my_instance', 'my_vpc_id', nil, nil) + expect(instanceid).to eq("i-XXXXXXX") + end end - describe "#tag_resource" do - it "tags an instance when created" do - tag_created = <<-eos + describe "#tag_resource" do + it "tags an instance when created" do + tag_created = <<-eos { "return":"true" } - eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources id-X --tags Key=externalid,Value=extername",nil).and_return(tag_created) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources id-X --tags Key=Name,Value=extername",nil).and_return(tag_created) - @aws.ec2.compute.tag_resource('us-west-1','id-X','extername') - end + eos + + tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new + tags = tags.add("externalid", "extername") + + create_tags = ZAWS::External::AWSCLI::Generators::API::EC2::CreateTags.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + create_tags = create_tags.resource("id-X").tags(tags) + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(create_tags) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(tag_created) + + tags = ZAWS::External::AWSCLI::Generators::Result::EC2::Tags.new + tags = tags.add("Name", "extername") + + create_tags = ZAWS::External::AWSCLI::Generators::API::EC2::CreateTags.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + create_tags = create_tags.resource("id-X").tags(tags) + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(create_tags) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(tag_created) + + @aws.ec2.compute.tag_resource('us-west-1', 'id-X', 'extername') + end end describe "#interval_eligible" do context "role policy exists" do - it "lists the names of the instances" do - @command_compute = ZAWS::Command::Compute.new([],options_policy_arn,{}); - @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}",nil).ordered.and_return(var_policy_meta_data) - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}",nil).ordered.and_return(var_policy_version_doc) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances",nil).and_return(var_describe_instance) - expect(@textout).to receive(:puts).with("my-name1\nmy-name2") - @command_compute.interval_eligible() - end - end + it "lists the names of the instances" do + @command_compute = ZAWS::Command::Compute.new([], options_policy_arn, {}); + @command_compute.aws=@aws + @command_compute.out=@textout + @command_compute.print_exit_code = true + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data) + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance) + expect(@textout).to receive(:puts).with("my-name1\nmy-name2") + @command_compute.interval_eligible() + end + end end describe "#start" do context "the instance is stopped, the name as been provided and the name exists" do - it "will start the instance" do - @command_compute = ZAWS::Command::Compute.new([],options_start_name,{}); - @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances",nil).and_return(var_describe_instance) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}",nil).and_return(var_describe_instance) - expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.") - @command_compute.start() - end - end + it "will start the instance" do + @command_compute = ZAWS::Command::Compute.new([], options_start_name, {}); + @command_compute.aws=@aws + @command_compute.out=@textout + @command_compute.print_exit_code = true + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}", nil).and_return(var_describe_instance) + expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.") + @command_compute.start() + end + end end describe "#stop" do context "the instance is running, the name as been provided and the name exists" do - it "will stop the instance" do - @command_compute = ZAWS::Command::Compute.new([],options_stop_name,{}); - @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances",nil).and_return(var_describe_instance) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}",nil).and_return(var_describe_instance) - expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.") - @command_compute.stop() - end - end + it "will stop the instance" do + @command_compute = ZAWS::Command::Compute.new([], options_stop_name, {}); + @command_compute.aws=@aws + @command_compute.out=@textout + @command_compute.print_exit_code = true + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}", nil).and_return(var_describe_instance) + expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.") + @command_compute.stop() + end + end end describe "#set_interval" do context "the instance exists" do - it "will tag instance with interval" do - @command_compute = ZAWS::Command::Compute.new([],options_set_interval,{}); - @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}",nil).ordered.and_return(var_policy_meta_data) - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}",nil).ordered.and_return(var_policy_version_doc) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances",nil).and_return(var_describe_instance) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 create-tags --resources #{vap_my_instance_id2} --tags Key=interval,Value=#{interval_val}",nil).and_return(var_describe_instance) - expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} tagged: Key=interval,Value=#{interval_val}") - @command_compute.set_interval(1,"test@test.com") - end - end + it "will tag instance with interval" do + @command_compute = ZAWS::Command::Compute.new([], options_set_interval, {}); + @command_compute.aws=@aws + @command_compute.out=@textout + @command_compute.print_exit_code = true + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data) + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 create-tags --resources #{vap_my_instance_id2} --tags Key=interval,Value=#{interval_val}", nil).and_return(var_describe_instance) + expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} tagged: Key=interval,Value=#{interval_val}") + @command_compute.set_interval(1, "test@test.com") + end + end end describe "#interval_cron" do context "one instance set to start that is stopped, one vice versa, one other" do - it "will start one, stop one, and nothing one" do - @command_compute = ZAWS::Command::Compute.new([],options_interval_cron,{}); - @command_compute.aws=@aws - @command_compute.out=@textout - @command_compute.print_exit_code = true - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}",nil).ordered.and_return(var_policy_meta_data) - expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}",nil).ordered.and_return(var_policy_version_doc) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances",nil).and_return(var_describe_instance) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}",nil).and_return(var_describe_instance) - expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}",nil).and_return(var_describe_instance) - expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.") - expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.") - @command_compute.interval_cron() - end - end + it "will start one, stop one, and nothing one" do + @command_compute = ZAWS::Command::Compute.new([], options_interval_cron, {}); + @command_compute.aws=@aws + @command_compute.out=@textout + @command_compute.print_exit_code = true + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy --policy-arn #{vap_policy_arn}", nil).ordered.and_return(var_policy_meta_data) + expect(@shellout).to receive(:cli).with("aws --output json iam get-policy-version --policy-arn #{vap_policy_arn} --version-id #{vap_policy_version}", nil).ordered.and_return(var_policy_version_doc) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 describe-instances", nil).and_return(var_describe_instance) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 start-instances --instance-ids #{vap_my_instance_id1}", nil).and_return(var_describe_instance) + expect(@shellout).to receive(:cli).with("aws --output json --region #{vap_region} ec2 stop-instances --instance-ids #{vap_my_instance_id2}", nil).and_return(var_describe_instance) + expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name1} started.") + expect(@textout).to receive(:puts).with("Instance #{vap_my_instance_name2} stopped.") + @command_compute.interval_cron() + end + end end diff --git a/spec/zaws/ec2/compute/network_spec.rb b/spec/zaws/ec2/compute/network_spec.rb index cf2f491..a4cda66 100755 --- a/spec/zaws/ec2/compute/network_spec.rb +++ b/spec/zaws/ec2/compute/network_spec.rb @@ -3,91 +3,91 @@ describe ZAWS::Services::EC2::Compute do before(:each) { - @textout=double('outout') + @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout, false)) } describe "#instance_ping?" do - it "determines an instance is reachable over the network with ping" do - - comline ='ping -q -c 2 0.0.0.0' - times_called = 0 - @shellout.stub(:cli).with(comline,nil).and_return do - times_called += 1 - raise Mixlib::ShellOut::ShellCommandFailed if times_called == 2 - end - @aws.ec2.compute.instance_ping?('0.0.0.0',10,1) - - end - - it "determines an instance is not reachable over the network with ping" do - - comline ='ping -q -c 2 0.0.0.0' - times_called = 0 - @shellout.stub(:cli).with(comline,nil).and_return do - times_called += 1 - raise Mixlib::ShellOut::ShellCommandFailed if times_called < 4 - end - expect {@aws.ec2.compute.instance_ping?('0.0.0.0',2,1)}.to raise_error(StandardError, 'Timeout before instance responded to ping.') - end + it "determines an instance is reachable over the network with ping" do + + comline ='ping -q -c 2 0.0.0.0' + times_called = 0 + @shellout.stub(:cli).with(comline, nil).and_return do + times_called += 1 + raise Mixlib::ShellOut::ShellCommandFailed if times_called == 2 + end + @aws.ec2.compute.instance_ping?('0.0.0.0', 10, 1) + + end + + it "determines an instance is not reachable over the network with ping" do + + comline ='ping -q -c 2 0.0.0.0' + times_called = 0 + @shellout.stub(:cli).with(comline, nil).and_return do + times_called += 1 + raise Mixlib::ShellOut::ShellCommandFailed if times_called < 4 + end + expect { @aws.ec2.compute.instance_ping?('0.0.0.0', 2, 1) + }.to raise_error(StandardError, 'Timeout before instance responded to ping.') + end end describe "#nosdcheck" do - it "sets no source/destination check for instances intended to be NAT instances" do - nosd_check_result = <<-eos - { "return":"true" } - eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 modify-instance-attribute --instance-id=id-X --no-source-dest-check",nil).and_return(nosd_check_result) - @aws.ec2.compute.nosdcheck('us-west-1','id-X') - end + it "sets no source/destination check for instances intended to be NAT instances" do + nosd_check_result = '{ "return":"true" }' + + mod_inst_attribute = ZAWS::External::AWSCLI::Generators::API::EC2::ModifyInstanceAttribute.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + mod_inst_attribute = mod_inst_attribute.instance_id("id-X").no_source_dest_check + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(mod_inst_attribute) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(nosd_check_result) + @aws.ec2.compute.nosdcheck('us-west-1', 'id-X') + end end describe "#network_interface_json" do - it "provides a network interface structure" do - - subnets = <<-eos - { "Subnets": [ - { - "VpcId": "vpc-XXXXXX", - "CidrBlock": "10.0.1.0/24", - "MapPublicIpOnLaunch": false, - "DefaultForAz": false, - "State": "available", - "SubnetId": "subnet-XXXXXX", - "AvailableIpAddressCount": 251 - }, - { - "VpcId": "vpc-XXXXXX", - "CidrBlock": "10.0.0.0/24", - "MapPublicIpOnLaunch": false, - "DefaultForAz": false, - "State": "available", - "SubnetId": "subnet-YYYYYY", - "AvailableIpAddressCount": 251 - } - ] - } - eos - - sgroups = <<-eos - { - "SecurityGroups": [ - { - "Description": "My security group", - "GroupName": "my_security_group_name", - "OwnerId": "123456789012", - "GroupId": "sg-903004f8" - } - ] - } - eos - - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=my_vpc_id'",nil).and_return(subnets) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'",nil).and_return(sgroups) - bdm = @aws.ec2.compute.network_interface_json('us-west-1',nil,'my_vpc_id','10.0.0.6','my_security_group_name') - expect(bdm).to eq('[{"Groups":["sg-903004f8"],"PrivateIpAddress":"10.0.0.6","DeviceIndex":0,"SubnetId":"subnet-YYYYYY"}]') - - end + it "provides a network interface structure" do + + subnets = ZAWS::External::AWSCLI::Generators::Result::EC2::Subnets.new + count=0 + [["10.0.1.0/24", "subnet-XXXXXX"], ["10.0.0.0/24", "subnet-YYYYYY"]].each do |x| + subnets = subnets.vpc_id(count, "vpc-XXXXXX").cidr_block(count, x[0]).map_public_ip_on_launch(count, false) + subnets = subnets.default_for_az(count, false).state(count, "available").subnet_id(count, x[1]) + subnets = subnets.available_ip_address_count(count, 251) + count+=1 + end + subnets= subnets.get_json + + filter=ZAWS::External::AWSCLI::Generators::API::EC2::Filter.new + desc_subnets = ZAWS::External::AWSCLI::Generators::API::EC2::DescribeSubnets.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + desc_subnets = desc_subnets.filter(filter.vpc_id("my_vpc_id")) + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(desc_subnets) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(subnets) + + security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new + security_groups = security_groups.description(0, "My security group").group_name(0, "my_security_group_name") + security_groups = security_groups.owner_id(0, "123456789012").group_id(0, "sg-903004f8") + sgroups = security_groups.get_json + + filter=ZAWS::External::AWSCLI::Generators::API::EC2::Filter.new + desc_sec_grps = ZAWS::External::AWSCLI::Generators::API::EC2::DescribeSecurityGroups.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + desc_sec_grps = desc_sec_grps.filter(filter.vpc_id("my_vpc_id").group_name("my_security_group_name")) + aws_command = aws_command.with_output("json").with_region("us-west-1").with_subcommand(desc_sec_grps) + + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(sgroups) + + network_interfaces=ZAWS::External::AWSCLI::Generators::API::EC2::NetworkInterfaces.new + network_interfaces=network_interfaces.add_group(0, "sg-903004f8").private_ip_address(0, "10.0.0.6") + network_interfaces=network_interfaces.device_index(0, 0).subnet_id(0, "subnet-YYYYYY") + + bdm = @aws.ec2.compute.network_interface_json('us-west-1', nil, 'my_vpc_id', '10.0.0.6', 'my_security_group_name') + expect(bdm).to eq(network_interfaces.get_network_interfaces_array_to_json) + end end end diff --git a/spec/zaws/ec2/compute/node_spec.rb b/spec/zaws/ec2/compute/node_spec.rb index 829a9ad..4ba9747 100755 --- a/spec/zaws/ec2/compute/node_spec.rb +++ b/spec/zaws/ec2/compute/node_spec.rb @@ -5,7 +5,7 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout,true)) } describe "#placement_aggregate" do @@ -44,7 +44,7 @@ ] } eos - comline="aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'" + comline="aws --output json --region us-west-1 ec2 describe-instances --filter \"Name=vpc-id,Values=my_vpc_id\" \"Name=tag:externalid,Values=my_instance\"" expect(@shellout).to receive(:cli).with(comline,nil).and_return(compute_instances_without,compute_instances) @aws.ec2.compute.instance_running?('us-west-1','my_vpc_id','my_instance',3,1,nil) @@ -58,7 +58,7 @@ ] } eos - comline="aws --output json --region us-west-1 ec2 describe-instances --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=tag:externalid,Values=my_instance'" + comline="aws --output json --region us-west-1 ec2 describe-instances --filter \"Name=vpc-id,Values=my_vpc_id\" \"Name=tag:externalid,Values=my_instance\"" expect(@shellout).to receive(:cli).with(comline,nil).and_return(compute_instances_without,compute_instances_without) expect {@aws.ec2.compute.instance_running?('us-west-1','my_vpc_id','my_instance',5,2,nil)}.to raise_error(StandardError, 'Timeout before instance state code set to running(16).') diff --git a/spec/zaws/ec2/compute/storage_spec.rb b/spec/zaws/ec2/compute/storage_spec.rb index 43e5e6c..2e04f40 100755 --- a/spec/zaws/ec2/compute/storage_spec.rb +++ b/spec/zaws/ec2/compute/storage_spec.rb @@ -35,14 +35,14 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,false)) } describe "#add_volume" do it "creates, tags, and attachs a volume" do expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-volume --availability-zone us-west-1a --size 70", nil).and_return(volumes) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags Key=externalid,Value=extername", nil).and_return(tag_created) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags Key=Name,Value=extername", nil).and_return(tag_created) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags \"Key=externalid,Value=extername\"", nil).and_return(tag_created) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 create-tags --resources vol-1234abcd --tags \"Key=Name,Value=extername\"", nil).and_return(tag_created) expect(@shellout).to receive(:cli).with('ping -q -c 2 0.0.0.0', nil).and_return(true) expect(@shellout).to receive(:cli).with("aws --output json ec2 attach-volume --region us-west-1 --volume-id vol-1234abcd --instance-id id-X --device /dev/sda", nil).and_return(attach_volume) bdm = @aws.ec2.compute.add_volume('us-west-1', 'id-X', 'extername', '0.0.0.0', '/dev/sda', 'us-west-1a', 70, nil) diff --git a/spec/zaws/ec2/security_group_spec.rb b/spec/zaws/ec2/security_group_spec.rb index 5794cf3..35cbda4 100755 --- a/spec/zaws/ec2/security_group_spec.rb +++ b/spec/zaws/ec2/security_group_spec.rb @@ -1,92 +1,64 @@ require 'spec_helper' describe ZAWS::Services::EC2::SecurityGroup do - + before(:each) { - @textout=double('outout') + @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,false)) + + @var_security_group_id="sg-abcd1234" + @var_output_json="json" + @var_region="us-west-1" + @var_vpc_id="my_vpc_id" + @var_sec_group_name="my_security_group_name" } describe "#id_by_name" do - it "security group id by group name" do + it "security group id by group name" do + + security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new + security_groups = security_groups.group_name(0, @var_sec_group_name).group_id(0, @var_security_group_id) - sgroups = <<-eos - { - "SecurityGroups": [ - { - "Description": "My security group", - "GroupName": "my_security_group_name", - "OwnerId": "123456789012", - "GroupId": "sg-abcd1234" - } - ] - } - eos + filter=ZAWS::External::AWSCLI::Generators::API::EC2::Filter.new + desc_sec_grps = ZAWS::External::AWSCLI::Generators::API::EC2::DescribeSecurityGroups.new + aws_command = ZAWS::External::AWSCLI::Generators::API::AWS::AWS.new + desc_sec_grps = desc_sec_grps.filter(filter.vpc_id(@var_vpc_id).group_name(@var_sec_group_name)) + aws_command = aws_command.with_output(@var_output_json).with_region(@var_region).with_subcommand(desc_sec_grps) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-security-groups --filter 'Name=vpc-id,Values=my_vpc_id' 'Name=group-name,Values=my_security_group_name'",nil).and_return(sgroups) - expect(@textout).to receive(:puts).with('sg-abcd1234') - @aws.ec2.security_group.id_by_name('us-west-1',@textout,nil,'my_vpc_id','my_security_group_name') - end + expect(@shellout).to receive(:cli).with(aws_command.get_command, nil).and_return(security_groups.get_json) + expect(@textout).to receive(:puts).with(@var_security_group_id) + @aws.ec2.security_group.id_by_name(@var_region, @textout, nil, @var_vpc_id, @var_sec_group_name) + end end describe "#filter_groups_by_instances" do - it 'security group id by group name' do + it 'filters out groups with security group ids used on an instance provided' do - security_groups_raw = <<-eos - { "SecurityGroups": [ - { - "GroupName": "my_group_name", - "VpcId": "vpc-12345678", - "OwnerId": "123456789012", - "GroupId": "sg-C2345678" - }, - { - "GroupName": "default", - "VpcId": "vpc-1f6bb57a", - "OwnerId": "123456789012", - "GroupId": "sg-B2345678" - }, - { - "GroupName": "my_unused_group", - "VpcId": "vpc-12345678", - "OwnerId": "123456789012", - "GroupId": "sg-A2345678" - } - ] } - eos + security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new + security_groups = security_groups.group_name(0, "my_group_name").vpc_id(0, "vpc-12345678").owner_id(0, "123456789012").group_id(0, "sg-C2345678") + security_groups = security_groups.group_name(1, "default").vpc_id(1, "vpc-1f6bb57a").owner_id(1, "123456789012").group_id(1, "sg-B2345678") + security_groups = security_groups.group_name(2, "my_unused_group").vpc_id(2, "vpc-12345678").owner_id(2, "123456789012").group_id(2, "sg-A2345678") + security_groups_raw = security_groups.get_json - instances_raw = <<-eos - { "Reservations": [ - { "Instances": [ - { "InstanceId": "i-12345678", - "SecurityGroups": [ - { - "GroupName": "my_group_name", - "GroupId": "sg-C2345678" - } - ], - "NetworkInterfaces": [ - { - "NetworkInterfaceId": "eni-12345678", - "Groups": [ - { - "GroupName": "my_group_name", - "GroupId": "sg-C2345678" - } - ] - } - ] - } - ] } - ] } - eos + security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new + security_groups = security_groups.group_name(0, "my_group_name").group_id(0, "sg-C2345678") + instances = ZAWS::External::AWSCLI::Generators::Result::EC2::Instances.new + net_interfaces= ZAWS::External::AWSCLI::Generators::Result::EC2::NetworkInterfaces.new + net_interfaces=net_interfaces.network_interface_id(0,"eni-1234568").groups(0,security_groups) + instances = instances.instance_id(0,"i-12345678") + instances = instances.security_groups(0,security_groups) + instances = instances.network_interfaces(0,net_interfaces) + instances_raw=instances.get_json - security_groups_filtered = '{"SecurityGroups":[{"GroupName":"default","VpcId":"vpc-1f6bb57a","OwnerId":"123456789012","GroupId":"sg-B2345678"},{"GroupName":"my_unused_group","VpcId":"vpc-12345678","OwnerId":"123456789012","GroupId":"sg-A2345678"}]}' + security_groups = ZAWS::External::AWSCLI::Generators::Result::EC2::SecurityGroups.new + security_groups = security_groups.group_name(0, "default").vpc_id(0, "vpc-1f6bb57a").owner_id(0, "123456789012").group_id(0, "sg-B2345678") + security_groups = security_groups.group_name(1, "my_unused_group").vpc_id(1, "vpc-12345678").owner_id(1, "123456789012").group_id(1, "sg-A2345678") + security_groups_filtered =security_groups.get_json.gsub(/\s+/,'') - expect(@aws.ec2.security_group.filter_groups_by_instances(security_groups_raw,instances_raw)).to eq(security_groups_filtered) + expect(@aws.ec2.security_group.filter_groups_by_instances(security_groups_raw, instances_raw)).to eq(security_groups_filtered) - end + end end end diff --git a/spec/zaws/ec2/subnet_spec.rb b/spec/zaws/ec2/subnet_spec.rb index a28c08e..8774f84 100755 --- a/spec/zaws/ec2/subnet_spec.rb +++ b/spec/zaws/ec2/subnet_spec.rb @@ -14,7 +14,7 @@ let(:vap_az) { "us-west-1b" } - let(:vac_describe_subnets) { "aws --output json --region #{vap_region} ec2 describe-subnets --filter 'Name=vpc-id,Values=#{vap_vpcid}' 'Name=cidr,Values=#{vap_cidr}'" } + let(:vac_describe_subnets) { "aws --output json --region #{vap_region} ec2 describe-subnets --filter \"Name=vpc-id,Values=#{vap_vpcid}\" \"Name=cidr,Values=#{vap_cidr}\"" } let(:var_subnets_exist) { <<-eos { "Subnets": [ @@ -57,8 +57,8 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @command_subnet = ZAWS::Command::Subnet.new([], options, {}); - @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout)) + @command_subnet = ZAWS::Command::Subnet.new([], options, {}) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,true)) @command_subnet.aws=@aws @command_subnet.out=@textout @command_subnet.print_exit_code = true @@ -168,8 +168,8 @@ } eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.0.0/24'", nil).and_return(subnets_10_0_0_0_24) - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.1.0/24'", nil).and_return(subnets_10_0_1_0_24) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter \"Name=vpc-id,Values=vpc-XXXXXX\" \"Name=cidr,Values=10.0.0.0/24\"", nil).and_return(subnets_10_0_0_0_24) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter \"Name=vpc-id,Values=vpc-XXXXXX\" \"Name=cidr,Values=10.0.1.0/24\"", nil).and_return(subnets_10_0_1_0_24) expect(@aws.ec2.subnet.id_array_by_cidrblock_array('us-west-1', nil, nil, 'vpc-XXXXXX', ["10.0.0.0/24", "10.0.1.0/24"])).to eql(["subnet-YYYYYYYY", "subnet-ZZZZZZZZ"]) end @@ -205,7 +205,7 @@ } eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX'", nil).and_return(subnets) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter \"Name=vpc-id,Values=vpc-XXXXXX\"", nil).and_return(subnets) expect(@textout).to receive(:puts).with('subnet-YYYYYY') @aws.ec2.subnet.id_by_ip('us-west-1', @textout, nil, 'vpc-XXXXXX', '10.0.0.24') end @@ -233,7 +233,7 @@ } eos - expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter 'Name=vpc-id,Values=vpc-XXXXXX' 'Name=cidr,Values=10.0.0.0/24'", nil).and_return(subnets) + expect(@shellout).to receive(:cli).with("aws --output json --region us-west-1 ec2 describe-subnets --filter \"Name=vpc-id,Values=vpc-XXXXXX\" \"Name=cidr,Values=10.0.0.0/24\"", nil).and_return(subnets) expect(@textout).to receive(:puts).with('subnet-YYYYYY') @aws.ec2.subnet.id_by_cidrblock('us-west-1', @textout, nil, 'vpc-XXXXXX', '10.0.0.0/24') diff --git a/spec/zaws/ec2/vpc_spec.rb b/spec/zaws/ec2/vpc_spec.rb index 02e25ea..c0041ef 100755 --- a/spec/zaws/ec2/vpc_spec.rb +++ b/spec/zaws/ec2/vpc_spec.rb @@ -106,7 +106,7 @@ @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') @command_vpc = ZAWS::Command::VPC.new([], options, {}); - @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,true)) @command_vpc.aws=@aws @command_vpc.out=@textout @command_vpc.print_exit_code = true diff --git a/spec/zaws/elb/load_balancer_spec.rb b/spec/zaws/elb/load_balancer_spec.rb index eb8638c..6fbeee5 100755 --- a/spec/zaws/elb/load_balancer_spec.rb +++ b/spec/zaws/elb/load_balancer_spec.rb @@ -5,7 +5,7 @@ before(:each) { @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') - @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout, ZAWS::AWSCLI.new(@shellout,false)) } describe "#calculated_listener" do diff --git a/spec/zaws/helper/option/absent_spec.rb b/spec/zaws/helper/option/absent_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/option/exclusive_spec.rb b/spec/zaws/helper/option/exclusive_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/option/exists_spec.rb b/spec/zaws/helper/option/exists_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/option/minimum_spec.rb b/spec/zaws/helper/option/minimum_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/binary_nagios_check_spec.rb b/spec/zaws/helper/output/binary_nagios_check_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/colorize_spec.rb b/spec/zaws/helper/output/colorize_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/opt_exclusive_spec.rb b/spec/zaws/helper/output/opt_exclusive_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/opt_minimum_spec.rb b/spec/zaws/helper/output/opt_minimum_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/opt_required_spec.rb b/spec/zaws/helper/output/opt_required_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/output/transform_cloudtrail_spec.rb b/spec/zaws/helper/output/transform_cloudtrail_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/helper/shell/if_then_spec.rb b/spec/zaws/helper/shell/if_then_spec.rb old mode 100644 new mode 100755 diff --git a/spec/zaws/iam/policy_spec.rb b/spec/zaws/iam/policy_spec.rb index a4698d1..3c37ae4 100755 --- a/spec/zaws/iam/policy_spec.rb +++ b/spec/zaws/iam/policy_spec.rb @@ -79,7 +79,7 @@ @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') @command_iam = ZAWS::Command::IAM.new([],options,{}); - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout,true)) @command_iam.aws=@aws @command_iam.out=@textout @command_iam.print_exit_code = true diff --git a/spec/zaws/iam/role_policy_spec.rb b/spec/zaws/iam/role_policy_spec.rb index e321dc3..5357747 100755 --- a/spec/zaws/iam/role_policy_spec.rb +++ b/spec/zaws/iam/role_policy_spec.rb @@ -16,7 +16,7 @@ @textout=double('outout') @shellout=double('ZAWS::Helper::Shell') @command_iam = ZAWS::Command::IAM.new([],options,{}); - @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout)) + @aws=ZAWS::AWS.new(@shellout,ZAWS::AWSCLI.new(@shellout,true)) @command_iam.aws=@aws @command_iam.out=@textout @command_iam.print_exit_code = true diff --git a/spec/zaws/nessus/scanners.json b/spec/zaws/nessus/scanners.json new file mode 100755 index 0000000..e69de29