ey-core 3.4.5 → 3.6.0.autoscaling1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +23 -26
 - data/.ruby-gemset +1 -1
 - data/.ruby-version +1 -1
 - data/.travis.yml +23 -23
 - data/CHANGELOG.md +174 -166
 - data/Dockerfile +3 -0
 - data/Gemfile +21 -21
 - data/Guardfile +15 -15
 - data/LICENSE.txt +19 -19
 - data/README.md +78 -78
 - data/Rakefile +18 -18
 - data/bin/ey-core +4 -4
 - data/examples/add_instance.rb +74 -74
 - data/examples/boot_env.rb +60 -60
 - data/examples/console/README.md +14 -14
 - data/examples/console/address.md +51 -51
 - data/examples/stop_env.rb +51 -51
 - data/examples/terminate_instance.rb +62 -62
 - data/ey-core.gemspec +51 -51
 - data/features/accounts.feature +13 -13
 - data/features/applications.feature +29 -29
 - data/features/current_user.feature +14 -14
 - data/features/environment_variables.feature +54 -0
 - data/features/environments.feature +30 -30
 - data/features/init.feature +6 -6
 - data/features/login.feature +6 -6
 - data/features/scp.feature +6 -6
 - data/features/step_definitions/accounts_steps.rb +37 -23
 - data/features/step_definitions/applications_steps.rb +39 -46
 - data/features/step_definitions/current_user_steps.rb +11 -11
 - data/features/step_definitions/deprecated_command_steps.rb +3 -3
 - data/features/step_definitions/environment_variables_steps.rb +51 -0
 - data/features/step_definitions/environments_steps.rb +52 -37
 - data/features/step_definitions/version_steps.rb +3 -3
 - data/features/support/account_helpers.rb +89 -89
 - data/features/support/app_helpers.rb +19 -19
 - data/features/support/aruba.rb +1 -1
 - data/features/support/boilerplate.rb +1 -1
 - data/features/support/client_helpers.rb +36 -36
 - data/features/support/config_file_helpers.rb +42 -42
 - data/features/support/core.rb +19 -19
 - data/features/support/deployment_helpers.rb +19 -19
 - data/features/support/env.rb +40 -40
 - data/features/support/environment_helpers.rb +23 -23
 - data/features/support/environment_variable_helpers.rb +20 -0
 - data/features/support/fake_kernel.rb +23 -23
 - data/features/support/io.rb +5 -5
 - data/features/support/mock_api.rb +21 -21
 - data/features/support/output_helpers.rb +7 -7
 - data/features/support/resource_helpers.rb +201 -189
 - data/features/support/server_helpers.rb +27 -27
 - data/features/version.feature +8 -8
 - data/features/whoami.feature +14 -14
 - data/lib/ey-core/associations.rb +155 -155
 - data/lib/ey-core/cli/accounts.rb +17 -17
 - data/lib/ey-core/cli/applications.rb +36 -36
 - data/lib/ey-core/cli/console.rb +28 -28
 - data/lib/ey-core/cli/current_user.rb +16 -16
 - data/lib/ey-core/cli/deploy.rb +123 -123
 - data/lib/ey-core/cli/environment_variables.rb +71 -0
 - data/lib/ey-core/cli/environments.rb +39 -39
 - data/lib/ey-core/cli/errors.rb +11 -11
 - data/lib/ey-core/cli/help.rb +30 -30
 - data/lib/ey-core/cli/helpers/archive.rb +70 -70
 - data/lib/ey-core/cli/helpers/chef.rb +51 -51
 - data/lib/ey-core/cli/helpers/core.rb +225 -196
 - data/lib/ey-core/cli/helpers/deprecated.rb +39 -39
 - data/lib/ey-core/cli/helpers/log_streaming.rb +41 -41
 - data/lib/ey-core/cli/helpers/server_sieve.rb +76 -76
 - data/lib/ey-core/cli/helpers/stream_printer.rb +42 -42
 - data/lib/ey-core/cli/init.rb +14 -14
 - data/lib/ey-core/cli/login.rb +38 -38
 - data/lib/ey-core/cli/logout.rb +22 -22
 - data/lib/ey-core/cli/logs.rb +70 -70
 - data/lib/ey-core/cli/main.rb +67 -65
 - data/lib/ey-core/cli/recipes/apply.rb +65 -65
 - data/lib/ey-core/cli/recipes/download.rb +52 -52
 - data/lib/ey-core/cli/recipes/main.rb +21 -21
 - data/lib/ey-core/cli/recipes/upload.rb +78 -78
 - data/lib/ey-core/cli/recipes.rb +10 -10
 - data/lib/ey-core/cli/scp.rb +14 -14
 - data/lib/ey-core/cli/servers.rb +58 -41
 - data/lib/ey-core/cli/ssh.rb +150 -150
 - data/lib/ey-core/cli/status.rb +60 -60
 - data/lib/ey-core/cli/subcommand.rb +53 -53
 - data/lib/ey-core/cli/timeout_deploy.rb +58 -58
 - data/lib/ey-core/cli/version.rb +16 -16
 - data/lib/ey-core/cli/web/disable.rb +49 -49
 - data/lib/ey-core/cli/web/enable.rb +46 -46
 - data/lib/ey-core/cli/web/main.rb +21 -21
 - data/lib/ey-core/cli/web/restart.rb +42 -42
 - data/lib/ey-core/cli/web.rb +10 -10
 - data/lib/ey-core/cli/whoami.rb +12 -12
 - data/lib/ey-core/cli.rb +8 -8
 - data/lib/ey-core/client/mock.rb +306 -302
 - data/lib/ey-core/client/real.rb +93 -93
 - data/lib/ey-core/client.rb +468 -442
 - data/lib/ey-core/collection.rb +131 -131
 - data/lib/ey-core/collections/account_cancellations.rb +6 -6
 - data/lib/ey-core/collections/account_referrals.rb +10 -10
 - data/lib/ey-core/collections/accounts.rb +8 -8
 - data/lib/ey-core/collections/addons.rb +16 -16
 - data/lib/ey-core/collections/addresses.rb +9 -9
 - data/lib/ey-core/collections/alerts.rb +9 -9
 - data/lib/ey-core/collections/application_archives.rb +9 -9
 - data/lib/ey-core/collections/application_deployments.rb +9 -9
 - data/lib/ey-core/collections/applications.rb +9 -9
 - data/lib/ey-core/collections/auto_scaling_alarms.rb +8 -0
 - data/lib/ey-core/collections/auto_scaling_groups.rb +8 -8
 - data/lib/ey-core/collections/auto_scaling_policies.rb +33 -0
 - data/lib/ey-core/collections/backup_files.rb +9 -9
 - data/lib/ey-core/collections/blueprints.rb +9 -9
 - data/lib/ey-core/collections/components.rb +9 -9
 - data/lib/ey-core/collections/contacts.rb +9 -9
 - data/lib/ey-core/collections/container_clusters.rb +9 -0
 - data/lib/ey-core/collections/container_service_deployments.rb +17 -0
 - data/lib/ey-core/collections/costs.rb +8 -8
 - data/lib/ey-core/collections/database_plan_usages.rb +7 -7
 - data/lib/ey-core/collections/database_server_revisions.rb +7 -7
 - data/lib/ey-core/collections/database_server_snapshots.rb +17 -17
 - data/lib/ey-core/collections/database_server_usages.rb +7 -7
 - data/lib/ey-core/collections/database_servers.rb +9 -9
 - data/lib/ey-core/collections/database_services.rb +9 -9
 - data/lib/ey-core/collections/deployments.rb +8 -8
 - data/lib/ey-core/collections/environment_plan_usages.rb +7 -7
 - data/lib/ey-core/collections/environment_variables.rb +8 -0
 - data/lib/ey-core/collections/environments.rb +15 -15
 - data/lib/ey-core/collections/features.rb +9 -9
 - data/lib/ey-core/collections/firewall_rules.rb +9 -9
 - data/lib/ey-core/collections/firewalls.rb +9 -9
 - data/lib/ey-core/collections/gems.rb +6 -6
 - data/lib/ey-core/collections/keypair_deployments.rb +9 -9
 - data/lib/ey-core/collections/keypairs.rb +9 -9
 - data/lib/ey-core/collections/legacy_alerts.rb +9 -9
 - data/lib/ey-core/collections/load_balancer_nodes.rb +9 -9
 - data/lib/ey-core/collections/load_balancer_services.rb +9 -9
 - data/lib/ey-core/collections/load_balancers.rb +16 -16
 - data/lib/ey-core/collections/logical_databases.rb +16 -16
 - data/lib/ey-core/collections/logs.rb +9 -9
 - data/lib/ey-core/collections/memberships.rb +9 -9
 - data/lib/ey-core/collections/messages.rb +9 -9
 - data/lib/ey-core/collections/plan_usages.rb +7 -7
 - data/lib/ey-core/collections/provider_locations.rb +13 -13
 - data/lib/ey-core/collections/providers.rb +15 -15
 - data/lib/ey-core/collections/requests.rb +10 -10
 - data/lib/ey-core/collections/server_events.rb +9 -9
 - data/lib/ey-core/collections/server_usages.rb +7 -7
 - data/lib/ey-core/collections/servers.rb +13 -13
 - data/lib/ey-core/collections/services.rb +14 -14
 - data/lib/ey-core/collections/ssl_certificates.rb +9 -9
 - data/lib/ey-core/collections/storage_users.rb +10 -10
 - data/lib/ey-core/collections/storages.rb +9 -9
 - data/lib/ey-core/collections/tasks.rb +9 -9
 - data/lib/ey-core/collections/tokens.rb +9 -9
 - data/lib/ey-core/collections/untracked_addresses.rb +4 -4
 - data/lib/ey-core/collections/untracked_servers.rb +9 -9
 - data/lib/ey-core/collections/users.rb +12 -12
 - data/lib/ey-core/collections/volumes.rb +9 -9
 - data/lib/ey-core/logger.rb +31 -31
 - data/lib/ey-core/memory_cache.rb +17 -17
 - data/lib/ey-core/mock/helper.rb +104 -104
 - data/lib/ey-core/mock/params.rb +31 -31
 - data/lib/ey-core/mock/resources.rb +92 -92
 - data/lib/ey-core/mock/searching.rb +115 -115
 - data/lib/ey-core/mock/util.rb +23 -23
 - data/lib/ey-core/model.rb +44 -44
 - data/lib/ey-core/models/account.rb +70 -70
 - data/lib/ey-core/models/account_cancellation.rb +6 -6
 - data/lib/ey-core/models/account_referral.rb +8 -8
 - data/lib/ey-core/models/account_trial.rb +15 -15
 - data/lib/ey-core/models/addon.rb +37 -37
 - data/lib/ey-core/models/address.rb +59 -57
 - data/lib/ey-core/models/alert.rb +99 -100
 - data/lib/ey-core/models/application.rb +33 -32
 - data/lib/ey-core/models/application_archive.rb +67 -67
 - data/lib/ey-core/models/application_deployment.rb +18 -18
 - data/lib/ey-core/models/auto_scaling_alarm.rb +54 -0
 - data/lib/ey-core/models/auto_scaling_group.rb +75 -49
 - data/lib/ey-core/models/backup_file.rb +52 -52
 - data/lib/ey-core/models/base_auto_scaling_policy.rb +61 -0
 - data/lib/ey-core/models/billing.rb +27 -27
 - data/lib/ey-core/models/blueprint.rb +30 -30
 - data/lib/ey-core/models/component.rb +11 -11
 - data/lib/ey-core/models/contact.rb +14 -14
 - data/lib/ey-core/models/container_service_deployment.rb +17 -0
 - data/lib/ey-core/models/cost.rb +16 -16
 - data/lib/ey-core/models/database_plan_usage.rb +10 -10
 - data/lib/ey-core/models/database_server.rb +56 -56
 - data/lib/ey-core/models/database_server_revision.rb +10 -10
 - data/lib/ey-core/models/database_server_snapshot.rb +43 -43
 - data/lib/ey-core/models/database_server_usage.rb +15 -15
 - data/lib/ey-core/models/database_service.rb +52 -52
 - data/lib/ey-core/models/deployment.rb +30 -30
 - data/lib/ey-core/models/environment.rb +248 -242
 - data/lib/ey-core/models/environment_plan_usage.rb +10 -10
 - data/lib/ey-core/models/environment_variable.rb +29 -0
 - data/lib/ey-core/models/feature.rb +33 -33
 - data/lib/ey-core/models/firewall.rb +46 -46
 - data/lib/ey-core/models/firewall_rule.rb +41 -41
 - data/lib/ey-core/models/gem.rb +5 -5
 - data/lib/ey-core/models/keypair.rb +38 -38
 - data/lib/ey-core/models/keypair_deployment.rb +26 -26
 - data/lib/ey-core/models/legacy_alert.rb +12 -12
 - data/lib/ey-core/models/load_balancer.rb +43 -43
 - data/lib/ey-core/models/load_balancer_node.rb +17 -17
 - data/lib/ey-core/models/load_balancer_service.rb +22 -22
 - data/lib/ey-core/models/log.rb +44 -44
 - data/lib/ey-core/models/logical_database.rb +40 -40
 - data/lib/ey-core/models/membership.rb +49 -49
 - data/lib/ey-core/models/message.rb +27 -27
 - data/lib/ey-core/models/plan_usage.rb +14 -14
 - data/lib/ey-core/models/provider.rb +59 -59
 - data/lib/ey-core/models/provider_location.rb +24 -24
 - data/lib/ey-core/models/request.rb +109 -105
 - data/lib/ey-core/models/server.rb +151 -151
 - data/lib/ey-core/models/server_event.rb +11 -11
 - data/lib/ey-core/models/server_usage.rb +15 -15
 - data/lib/ey-core/models/service.rb +10 -10
 - data/lib/ey-core/models/simple_auto_scaling_policy.rb +24 -0
 - data/lib/ey-core/models/ssl_certificate.rb +44 -44
 - data/lib/ey-core/models/step_auto_scaling_policy.rb +24 -0
 - data/lib/ey-core/models/storage.rb +38 -38
 - data/lib/ey-core/models/storage_user.rb +44 -44
 - data/lib/ey-core/models/support_trial.rb +10 -10
 - data/lib/ey-core/models/target_auto_scaling_policy.rb +24 -0
 - data/lib/ey-core/models/task.rb +35 -35
 - data/lib/ey-core/models/token.rb +24 -24
 - data/lib/ey-core/models/untracked_address.rb +24 -24
 - data/lib/ey-core/models/untracked_server.rb +45 -45
 - data/lib/ey-core/models/user.rb +39 -39
 - data/lib/ey-core/models/volume.rb +20 -20
 - data/lib/ey-core/request.rb +21 -21
 - data/lib/ey-core/request_failure.rb +11 -11
 - data/lib/ey-core/requests/acknowledge_alert.rb +29 -29
 - data/lib/ey-core/requests/apply_environment_updates.rb +54 -54
 - data/lib/ey-core/requests/apply_server_updates.rb +52 -52
 - data/lib/ey-core/requests/attach_address.rb +53 -53
 - data/lib/ey-core/requests/authorized_channel.rb +22 -22
 - data/lib/ey-core/requests/blueprint_environment.rb +72 -72
 - data/lib/ey-core/requests/boot_environment.rb +187 -187
 - data/lib/ey-core/requests/bootstrap_logical_database.rb +80 -80
 - data/lib/ey-core/requests/cancel_account.rb +33 -33
 - data/lib/ey-core/requests/change_environment_maintenance.rb +38 -38
 - data/lib/ey-core/requests/create_account.rb +38 -33
 - data/lib/ey-core/requests/create_addon.rb +35 -35
 - data/lib/ey-core/requests/create_address.rb +54 -53
 - data/lib/ey-core/requests/create_alert.rb +63 -63
 - data/lib/ey-core/requests/create_application.rb +73 -72
 - data/lib/ey-core/requests/create_application_archive.rb +44 -44
 - data/lib/ey-core/requests/create_auto_scaling_alarm.rb +69 -0
 - data/lib/ey-core/requests/create_auto_scaling_group.rb +62 -62
 - data/lib/ey-core/requests/create_auto_scaling_policy.rb +68 -0
 - data/lib/ey-core/requests/create_backup_file.rb +52 -52
 - data/lib/ey-core/requests/create_database_server.rb +72 -72
 - data/lib/ey-core/requests/create_database_service.rb +57 -57
 - data/lib/ey-core/requests/create_database_service_snapshot.rb +69 -69
 - data/lib/ey-core/requests/create_environment.rb +77 -76
 - data/lib/ey-core/requests/create_environment_variable.rb +39 -0
 - data/lib/ey-core/requests/create_firewall.rb +62 -62
 - data/lib/ey-core/requests/create_firewall_rule.rb +60 -60
 - data/lib/ey-core/requests/create_keypair.rb +42 -42
 - data/lib/ey-core/requests/create_keypair_deployment.rb +36 -36
 - data/lib/ey-core/requests/create_load_balancer.rb +62 -62
 - data/lib/ey-core/requests/create_log.rb +53 -53
 - data/lib/ey-core/requests/create_logical_database.rb +56 -56
 - data/lib/ey-core/requests/create_membership.rb +47 -47
 - data/lib/ey-core/requests/create_message.rb +35 -35
 - data/lib/ey-core/requests/create_password_reset.rb +38 -38
 - data/lib/ey-core/requests/create_provider.rb +90 -90
 - data/lib/ey-core/requests/create_server.rb +121 -121
 - data/lib/ey-core/requests/create_ssl_certificate.rb +83 -83
 - data/lib/ey-core/requests/create_storage.rb +64 -64
 - data/lib/ey-core/requests/create_storage_user.rb +64 -64
 - data/lib/ey-core/requests/create_task.rb +55 -55
 - data/lib/ey-core/requests/create_token.rb +24 -24
 - data/lib/ey-core/requests/create_untracked_address.rb +50 -50
 - data/lib/ey-core/requests/create_untracked_server.rb +39 -39
 - data/lib/ey-core/requests/create_user.rb +54 -52
 - data/lib/ey-core/requests/deploy_environment_application.rb +60 -60
 - data/lib/ey-core/requests/deprovision_environment.rb +17 -17
 - data/lib/ey-core/requests/destroy_addon.rb +24 -24
 - data/lib/ey-core/requests/destroy_auto_scaling_alarm.rb +49 -0
 - data/lib/ey-core/requests/destroy_auto_scaling_group.rb +44 -44
 - data/lib/ey-core/requests/destroy_auto_scaling_policy.rb +49 -0
 - data/lib/ey-core/requests/destroy_blueprint.rb +22 -22
 - data/lib/ey-core/requests/destroy_database_server.rb +41 -41
 - data/lib/ey-core/requests/destroy_database_server_snapshot.rb +42 -42
 - data/lib/ey-core/requests/destroy_database_service.rb +57 -57
 - data/lib/ey-core/requests/destroy_environment.rb +43 -43
 - data/lib/ey-core/requests/destroy_firewall.rb +41 -41
 - data/lib/ey-core/requests/destroy_firewall_rule.rb +41 -41
 - data/lib/ey-core/requests/destroy_load_balancer.rb +30 -30
 - data/lib/ey-core/requests/destroy_logical_database.rb +41 -41
 - data/lib/ey-core/requests/destroy_provider.rb +34 -34
 - data/lib/ey-core/requests/destroy_server.rb +48 -48
 - data/lib/ey-core/requests/destroy_ssl_certificate.rb +28 -28
 - data/lib/ey-core/requests/destroy_storage.rb +33 -33
 - data/lib/ey-core/requests/destroy_storage_user.rb +38 -38
 - data/lib/ey-core/requests/destroy_user.rb +29 -29
 - data/lib/ey-core/requests/detach_address.rb +48 -48
 - data/lib/ey-core/requests/disable_feature.rb +30 -30
 - data/lib/ey-core/requests/discover_container_service_deployments.rb +71 -0
 - data/lib/ey-core/requests/discover_database_server.rb +66 -66
 - data/lib/ey-core/requests/discover_database_server_snapshots.rb +69 -69
 - data/lib/ey-core/requests/discover_provider_location.rb +57 -57
 - data/lib/ey-core/requests/discover_server.rb +60 -60
 - data/lib/ey-core/requests/download_file.rb +25 -25
 - data/lib/ey-core/requests/enable_feature.rb +35 -35
 - data/lib/ey-core/requests/get_account.rb +29 -29
 - data/lib/ey-core/requests/get_account_cancellation.rb +21 -21
 - data/lib/ey-core/requests/get_account_referrals.rb +28 -28
 - data/lib/ey-core/requests/get_account_trial.rb +32 -32
 - data/lib/ey-core/requests/get_accounts.rb +42 -42
 - data/lib/ey-core/requests/get_addon.rb +25 -25
 - data/lib/ey-core/requests/get_addons.rb +24 -24
 - data/lib/ey-core/requests/get_address.rb +25 -25
 - data/lib/ey-core/requests/get_addresses.rb +27 -27
 - data/lib/ey-core/requests/get_alert.rb +21 -21
 - data/lib/ey-core/requests/get_alerting_environments.rb +41 -41
 - data/lib/ey-core/requests/get_alerts.rb +44 -44
 - data/lib/ey-core/requests/get_api_token.rb +19 -19
 - data/lib/ey-core/requests/get_application.rb +21 -21
 - data/lib/ey-core/requests/get_application_archive.rb +32 -32
 - data/lib/ey-core/requests/get_application_archives.rb +29 -29
 - data/lib/ey-core/requests/get_application_deployment.rb +21 -21
 - data/lib/ey-core/requests/get_application_deployments.rb +28 -28
 - data/lib/ey-core/requests/get_applications.rb +28 -28
 - data/lib/ey-core/requests/get_auto_scaling_alarm.rb +27 -0
 - data/lib/ey-core/requests/get_auto_scaling_alarms.rb +34 -0
 - data/lib/ey-core/requests/get_auto_scaling_group.rb +21 -21
 - data/lib/ey-core/requests/get_auto_scaling_groups.rb +29 -29
 - data/lib/ey-core/requests/get_auto_scaling_policies.rb +46 -0
 - data/lib/ey-core/requests/get_auto_scaling_policy.rb +27 -0
 - data/lib/ey-core/requests/get_backup_file.rb +21 -21
 - data/lib/ey-core/requests/get_backup_files.rb +28 -28
 - data/lib/ey-core/requests/get_billing.rb +24 -24
 - data/lib/ey-core/requests/get_blueprint.rb +21 -21
 - data/lib/ey-core/requests/get_blueprints.rb +29 -29
 - data/lib/ey-core/requests/get_component.rb +21 -21
 - data/lib/ey-core/requests/get_components.rb +29 -29
 - data/lib/ey-core/requests/get_contacts.rb +34 -34
 - data/lib/ey-core/requests/get_costs.rb +25 -25
 - data/lib/ey-core/requests/get_current_user.rb +19 -19
 - data/lib/ey-core/requests/get_database_plan_usages.rb +24 -24
 - data/lib/ey-core/requests/get_database_server.rb +21 -21
 - data/lib/ey-core/requests/get_database_server_revisions.rb +27 -27
 - data/lib/ey-core/requests/get_database_server_snapshot.rb +20 -20
 - data/lib/ey-core/requests/get_database_server_snapshots.rb +39 -39
 - data/lib/ey-core/requests/get_database_server_usages.rb +24 -24
 - data/lib/ey-core/requests/get_database_servers.rb +30 -30
 - data/lib/ey-core/requests/get_database_servers_firewalls.rb +30 -30
 - data/lib/ey-core/requests/get_database_service.rb +20 -20
 - data/lib/ey-core/requests/get_database_services.rb +55 -55
 - data/lib/ey-core/requests/get_deployment.rb +19 -19
 - data/lib/ey-core/requests/get_deployments.rb +29 -29
 - data/lib/ey-core/requests/get_environment.rb +21 -21
 - data/lib/ey-core/requests/get_environment_database_services.rb +21 -21
 - data/lib/ey-core/requests/get_environment_logical_databases.rb +20 -20
 - data/lib/ey-core/requests/get_environment_plan_usages.rb +24 -24
 - data/lib/ey-core/requests/get_environment_variable.rb +19 -0
 - data/lib/ey-core/requests/get_environment_variables.rb +29 -0
 - data/lib/ey-core/requests/get_environments.rb +29 -29
 - data/lib/ey-core/requests/get_feature.rb +21 -21
 - data/lib/ey-core/requests/get_features.rb +28 -28
 - data/lib/ey-core/requests/get_firewall.rb +21 -21
 - data/lib/ey-core/requests/get_firewall_rule.rb +21 -21
 - data/lib/ey-core/requests/get_firewall_rules.rb +29 -29
 - data/lib/ey-core/requests/get_firewalls.rb +45 -45
 - data/lib/ey-core/requests/get_gem.rb +24 -24
 - data/lib/ey-core/requests/get_keypair.rb +21 -21
 - data/lib/ey-core/requests/get_keypair_deployment.rb +21 -21
 - data/lib/ey-core/requests/get_keypair_deployments.rb +29 -29
 - data/lib/ey-core/requests/get_keypairs.rb +34 -34
 - data/lib/ey-core/requests/get_legacy_alert.rb +21 -21
 - data/lib/ey-core/requests/get_legacy_alerts.rb +29 -29
 - data/lib/ey-core/requests/get_load_balancer.rb +21 -21
 - data/lib/ey-core/requests/get_load_balancer_node.rb +21 -21
 - data/lib/ey-core/requests/get_load_balancer_nodes.rb +30 -30
 - data/lib/ey-core/requests/get_load_balancer_service.rb +21 -21
 - data/lib/ey-core/requests/get_load_balancer_services.rb +30 -30
 - data/lib/ey-core/requests/get_load_balancers.rb +29 -29
 - data/lib/ey-core/requests/get_log.rb +21 -21
 - data/lib/ey-core/requests/get_logical_database.rb +23 -23
 - data/lib/ey-core/requests/get_logical_databases.rb +36 -36
 - data/lib/ey-core/requests/get_logs.rb +37 -37
 - data/lib/ey-core/requests/get_membership.rb +21 -21
 - data/lib/ey-core/requests/get_memberships.rb +29 -29
 - data/lib/ey-core/requests/get_message.rb +28 -28
 - data/lib/ey-core/requests/get_messages.rb +27 -27
 - data/lib/ey-core/requests/get_metadata.rb +22 -22
 - data/lib/ey-core/requests/get_operational_contact.rb +21 -21
 - data/lib/ey-core/requests/get_operational_contacts.rb +20 -20
 - data/lib/ey-core/requests/get_plan_usages.rb +24 -24
 - data/lib/ey-core/requests/get_possible_provider_locations.rb +19 -19
 - data/lib/ey-core/requests/get_provider.rb +21 -21
 - data/lib/ey-core/requests/get_provider_location.rb +29 -29
 - data/lib/ey-core/requests/get_provider_locations.rb +28 -28
 - data/lib/ey-core/requests/get_providers.rb +28 -28
 - data/lib/ey-core/requests/get_request.rb +71 -71
 - data/lib/ey-core/requests/get_requests.rb +29 -29
 - data/lib/ey-core/requests/get_server.rb +34 -34
 - data/lib/ey-core/requests/get_server_event.rb +20 -20
 - data/lib/ey-core/requests/get_server_events.rb +28 -28
 - data/lib/ey-core/requests/get_server_usages.rb +24 -24
 - data/lib/ey-core/requests/get_servers.rb +25 -25
 - data/lib/ey-core/requests/get_ssl_certificate.rb +23 -23
 - data/lib/ey-core/requests/get_ssl_certificates.rb +28 -28
 - data/lib/ey-core/requests/get_storage.rb +21 -21
 - data/lib/ey-core/requests/get_storage_user.rb +21 -21
 - data/lib/ey-core/requests/get_storage_users.rb +28 -28
 - data/lib/ey-core/requests/get_storages.rb +28 -28
 - data/lib/ey-core/requests/get_support_trial.rb +51 -51
 - data/lib/ey-core/requests/get_task.rb +21 -21
 - data/lib/ey-core/requests/get_tasks.rb +28 -28
 - data/lib/ey-core/requests/get_token.rb +21 -21
 - data/lib/ey-core/requests/get_token_by_login.rb +30 -30
 - data/lib/ey-core/requests/get_tokens.rb +32 -32
 - data/lib/ey-core/requests/get_untracked_server.rb +18 -18
 - data/lib/ey-core/requests/get_untracked_servers.rb +24 -24
 - data/lib/ey-core/requests/get_user.rb +21 -21
 - data/lib/ey-core/requests/get_users.rb +42 -42
 - data/lib/ey-core/requests/get_volume.rb +21 -21
 - data/lib/ey-core/requests/get_volumes.rb +28 -28
 - data/lib/ey-core/requests/reboot_server.rb +39 -39
 - data/lib/ey-core/requests/reconcile_server.rb +39 -39
 - data/lib/ey-core/requests/request_callback.rb +26 -26
 - data/lib/ey-core/requests/reset_password.rb +31 -31
 - data/lib/ey-core/requests/reset_server_state.rb +32 -32
 - data/lib/ey-core/requests/restart_environment_app_servers.rb +38 -38
 - data/lib/ey-core/requests/run_cluster_application_action.rb +28 -28
 - data/lib/ey-core/requests/run_environment_application_action.rb +29 -29
 - data/lib/ey-core/requests/signup.rb +56 -56
 - data/lib/ey-core/requests/start_server.rb +39 -39
 - data/lib/ey-core/requests/stop_server.rb +39 -39
 - data/lib/ey-core/requests/timeout_deployment.rb +27 -27
 - data/lib/ey-core/requests/unassign_environment.rb +31 -31
 - data/lib/ey-core/requests/update_addon.rb +28 -28
 - data/lib/ey-core/requests/update_address.rb +29 -29
 - data/lib/ey-core/requests/update_alert.rb +32 -32
 - data/lib/ey-core/requests/update_application_archive.rb +23 -23
 - data/lib/ey-core/requests/update_auto_scaling_alarm.rb +45 -0
 - data/lib/ey-core/requests/update_auto_scaling_group.rb +45 -45
 - data/lib/ey-core/requests/update_auto_scaling_policy.rb +46 -0
 - data/lib/ey-core/requests/update_billing.rb +26 -26
 - data/lib/ey-core/requests/update_blueprint.rb +29 -29
 - data/lib/ey-core/requests/update_connector.rb +32 -32
 - data/lib/ey-core/requests/update_environment.rb +17 -17
 - data/lib/ey-core/requests/update_environment_variable.rb +25 -0
 - data/lib/ey-core/requests/update_membership.rb +29 -29
 - data/lib/ey-core/requests/update_provider_location.rb +29 -29
 - data/lib/ey-core/requests/update_server.rb +29 -29
 - data/lib/ey-core/requests/update_ssl_certificate.rb +25 -25
 - data/lib/ey-core/requests/update_untracked_server.rb +24 -24
 - data/lib/ey-core/requests/upload_file.rb +44 -44
 - data/lib/ey-core/requests/upload_recipes_for_environment.rb +28 -28
 - data/lib/ey-core/response.rb +59 -59
 - data/lib/ey-core/response_cache.rb +29 -29
 - data/lib/ey-core/subscribable.rb +60 -60
 - data/lib/ey-core/test_helpers/account_helpers.rb +73 -73
 - data/lib/ey-core/test_helpers/alert_helpers.rb +16 -16
 - data/lib/ey-core/test_helpers/auto_scaling_helpers.rb +35 -0
 - data/lib/ey-core/test_helpers/client_helpers.rb +40 -40
 - data/lib/ey-core/test_helpers/cucumber.rb +3 -3
 - data/lib/ey-core/test_helpers/resource_helpers.rb +196 -196
 - data/lib/ey-core/test_helpers/rspec.rb +5 -5
 - data/lib/ey-core/test_helpers.rb +17 -15
 - data/lib/ey-core/token_authentication.rb +13 -13
 - data/lib/ey-core/version.rb +5 -5
 - data/lib/ey-core.rb +59 -59
 - data/spec/account_spec.rb +65 -65
 - data/spec/account_trial_spec.rb +17 -17
 - data/spec/accounts_referrals_spec.rb +20 -20
 - data/spec/accounts_spec.rb +113 -113
 - data/spec/addons_and_vars_spec.rb +62 -62
 - data/spec/addresses_spec.rb +57 -56
 - data/spec/alerts_spec.rb +155 -155
 - data/spec/application_archives_spec.rb +39 -39
 - data/spec/applications_spec.rb +65 -65
 - data/spec/auto_scaling_alarms_spec.rb +40 -0
 - data/spec/auto_scaling_groups_spec.rb +28 -28
 - data/spec/auto_scaling_policies_spec.rb +94 -0
 - data/spec/billing_spec.rb +31 -31
 - data/spec/blueprints_spec.rb +47 -47
 - data/spec/client_spec.rb +16 -16
 - data/spec/collection_spec.rb +43 -43
 - data/spec/costs_spec.rb +22 -22
 - data/spec/database_plan_usage_spec.rb +39 -39
 - data/spec/database_server_snapshots_spec.rb +41 -41
 - data/spec/database_server_usage_spec.rb +49 -49
 - data/spec/database_servers_spec.rb +61 -61
 - data/spec/database_services_spec.rb +76 -76
 - data/spec/deployments_spec.rb +24 -24
 - data/spec/environment_plan_usage_spec.rb +38 -38
 - data/spec/environments_spec.rb +212 -212
 - data/spec/ey-core/cli/accounts_spec.rb +20 -20
 - data/spec/ey-core/cli/helpers/server_sieve_spec.rb +226 -226
 - data/spec/ey-core/cli/recipes/apply_spec.rb +34 -34
 - data/spec/ey-core/cli/recipes/download_spec.rb +93 -93
 - data/spec/ey-core/cli/recipes/upload_spec.rb +80 -80
 - data/spec/features_spec.rb +79 -79
 - data/spec/firewalls_spec.rb +84 -84
 - data/spec/gems_spec.rb +11 -11
 - data/spec/keypair_deployments_spec.rb +33 -33
 - data/spec/keypairs_spec.rb +51 -51
 - data/spec/legacy_alerts_spec.rb +44 -44
 - data/spec/load_balancers_spec.rb +31 -31
 - data/spec/logical_databases_spec.rb +38 -38
 - data/spec/logs_spec.rb +44 -44
 - data/spec/memberships_spec.rb +73 -73
 - data/spec/messages_spec.rb +27 -27
 - data/spec/metadata_spec.rb +11 -11
 - data/spec/plan_usage_spec.rb +65 -65
 - data/spec/provider_locations_spec.rb +85 -85
 - data/spec/providers_spec.rb +105 -105
 - data/spec/requests/upload_file_spec.rb +25 -25
 - data/spec/requests_spec.rb +23 -23
 - data/spec/reset_password_spec.rb +22 -22
 - data/spec/server_events_spec.rb +31 -31
 - data/spec/server_usage_spec.rb +70 -70
 - data/spec/servers_spec.rb +202 -202
 - data/spec/services_spec.rb +9 -9
 - data/spec/signups_spec.rb +45 -45
 - data/spec/spec_helper.rb +27 -20
 - data/spec/ssl_certificates_spec.rb +94 -94
 - data/spec/storages_spec.rb +57 -57
 - data/spec/support/cli_helpers.rb +47 -47
 - data/spec/support/core.rb +23 -23
 - data/spec/support/coverage.rb +43 -43
 - data/spec/support/fake_kernel.rb +21 -21
 - data/spec/support/helpers.rb +1 -1
 - data/spec/support/timecop.rb +8 -8
 - data/spec/support_trial_spec.rb +33 -33
 - data/spec/tokens_spec.rb +59 -59
 - data/spec/untracked_servers_spec.rb +59 -59
 - data/spec/users_spec.rb +108 -108
 - metadata +46 -8
 - data/bin/console +0 -4
 
| 
         @@ -1,92 +1,92 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ey::Core::Mock
         
     | 
| 
       2 
     | 
    
         
            -
              module Resources
         
     | 
| 
       3 
     | 
    
         
            -
                # Attempt to determine the identity of the resource. Used to make the mock requests DRYer
         
     | 
| 
       4 
     | 
    
         
            -
                #
         
     | 
| 
       5 
     | 
    
         
            -
                # @param params [nil] returns nil
         
     | 
| 
       6 
     | 
    
         
            -
                # @param params [Integer] id of the resource
         
     | 
| 
       7 
     | 
    
         
            -
                # @param params [String] id or url of the resource
         
     | 
| 
       8 
     | 
    
         
            -
                # @param params [Hash] description of resource
         
     | 
| 
       9 
     | 
    
         
            -
                # @option params [String] url url of the resource
         
     | 
| 
       10 
     | 
    
         
            -
                # @option params [String] id id of the resource
         
     | 
| 
       11 
     | 
    
         
            -
                # @return identity of the resource
         
     | 
| 
       12 
     | 
    
         
            -
                def resource_identity(params)
         
     | 
| 
       13 
     | 
    
         
            -
                  id = nil
         
     | 
| 
       14 
     | 
    
         
            -
                  url = nil
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  case params
         
     | 
| 
       17 
     | 
    
         
            -
                  when Hash
         
     | 
| 
       18 
     | 
    
         
            -
                    id  = params["id"]
         
     | 
| 
       19 
     | 
    
         
            -
                    url = params["url"]
         
     | 
| 
       20 
     | 
    
         
            -
                  when String
         
     | 
| 
       21 
     | 
    
         
            -
                    if params.start_with?(@url)
         
     | 
| 
       22 
     | 
    
         
            -
                      url = params
         
     | 
| 
       23 
     | 
    
         
            -
                    else
         
     | 
| 
       24 
     | 
    
         
            -
                      id = params
         
     | 
| 
       25 
     | 
    
         
            -
                    end
         
     | 
| 
       26 
     | 
    
         
            -
                  when Integer
         
     | 
| 
       27 
     | 
    
         
            -
                    id = params
         
     | 
| 
       28 
     | 
    
         
            -
                  when nil
         
     | 
| 
       29 
     | 
    
         
            -
                    return
         
     | 
| 
       30 
     | 
    
         
            -
                  else
         
     | 
| 
       31 
     | 
    
         
            -
                    raise ArgumentError, "Cannot determine resource identity of #{params.inspect}"
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                  id ||= url && URI.parse(url).path.split("/")[2]
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  Integer(id) rescue id
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                def find(collection, id_or_url)
         
     | 
| 
       40 
     | 
    
         
            -
                  id = resource_identity(id_or_url)
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                  # polymorphic associations suck
         
     | 
| 
       43 
     | 
    
         
            -
                  if collection.is_a?(Array)
         
     | 
| 
       44 
     | 
    
         
            -
                    resource = collection.map do |key|
         
     | 
| 
       45 
     | 
    
         
            -
                      data = self.data[key][id] || self.data[key][id.to_i]
         
     | 
| 
       46 
     | 
    
         
            -
                      [key.to_s.tr('_', '-'), data] if data
         
     | 
| 
       47 
     | 
    
         
            -
                    end.compact.first
         
     | 
| 
       48 
     | 
    
         
            -
                    resource || response(status: 404, body: "Couldn't find #{collection.last} with #{id}")
         
     | 
| 
       49 
     | 
    
         
            -
                  else
         
     | 
| 
       50 
     | 
    
         
            -
                    self.data[collection][id] || self.data[collection][id.to_i] || response(status: 404, body: "Couldn't find #{collection} with [#{id}]")
         
     | 
| 
       51 
     | 
    
         
            -
                  end
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                def mock_account_setup(resource_id, resource)
         
     | 
| 
       55 
     | 
    
         
            -
                  resource["support_plan"] ||= "standard"
         
     | 
| 
       56 
     | 
    
         
            -
                  account_url = url_for("/accounts/#{resource_id}")
         
     | 
| 
       57 
     | 
    
         
            -
                  resource.merge!({
         
     | 
| 
       58 
     | 
    
         
            -
                    "id"               => resource_id,
         
     | 
| 
       59 
     | 
    
         
            -
                    "account_trial"    => "#{account_url}/trial",
         
     | 
| 
       60 
     | 
    
         
            -
                    "addons"           => "#{account_url}/addons",
         
     | 
| 
       61 
     | 
    
         
            -
                    "addresses"        => "#{account_url}/addressses",
         
     | 
| 
       62 
     | 
    
         
            -
                    "applications"     => "#{account_url}/applications",
         
     | 
| 
       63 
     | 
    
         
            -
                    "cancelled_at"     => nil,
         
     | 
| 
       64 
     | 
    
         
            -
                    "costs"            => "#{account_url}/costs",
         
     | 
| 
       65 
     | 
    
         
            -
                    "created_at"       => Time.now.to_s,
         
     | 
| 
       66 
     | 
    
         
            -
                    "deis_clusters"    => "#{account_url}/deis-clusters",
         
     | 
| 
       67 
     | 
    
         
            -
                    "environments"     => "#{account_url}/environments",
         
     | 
| 
       68 
     | 
    
         
            -
                    "features"         => "#{account_url}/features",
         
     | 
| 
       69 
     | 
    
         
            -
                    "memberships"      => "#{account_url}/memberships",
         
     | 
| 
       70 
     | 
    
         
            -
                    "notes"            => "#{account_url}/notes",
         
     | 
| 
       71 
     | 
    
         
            -
                    "owners"           => "#{account_url}/owners",
         
     | 
| 
       72 
     | 
    
         
            -
                    "providers"        => "#{account_url}/providers",
         
     | 
| 
       73 
     | 
    
         
            -
                    "referrals"        => "#{account_url}/referrals",
         
     | 
| 
       74 
     | 
    
         
            -
                    "requests"         => "#{account_url}/requests",
         
     | 
| 
       75 
     | 
    
         
            -
                    "resource_url"     => account_url,
         
     | 
| 
       76 
     | 
    
         
            -
                    "ssl_certificates" => "#{account_url}/ssl-certificates",
         
     | 
| 
       77 
     | 
    
         
            -
                    "support_trial"    => nil,
         
     | 
| 
       78 
     | 
    
         
            -
                    "updated_at"       => Time.now.to_s,
         
     | 
| 
       79 
     | 
    
         
            -
                    "users"            => "#{account_url}/users",
         
     | 
| 
       80 
     | 
    
         
            -
                  })
         
     | 
| 
       81 
     | 
    
         
            -
                  resource
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                def mock_ssh_key
         
     | 
| 
       85 
     | 
    
         
            -
                  {
         
     | 
| 
       86 
     | 
    
         
            -
                    public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC05RVR8BF6gm1oevz+y34AY84OJ3JRSK8sGQycW1Ita7PV8H1b/i5zGWUFjhmR4tuQFjtIku9duZzxKES0bHGVng6PbJeUoJVflYf8rXQzcD4gcF+rYHZGv34N59RH2WYcA+4W4JM8m+hmp/dbXvYjqvf5ykOcETkwUcCfCsAD9tk2GqQQpu8z991Lwu36UHN2I8gcuPy+hR1PokbBxSBT+46MbZFomvA7onjqDcvkXIgZ+GyW12yeKMaF8+zvOT1dDxTnzjvWB7zffCDaNfMW7HkdhvlGAKUxk3CdEVO6peQy4a0E5AdElZDEoCvxpKxKZHXfA6penIysk6p/bEBx".freeze,
         
     | 
| 
       87 
     | 
    
         
            -
                    private_key: "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAtOUVUfAReoJtaHr8/st+AGPODidyUUivLBkMnFtSLWuz1fB9\nW/4ucxllBY4ZkeLbkBY7SJLvXbmc8ShEtGxxlZ4Oj2yXlKCVX5WH/K10M3A+IHBf\nq2B2Rr9+DefUR9lmHAPuFuCTPJvoZqf3W172I6r3+cpDnBE5MFHAnwrAA/bZNhqk\nEKbvM/fdS8Lt+lBzdiPIHLj8voUdT6JGwcUgU/uOjG2RaJrwO6J46g3L5FyIGfhs\nltdsnijGhfPs7zk9XQ8U58471ge833wg2jXzFux5HYb5RgClMZNwnRFTuqXkMuGt\nBOQHRJWQxKAr8aSsSmR13wOqXpyMrJOqf2xAcQIDAQABAoIBAACyxbNMRvT/HecC\nWomtRW5A9GGvm0xfCHYWHqtX2uhb+xS/WeyJ/anqFi7ATq72fjx/KXltP8lP1yBD\nNIixxnp6YroBBFDJkeoNjLnX/ZPZQhQj+uqRc8NwJ89r7rDcUP2YskmaUlcwjuQe\nj+Dla/PVTCHFux8WHe9m0WSLyRP61U+aCEMX5mFhaiXCZGZjtN8CpNl/drfbQTyF\nZMGI4AuPiwR4uS0DN1o1VKIYxsDB5ZMvYqwthqF2WZE4H84IJvvfFyhX39hF9VDr\nqiTI2BRQoBs5O5zqCY0C2xxpICJmlqrM9DYd/411GwIGFBHXBgp8qJxF0PIxHjPt\naYHvqrECgYEA5YV7iQdKi07Cip99Y6MeyFjvp7oYHsSlrPko5y7VmDdAZlvZQ6KI\nNlJ7Vbl3GHtRYyPgh6WZMGDH+1EnSON0c/7IJk30BScMl5pAPHSy3cr2QWLlC9tE\ngyTzJC2GwSyN8ObSl9Mv71L1+y1SAS9ZuG984Y8r/EJLaiMwDNv8TVUCgYEAycN/\n4DjBGLvt9WfuXAQdKuUHvxp4LJOz1cAU60hucGYAY9/kmOsdfMUL+kh1diijmT35\nrr5zC665zq2FyVOnbUPkwKDnLW1o13rhxZYX9se1CFMUbskxCbc39CJmmyEX4bOm\n2Wwt2cJpfCnv+D+rMxXldQOFf46XkMiDjhusBq0CgYEAnDpkoRweaH5+ux7embCR\npmurDS8FdgQChZ+/cMUXTJnnMwU3+Oqr7tXr76jjYP2no2TrU0mr4RsvZGiT5fA0\n9zOohzIudEdlMdgj+0Kv8XpSbqVjJNPmaaIAAlMe02SBZUWoeQGeMjf1CTiLBhV1\n662vglUS6o0xihhTf51JulUCgYEAtgxVDH6JFIU0/3Hoa1Q28SY4KCF8/1PCNwKa\nnXT8WSRgA73X6HZ0Y8jztr+8ZIHko3d9G0OyUH82HhsJlQ+LCRbyhzBnhuCqcYrp\nvbthIgUt/jXgQNn+CjMsJHcJt71TbA4KZTGr6Uj2ntbENG1WTsDaCgvEX8TMUxHp\nSccEH/0CgYBULXDEqtCv85sAiJlgQ0uUI/LhAG48B/G8xUgZkSI+hId/dfrZuSqs\nJvms2/3P58fb15rE5fWtn9iPwA6wU2jlJg6KEnCawiEfhTZgy8XRhgQm0XK0HAHz\n4EWoM5VwYbdIs+LyuVQK/yNRJlP3gtODs6ADAZyzVyj8H2VBduzn9w==\n-----END RSA PRIVATE KEY-----\n".freeze,
         
     | 
| 
       88 
     | 
    
         
            -
                    fingerprint: 16.times.map {rand(16**2).to_s(16).rjust(2,'0')}.join(":"), # => "8a:56:9a:b3:90:b1:3e:21:33:8d:a8:ee:61:69:c5:bc"
         
     | 
| 
       89 
     | 
    
         
            -
                  }
         
     | 
| 
       90 
     | 
    
         
            -
                end
         
     | 
| 
       91 
     | 
    
         
            -
              end
         
     | 
| 
       92 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module Ey::Core::Mock
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Resources
         
     | 
| 
      
 3 
     | 
    
         
            +
                # Attempt to determine the identity of the resource. Used to make the mock requests DRYer
         
     | 
| 
      
 4 
     | 
    
         
            +
                #
         
     | 
| 
      
 5 
     | 
    
         
            +
                # @param params [nil] returns nil
         
     | 
| 
      
 6 
     | 
    
         
            +
                # @param params [Integer] id of the resource
         
     | 
| 
      
 7 
     | 
    
         
            +
                # @param params [String] id or url of the resource
         
     | 
| 
      
 8 
     | 
    
         
            +
                # @param params [Hash] description of resource
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @option params [String] url url of the resource
         
     | 
| 
      
 10 
     | 
    
         
            +
                # @option params [String] id id of the resource
         
     | 
| 
      
 11 
     | 
    
         
            +
                # @return identity of the resource
         
     | 
| 
      
 12 
     | 
    
         
            +
                def resource_identity(params)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  id = nil
         
     | 
| 
      
 14 
     | 
    
         
            +
                  url = nil
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  case params
         
     | 
| 
      
 17 
     | 
    
         
            +
                  when Hash
         
     | 
| 
      
 18 
     | 
    
         
            +
                    id  = params["id"]
         
     | 
| 
      
 19 
     | 
    
         
            +
                    url = params["url"]
         
     | 
| 
      
 20 
     | 
    
         
            +
                  when String
         
     | 
| 
      
 21 
     | 
    
         
            +
                    if params.start_with?(@url)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      url = params
         
     | 
| 
      
 23 
     | 
    
         
            +
                    else
         
     | 
| 
      
 24 
     | 
    
         
            +
                      id = params
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  when Integer
         
     | 
| 
      
 27 
     | 
    
         
            +
                    id = params
         
     | 
| 
      
 28 
     | 
    
         
            +
                  when nil
         
     | 
| 
      
 29 
     | 
    
         
            +
                    return
         
     | 
| 
      
 30 
     | 
    
         
            +
                  else
         
     | 
| 
      
 31 
     | 
    
         
            +
                    raise ArgumentError, "Cannot determine resource identity of #{params.inspect}"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  id ||= url && URI.parse(url).path.split("/")[2]
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  Integer(id) rescue id
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def find(collection, id_or_url)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  id = resource_identity(id_or_url)
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  # polymorphic associations suck
         
     | 
| 
      
 43 
     | 
    
         
            +
                  if collection.is_a?(Array)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    resource = collection.map do |key|
         
     | 
| 
      
 45 
     | 
    
         
            +
                      data = self.data[key][id] || self.data[key][id.to_i]
         
     | 
| 
      
 46 
     | 
    
         
            +
                      [key.to_s.tr('_', '-'), data] if data
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end.compact.first
         
     | 
| 
      
 48 
     | 
    
         
            +
                    resource || response(status: 404, body: "Couldn't find #{collection.last} with #{id}")
         
     | 
| 
      
 49 
     | 
    
         
            +
                  else
         
     | 
| 
      
 50 
     | 
    
         
            +
                    self.data[collection][id] || self.data[collection][id.to_i] || response(status: 404, body: "Couldn't find #{collection} with [#{id}]")
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def mock_account_setup(resource_id, resource)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  resource["support_plan"] ||= "standard"
         
     | 
| 
      
 56 
     | 
    
         
            +
                  account_url = url_for("/accounts/#{resource_id}")
         
     | 
| 
      
 57 
     | 
    
         
            +
                  resource.merge!({
         
     | 
| 
      
 58 
     | 
    
         
            +
                    "id"               => resource_id,
         
     | 
| 
      
 59 
     | 
    
         
            +
                    "account_trial"    => "#{account_url}/trial",
         
     | 
| 
      
 60 
     | 
    
         
            +
                    "addons"           => "#{account_url}/addons",
         
     | 
| 
      
 61 
     | 
    
         
            +
                    "addresses"        => "#{account_url}/addressses",
         
     | 
| 
      
 62 
     | 
    
         
            +
                    "applications"     => "#{account_url}/applications",
         
     | 
| 
      
 63 
     | 
    
         
            +
                    "cancelled_at"     => nil,
         
     | 
| 
      
 64 
     | 
    
         
            +
                    "costs"            => "#{account_url}/costs",
         
     | 
| 
      
 65 
     | 
    
         
            +
                    "created_at"       => Time.now.to_s,
         
     | 
| 
      
 66 
     | 
    
         
            +
                    "deis_clusters"    => "#{account_url}/deis-clusters",
         
     | 
| 
      
 67 
     | 
    
         
            +
                    "environments"     => "#{account_url}/environments",
         
     | 
| 
      
 68 
     | 
    
         
            +
                    "features"         => "#{account_url}/features",
         
     | 
| 
      
 69 
     | 
    
         
            +
                    "memberships"      => "#{account_url}/memberships",
         
     | 
| 
      
 70 
     | 
    
         
            +
                    "notes"            => "#{account_url}/notes",
         
     | 
| 
      
 71 
     | 
    
         
            +
                    "owners"           => "#{account_url}/owners",
         
     | 
| 
      
 72 
     | 
    
         
            +
                    "providers"        => "#{account_url}/providers",
         
     | 
| 
      
 73 
     | 
    
         
            +
                    "referrals"        => "#{account_url}/referrals",
         
     | 
| 
      
 74 
     | 
    
         
            +
                    "requests"         => "#{account_url}/requests",
         
     | 
| 
      
 75 
     | 
    
         
            +
                    "resource_url"     => account_url,
         
     | 
| 
      
 76 
     | 
    
         
            +
                    "ssl_certificates" => "#{account_url}/ssl-certificates",
         
     | 
| 
      
 77 
     | 
    
         
            +
                    "support_trial"    => nil,
         
     | 
| 
      
 78 
     | 
    
         
            +
                    "updated_at"       => Time.now.to_s,
         
     | 
| 
      
 79 
     | 
    
         
            +
                    "users"            => "#{account_url}/users",
         
     | 
| 
      
 80 
     | 
    
         
            +
                  })
         
     | 
| 
      
 81 
     | 
    
         
            +
                  resource
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                def mock_ssh_key
         
     | 
| 
      
 85 
     | 
    
         
            +
                  {
         
     | 
| 
      
 86 
     | 
    
         
            +
                    public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC05RVR8BF6gm1oevz+y34AY84OJ3JRSK8sGQycW1Ita7PV8H1b/i5zGWUFjhmR4tuQFjtIku9duZzxKES0bHGVng6PbJeUoJVflYf8rXQzcD4gcF+rYHZGv34N59RH2WYcA+4W4JM8m+hmp/dbXvYjqvf5ykOcETkwUcCfCsAD9tk2GqQQpu8z991Lwu36UHN2I8gcuPy+hR1PokbBxSBT+46MbZFomvA7onjqDcvkXIgZ+GyW12yeKMaF8+zvOT1dDxTnzjvWB7zffCDaNfMW7HkdhvlGAKUxk3CdEVO6peQy4a0E5AdElZDEoCvxpKxKZHXfA6penIysk6p/bEBx".freeze,
         
     | 
| 
      
 87 
     | 
    
         
            +
                    private_key: "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAtOUVUfAReoJtaHr8/st+AGPODidyUUivLBkMnFtSLWuz1fB9\nW/4ucxllBY4ZkeLbkBY7SJLvXbmc8ShEtGxxlZ4Oj2yXlKCVX5WH/K10M3A+IHBf\nq2B2Rr9+DefUR9lmHAPuFuCTPJvoZqf3W172I6r3+cpDnBE5MFHAnwrAA/bZNhqk\nEKbvM/fdS8Lt+lBzdiPIHLj8voUdT6JGwcUgU/uOjG2RaJrwO6J46g3L5FyIGfhs\nltdsnijGhfPs7zk9XQ8U58471ge833wg2jXzFux5HYb5RgClMZNwnRFTuqXkMuGt\nBOQHRJWQxKAr8aSsSmR13wOqXpyMrJOqf2xAcQIDAQABAoIBAACyxbNMRvT/HecC\nWomtRW5A9GGvm0xfCHYWHqtX2uhb+xS/WeyJ/anqFi7ATq72fjx/KXltP8lP1yBD\nNIixxnp6YroBBFDJkeoNjLnX/ZPZQhQj+uqRc8NwJ89r7rDcUP2YskmaUlcwjuQe\nj+Dla/PVTCHFux8WHe9m0WSLyRP61U+aCEMX5mFhaiXCZGZjtN8CpNl/drfbQTyF\nZMGI4AuPiwR4uS0DN1o1VKIYxsDB5ZMvYqwthqF2WZE4H84IJvvfFyhX39hF9VDr\nqiTI2BRQoBs5O5zqCY0C2xxpICJmlqrM9DYd/411GwIGFBHXBgp8qJxF0PIxHjPt\naYHvqrECgYEA5YV7iQdKi07Cip99Y6MeyFjvp7oYHsSlrPko5y7VmDdAZlvZQ6KI\nNlJ7Vbl3GHtRYyPgh6WZMGDH+1EnSON0c/7IJk30BScMl5pAPHSy3cr2QWLlC9tE\ngyTzJC2GwSyN8ObSl9Mv71L1+y1SAS9ZuG984Y8r/EJLaiMwDNv8TVUCgYEAycN/\n4DjBGLvt9WfuXAQdKuUHvxp4LJOz1cAU60hucGYAY9/kmOsdfMUL+kh1diijmT35\nrr5zC665zq2FyVOnbUPkwKDnLW1o13rhxZYX9se1CFMUbskxCbc39CJmmyEX4bOm\n2Wwt2cJpfCnv+D+rMxXldQOFf46XkMiDjhusBq0CgYEAnDpkoRweaH5+ux7embCR\npmurDS8FdgQChZ+/cMUXTJnnMwU3+Oqr7tXr76jjYP2no2TrU0mr4RsvZGiT5fA0\n9zOohzIudEdlMdgj+0Kv8XpSbqVjJNPmaaIAAlMe02SBZUWoeQGeMjf1CTiLBhV1\n662vglUS6o0xihhTf51JulUCgYEAtgxVDH6JFIU0/3Hoa1Q28SY4KCF8/1PCNwKa\nnXT8WSRgA73X6HZ0Y8jztr+8ZIHko3d9G0OyUH82HhsJlQ+LCRbyhzBnhuCqcYrp\nvbthIgUt/jXgQNn+CjMsJHcJt71TbA4KZTGr6Uj2ntbENG1WTsDaCgvEX8TMUxHp\nSccEH/0CgYBULXDEqtCv85sAiJlgQ0uUI/LhAG48B/G8xUgZkSI+hId/dfrZuSqs\nJvms2/3P58fb15rE5fWtn9iPwA6wU2jlJg6KEnCawiEfhTZgy8XRhgQm0XK0HAHz\n4EWoM5VwYbdIs+LyuVQK/yNRJlP3gtODs6ADAZyzVyj8H2VBduzn9w==\n-----END RSA PRIVATE KEY-----\n".freeze,
         
     | 
| 
      
 88 
     | 
    
         
            +
                    fingerprint: 16.times.map {rand(16**2).to_s(16).rjust(2,'0')}.join(":"), # => "8a:56:9a:b3:90:b1:3e:21:33:8d:a8:ee:61:69:c5:bc"
         
     | 
| 
      
 89 
     | 
    
         
            +
                  }
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,115 +1,115 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ey::Core::Mock
         
     | 
| 
       2 
     | 
    
         
            -
              module Searching
         
     | 
| 
       3 
     | 
    
         
            -
                def url_for_page(collection, page_index, page_size, rel)
         
     | 
| 
       4 
     | 
    
         
            -
                  "<#{url_for(collection)}?page=#{page_index}&per_page=#{page_size}>; rel=\"#{rel}\""
         
     | 
| 
       5 
     | 
    
         
            -
                end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                def page(params, collection, options={})
         
     | 
| 
       8 
     | 
    
         
            -
                  if params["url"]
         
     | 
| 
       9 
     | 
    
         
            -
                    raise "url param should be extracted before paging"
         
     | 
| 
       10 
     | 
    
         
            -
                  end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  unless resources = options.delete(:resources)
         
     | 
| 
       13 
     | 
    
         
            -
                    raise "tried to `page` #{collection} without given `resources` option."
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  if options.any?
         
     | 
| 
       17 
     | 
    
         
            -
                    raise ArgumentError, "Unknown options: #{options.keys}"
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  page_size   = (params["per_page"] || 20).to_i
         
     | 
| 
       21 
     | 
    
         
            -
                  page_index  = (params["page"] || 1).to_i
         
     | 
| 
       22 
     | 
    
         
            -
                  total_pages = (resources.size.to_f / page_size.to_f).ceil
         
     | 
| 
       23 
     | 
    
         
            -
                  offset      = (page_index - 1) * page_size
         
     | 
| 
       24 
     | 
    
         
            -
                  links       = []
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                  resource_page = resources.values.reverse.slice(offset, page_size)
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                  if page_index < total_pages
         
     | 
| 
       29 
     | 
    
         
            -
                    links << url_for_page(collection, page_index + 1, page_size, 'next')
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                  if page_index - 1 > 0
         
     | 
| 
       33 
     | 
    
         
            -
                    links << url_for_page(collection, page_index - 1, page_size, 'prev')
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  links << url_for_page(collection, total_pages, page_size, 'last')
         
     | 
| 
       37 
     | 
    
         
            -
                  headers = {
         
     | 
| 
       38 
     | 
    
         
            -
                    "Link" => links.join(", "),
         
     | 
| 
       39 
     | 
    
         
            -
                    "X-Total-Count" => resources.size
         
     | 
| 
       40 
     | 
    
         
            -
                  }
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                  [headers, resource_page]
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                def pluralize(word)
         
     | 
| 
       46 
     | 
    
         
            -
                  # @fixme make it better
         
     | 
| 
       47 
     | 
    
         
            -
                  "#{word}s"
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                # Filter a mocked data collection by given search parameters
         
     | 
| 
       51 
     | 
    
         
            -
                # @param resource [...] mocked data collection to search through
         
     | 
| 
       52 
     | 
    
         
            -
                # @param params [Hash] parameters to AND search by, array value ORs within that key
         
     | 
| 
       53 
     | 
    
         
            -
                def search(resources, params)
         
     | 
| 
       54 
     | 
    
         
            -
                  search_params = Cistern::Hash.stringify_keys(params)
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                  search_params.select { |k,v| v.respond_to?(:id) }.each do |k,v|
         
     | 
| 
       57 
     | 
    
         
            -
                    search_params[k] = v.id
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  resources.select do |id, attrs|
         
     | 
| 
       61 
     | 
    
         
            -
                    search_params.all? do |term, condition|
         
     | 
| 
       62 
     | 
    
         
            -
                      if condition.kind_of? Array
         
     | 
| 
       63 
     | 
    
         
            -
                        condition.include?(attrs[term]) || condition.include?(attrs["_#{term}"])
         
     | 
| 
       64 
     | 
    
         
            -
                      else
         
     | 
| 
       65 
     | 
    
         
            -
                        # @fixme the search functions should define more accurate / explicit definition of search terms
         
     | 
| 
       66 
     | 
    
         
            -
                        # this is a cheap mapping
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                        # [provider, 3] => "http://api-test.engineyard.com/providers/3"
         
     | 
| 
       69 
     | 
    
         
            -
                        resource_url = url_for("/#{pluralize(term.to_s).gsub("_", "-")}/#{condition}")
         
     | 
| 
       70 
     | 
    
         
            -
                        hidden_term = "_#{term}"
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                        (
         
     | 
| 
       73 
     | 
    
         
            -
                          attrs.key?(term) && (
         
     | 
| 
       74 
     | 
    
         
            -
                            attrs[term] == resource_url ||  # find by relation to a specific resource
         
     | 
| 
       75 
     | 
    
         
            -
                            attrs[term] == condition        # find by direct attribute
         
     | 
| 
       76 
     | 
    
         
            -
                          )
         
     | 
| 
       77 
     | 
    
         
            -
                        ) || (
         
     | 
| 
       78 
     | 
    
         
            -
                          attrs.key?(hidden_term) &&
         
     | 
| 
       79 
     | 
    
         
            -
                          (attrs[hidden_term] == condition) # find by a hidden attribute
         
     | 
| 
       80 
     | 
    
         
            -
                        )
         
     | 
| 
       81 
     | 
    
         
            -
                      end
         
     | 
| 
       82 
     | 
    
         
            -
                    end
         
     | 
| 
       83 
     | 
    
         
            -
                  end
         
     | 
| 
       84 
     | 
    
         
            -
                end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                # @param params [Hash] all query params
         
     | 
| 
       87 
     | 
    
         
            -
                # @param collection [Symbol] collection to use, matches self.data[...]
         
     | 
| 
       88 
     | 
    
         
            -
                # @option opts [Array<#to_s>] :search_keys param keys to search by, using ==
         
     | 
| 
       89 
     | 
    
         
            -
                # @option opts [...] :resources (self.data[collection]) to search and page from
         
     | 
| 
       90 
     | 
    
         
            -
                # @see #page for more options
         
     | 
| 
       91 
     | 
    
         
            -
                def search_and_page(params, collection, options={})
         
     | 
| 
       92 
     | 
    
         
            -
                  deleted_key   = options.delete(:deleted_key) || "deleted_at"
         
     | 
| 
       93 
     | 
    
         
            -
                  resources     = (options.delete(:resources) || self.data[collection]) or raise ArgumentError, "Could not find collection: #{collection}"
         
     | 
| 
       94 
     | 
    
         
            -
                  search_keys   = options.delete(:search_keys) or raise ArgumentError, "Missing required option 'search_keys'"
         
     | 
| 
       95 
     | 
    
         
            -
                  search_params = Cistern::Hash.slice(params, *search_keys)
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                  unless (bad_params = params.keys - search_keys - %w[deleted with_deleted page per_page]).empty?
         
     | 
| 
       98 
     | 
    
         
            -
                    raise "Cannot search #{collection} by params: #{bad_params.join(', ')}"
         
     | 
| 
       99 
     | 
    
         
            -
                  end
         
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
                  @logger.debug('request.search') { "Searching #{collection} with: #{params.inspect}" }
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
                  resources = search(resources, search_params)
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                  # filter out deleted resources by default
         
     | 
| 
       106 
     | 
    
         
            -
                  filter = lambda { |_, attrs| attrs[deleted_key] }
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                  unless params["with_deleted"]
         
     | 
| 
       109 
     | 
    
         
            -
                    params["deleted"] ? resources.select!(&filter) : resources.reject!(&filter)
         
     | 
| 
       110 
     | 
    
         
            -
                  end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                  page(params, collection, options.merge(resources: resources))
         
     | 
| 
       113 
     | 
    
         
            -
                end
         
     | 
| 
       114 
     | 
    
         
            -
              end
         
     | 
| 
       115 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module Ey::Core::Mock
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Searching
         
     | 
| 
      
 3 
     | 
    
         
            +
                def url_for_page(collection, page_index, page_size, rel)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  "<#{url_for(collection)}?page=#{page_index}&per_page=#{page_size}>; rel=\"#{rel}\""
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def page(params, collection, options={})
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if params["url"]
         
     | 
| 
      
 9 
     | 
    
         
            +
                    raise "url param should be extracted before paging"
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  unless resources = options.delete(:resources)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    raise "tried to `page` #{collection} without given `resources` option."
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  if options.any?
         
     | 
| 
      
 17 
     | 
    
         
            +
                    raise ArgumentError, "Unknown options: #{options.keys}"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  page_size   = (params["per_page"] || 20).to_i
         
     | 
| 
      
 21 
     | 
    
         
            +
                  page_index  = (params["page"] || 1).to_i
         
     | 
| 
      
 22 
     | 
    
         
            +
                  total_pages = (resources.size.to_f / page_size.to_f).ceil
         
     | 
| 
      
 23 
     | 
    
         
            +
                  offset      = (page_index - 1) * page_size
         
     | 
| 
      
 24 
     | 
    
         
            +
                  links       = []
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  resource_page = resources.values.reverse.slice(offset, page_size)
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  if page_index < total_pages
         
     | 
| 
      
 29 
     | 
    
         
            +
                    links << url_for_page(collection, page_index + 1, page_size, 'next')
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  if page_index - 1 > 0
         
     | 
| 
      
 33 
     | 
    
         
            +
                    links << url_for_page(collection, page_index - 1, page_size, 'prev')
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  links << url_for_page(collection, total_pages, page_size, 'last')
         
     | 
| 
      
 37 
     | 
    
         
            +
                  headers = {
         
     | 
| 
      
 38 
     | 
    
         
            +
                    "Link" => links.join(", "),
         
     | 
| 
      
 39 
     | 
    
         
            +
                    "X-Total-Count" => resources.size
         
     | 
| 
      
 40 
     | 
    
         
            +
                  }
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  [headers, resource_page]
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def pluralize(word)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  # @fixme make it better
         
     | 
| 
      
 47 
     | 
    
         
            +
                  "#{word}s"
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                # Filter a mocked data collection by given search parameters
         
     | 
| 
      
 51 
     | 
    
         
            +
                # @param resource [...] mocked data collection to search through
         
     | 
| 
      
 52 
     | 
    
         
            +
                # @param params [Hash] parameters to AND search by, array value ORs within that key
         
     | 
| 
      
 53 
     | 
    
         
            +
                def search(resources, params)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  search_params = Cistern::Hash.stringify_keys(params)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  search_params.select { |k,v| v.respond_to?(:id) }.each do |k,v|
         
     | 
| 
      
 57 
     | 
    
         
            +
                    search_params[k] = v.id
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  resources.select do |id, attrs|
         
     | 
| 
      
 61 
     | 
    
         
            +
                    search_params.all? do |term, condition|
         
     | 
| 
      
 62 
     | 
    
         
            +
                      if condition.kind_of? Array
         
     | 
| 
      
 63 
     | 
    
         
            +
                        condition.include?(attrs[term]) || condition.include?(attrs["_#{term}"])
         
     | 
| 
      
 64 
     | 
    
         
            +
                      else
         
     | 
| 
      
 65 
     | 
    
         
            +
                        # @fixme the search functions should define more accurate / explicit definition of search terms
         
     | 
| 
      
 66 
     | 
    
         
            +
                        # this is a cheap mapping
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                        # [provider, 3] => "http://api-test.engineyard.com/providers/3"
         
     | 
| 
      
 69 
     | 
    
         
            +
                        resource_url = url_for("/#{pluralize(term.to_s).gsub("_", "-")}/#{condition}")
         
     | 
| 
      
 70 
     | 
    
         
            +
                        hidden_term = "_#{term}"
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                        (
         
     | 
| 
      
 73 
     | 
    
         
            +
                          attrs.key?(term) && (
         
     | 
| 
      
 74 
     | 
    
         
            +
                            attrs[term] == resource_url ||  # find by relation to a specific resource
         
     | 
| 
      
 75 
     | 
    
         
            +
                            attrs[term] == condition        # find by direct attribute
         
     | 
| 
      
 76 
     | 
    
         
            +
                          )
         
     | 
| 
      
 77 
     | 
    
         
            +
                        ) || (
         
     | 
| 
      
 78 
     | 
    
         
            +
                          attrs.key?(hidden_term) &&
         
     | 
| 
      
 79 
     | 
    
         
            +
                          (attrs[hidden_term] == condition) # find by a hidden attribute
         
     | 
| 
      
 80 
     | 
    
         
            +
                        )
         
     | 
| 
      
 81 
     | 
    
         
            +
                      end
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                # @param params [Hash] all query params
         
     | 
| 
      
 87 
     | 
    
         
            +
                # @param collection [Symbol] collection to use, matches self.data[...]
         
     | 
| 
      
 88 
     | 
    
         
            +
                # @option opts [Array<#to_s>] :search_keys param keys to search by, using ==
         
     | 
| 
      
 89 
     | 
    
         
            +
                # @option opts [...] :resources (self.data[collection]) to search and page from
         
     | 
| 
      
 90 
     | 
    
         
            +
                # @see #page for more options
         
     | 
| 
      
 91 
     | 
    
         
            +
                def search_and_page(params, collection, options={})
         
     | 
| 
      
 92 
     | 
    
         
            +
                  deleted_key   = options.delete(:deleted_key) || "deleted_at"
         
     | 
| 
      
 93 
     | 
    
         
            +
                  resources     = (options.delete(:resources) || self.data[collection]) or raise ArgumentError, "Could not find collection: #{collection}"
         
     | 
| 
      
 94 
     | 
    
         
            +
                  search_keys   = options.delete(:search_keys) or raise ArgumentError, "Missing required option 'search_keys'"
         
     | 
| 
      
 95 
     | 
    
         
            +
                  search_params = Cistern::Hash.slice(params, *search_keys)
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                  unless (bad_params = params.keys - search_keys - %w[deleted with_deleted page per_page]).empty?
         
     | 
| 
      
 98 
     | 
    
         
            +
                    raise "Cannot search #{collection} by params: #{bad_params.join(', ')}"
         
     | 
| 
      
 99 
     | 
    
         
            +
                  end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                  @logger.debug('request.search') { "Searching #{collection} with: #{params.inspect}" }
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  resources = search(resources, search_params)
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  # filter out deleted resources by default
         
     | 
| 
      
 106 
     | 
    
         
            +
                  filter = lambda { |_, attrs| attrs[deleted_key] }
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                  unless params["with_deleted"]
         
     | 
| 
      
 109 
     | 
    
         
            +
                    params["deleted"] ? resources.select!(&filter) : resources.reject!(&filter)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  page(params, collection, options.merge(resources: resources))
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
              end
         
     | 
| 
      
 115 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ey-core/mock/util.rb
    CHANGED
    
    | 
         @@ -1,23 +1,23 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Ey::Core::Mock
         
     | 
| 
       2 
     | 
    
         
            -
              module Util
         
     | 
| 
       3 
     | 
    
         
            -
                def normalize_hash(hash)
         
     | 
| 
       4 
     | 
    
         
            -
                  JSON.load(JSON.dump(hash))
         
     | 
| 
       5 
     | 
    
         
            -
                end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                def deep_dup(object)
         
     | 
| 
       8 
     | 
    
         
            -
                  Marshal.load(Marshal.dump(object))
         
     | 
| 
       9 
     | 
    
         
            -
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                def uuid
         
     | 
| 
       12 
     | 
    
         
            -
                  SecureRandom.uuid
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                def ip_address
         
     | 
| 
       16 
     | 
    
         
            -
                  Array.new(4) { rand(256) }.join('.')
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                def api_token
         
     | 
| 
       20 
     | 
    
         
            -
                  SecureRandom.hex(20)
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            module Ey::Core::Mock
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Util
         
     | 
| 
      
 3 
     | 
    
         
            +
                def normalize_hash(hash)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  JSON.load(JSON.dump(hash))
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def deep_dup(object)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Marshal.load(Marshal.dump(object))
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def uuid
         
     | 
| 
      
 12 
     | 
    
         
            +
                  SecureRandom.uuid
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def ip_address
         
     | 
| 
      
 16 
     | 
    
         
            +
                  Array.new(4) { rand(256) }.join('.')
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def api_token
         
     | 
| 
      
 20 
     | 
    
         
            +
                  SecureRandom.hex(20)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/ey-core/model.rb
    CHANGED
    
    | 
         @@ -1,44 +1,44 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Ey::Core::Model < Cistern::Model
         
     | 
| 
       2 
     | 
    
         
            -
              def url
         
     | 
| 
       3 
     | 
    
         
            -
                if self.class.attributes[:url]
         
     | 
| 
       4 
     | 
    
         
            -
                  read_attribute(:url)
         
     | 
| 
       5 
     | 
    
         
            -
                else
         
     | 
| 
       6 
     | 
    
         
            -
                  "#{self.collection.url}/#{self.id}"
         
     | 
| 
       7 
     | 
    
         
            -
                end
         
     | 
| 
       8 
     | 
    
         
            -
              end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              def to_s
         
     | 
| 
       11 
     | 
    
         
            -
                shortname = self.class.name.split("::").last
         
     | 
| 
       12 
     | 
    
         
            -
                "#{shortname}:#{id}"
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def self.range_parser(v)
         
     | 
| 
       16 
     | 
    
         
            -
                case v
         
     | 
| 
       17 
     | 
    
         
            -
                when Range then
         
     | 
| 
       18 
     | 
    
         
            -
                  v
         
     | 
| 
       19 
     | 
    
         
            -
                when String then
         
     | 
| 
       20 
     | 
    
         
            -
                  first, last = v.split("-").map(&:to_i)
         
     | 
| 
       21 
     | 
    
         
            -
                  last ||= first
         
     | 
| 
       22 
     | 
    
         
            -
                  Range.new(first, last)
         
     | 
| 
       23 
     | 
    
         
            -
                else
         
     | 
| 
       24 
     | 
    
         
            -
                  v
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              def update!(attributes)
         
     | 
| 
       29 
     | 
    
         
            -
                merge_attributes(attributes)
         
     | 
| 
       30 
     | 
    
         
            -
                save!
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
              def save
         
     | 
| 
       34 
     | 
    
         
            -
                save!
         
     | 
| 
       35 
     | 
    
         
            -
              rescue Ey::Core::Response::Error
         
     | 
| 
       36 
     | 
    
         
            -
                false
         
     | 
| 
       37 
     | 
    
         
            -
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              def destroy
         
     | 
| 
       40 
     | 
    
         
            -
                destroy!
         
     | 
| 
       41 
     | 
    
         
            -
              rescue Ey::Core::Response::Error
         
     | 
| 
       42 
     | 
    
         
            -
                false
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            class Ey::Core::Model < Cistern::Model
         
     | 
| 
      
 2 
     | 
    
         
            +
              def url
         
     | 
| 
      
 3 
     | 
    
         
            +
                if self.class.attributes[:url]
         
     | 
| 
      
 4 
     | 
    
         
            +
                  read_attribute(:url)
         
     | 
| 
      
 5 
     | 
    
         
            +
                else
         
     | 
| 
      
 6 
     | 
    
         
            +
                  "#{self.collection.url}/#{self.id}"
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def to_s
         
     | 
| 
      
 11 
     | 
    
         
            +
                shortname = self.class.name.split("::").last
         
     | 
| 
      
 12 
     | 
    
         
            +
                "#{shortname}:#{id}"
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def self.range_parser(v)
         
     | 
| 
      
 16 
     | 
    
         
            +
                case v
         
     | 
| 
      
 17 
     | 
    
         
            +
                when Range then
         
     | 
| 
      
 18 
     | 
    
         
            +
                  v
         
     | 
| 
      
 19 
     | 
    
         
            +
                when String then
         
     | 
| 
      
 20 
     | 
    
         
            +
                  first, last = v.split("-").map(&:to_i)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  last ||= first
         
     | 
| 
      
 22 
     | 
    
         
            +
                  Range.new(first, last)
         
     | 
| 
      
 23 
     | 
    
         
            +
                else
         
     | 
| 
      
 24 
     | 
    
         
            +
                  v
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def update!(attributes)
         
     | 
| 
      
 29 
     | 
    
         
            +
                merge_attributes(attributes)
         
     | 
| 
      
 30 
     | 
    
         
            +
                save!
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def save
         
     | 
| 
      
 34 
     | 
    
         
            +
                save!
         
     | 
| 
      
 35 
     | 
    
         
            +
              rescue Ey::Core::Response::Error
         
     | 
| 
      
 36 
     | 
    
         
            +
                false
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def destroy
         
     | 
| 
      
 40 
     | 
    
         
            +
                destroy!
         
     | 
| 
      
 41 
     | 
    
         
            +
              rescue Ey::Core::Response::Error
         
     | 
| 
      
 42 
     | 
    
         
            +
                false
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     |