ey-core 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +167 -0
- data/Gemfile +28 -0
- data/Guardfile +15 -0
- data/LICENSE.txt +19 -0
- data/README.md +82 -0
- data/Rakefile +15 -0
- data/bin/ey-core +4 -0
- data/ey-core.gemspec +28 -0
- data/lib/ey-core.rb +59 -0
- data/lib/ey-core/associations.rb +155 -0
- data/lib/ey-core/cli.rb +118 -0
- data/lib/ey-core/client.rb +402 -0
- data/lib/ey-core/client/mock.rb +288 -0
- data/lib/ey-core/client/real.rb +93 -0
- data/lib/ey-core/collection.rb +131 -0
- data/lib/ey-core/collections/account_cancellations.rb +6 -0
- data/lib/ey-core/collections/account_referrals.rb +10 -0
- data/lib/ey-core/collections/accounts.rb +8 -0
- data/lib/ey-core/collections/addons.rb +16 -0
- data/lib/ey-core/collections/addresses.rb +9 -0
- data/lib/ey-core/collections/alerts.rb +9 -0
- data/lib/ey-core/collections/application_archives.rb +9 -0
- data/lib/ey-core/collections/application_deployments.rb +9 -0
- data/lib/ey-core/collections/applications.rb +9 -0
- data/lib/ey-core/collections/backup_files.rb +9 -0
- data/lib/ey-core/collections/components.rb +9 -0
- data/lib/ey-core/collections/contacts.rb +9 -0
- data/lib/ey-core/collections/costs.rb +8 -0
- data/lib/ey-core/collections/database_plan_usages.rb +7 -0
- data/lib/ey-core/collections/database_server_revisions.rb +7 -0
- data/lib/ey-core/collections/database_server_snapshots.rb +17 -0
- data/lib/ey-core/collections/database_server_usages.rb +7 -0
- data/lib/ey-core/collections/database_servers.rb +9 -0
- data/lib/ey-core/collections/database_services.rb +9 -0
- data/lib/ey-core/collections/environment_plan_usages.rb +7 -0
- data/lib/ey-core/collections/environments.rb +15 -0
- data/lib/ey-core/collections/features.rb +9 -0
- data/lib/ey-core/collections/firewall_rules.rb +9 -0
- data/lib/ey-core/collections/firewalls.rb +9 -0
- data/lib/ey-core/collections/gems.rb +6 -0
- data/lib/ey-core/collections/keypair_deployments.rb +9 -0
- data/lib/ey-core/collections/keypairs.rb +9 -0
- data/lib/ey-core/collections/legacy_alerts.rb +9 -0
- data/lib/ey-core/collections/load_balancer_nodes.rb +9 -0
- data/lib/ey-core/collections/load_balancer_services.rb +9 -0
- data/lib/ey-core/collections/load_balancers.rb +16 -0
- data/lib/ey-core/collections/logical_databases.rb +16 -0
- data/lib/ey-core/collections/logs.rb +9 -0
- data/lib/ey-core/collections/memberships.rb +9 -0
- data/lib/ey-core/collections/messages.rb +9 -0
- data/lib/ey-core/collections/plan_usages.rb +7 -0
- data/lib/ey-core/collections/provider_locations.rb +13 -0
- data/lib/ey-core/collections/providers.rb +15 -0
- data/lib/ey-core/collections/requests.rb +10 -0
- data/lib/ey-core/collections/server_events.rb +9 -0
- data/lib/ey-core/collections/server_usages.rb +7 -0
- data/lib/ey-core/collections/servers.rb +9 -0
- data/lib/ey-core/collections/services.rb +14 -0
- data/lib/ey-core/collections/ssl_certificates.rb +9 -0
- data/lib/ey-core/collections/storage_users.rb +10 -0
- data/lib/ey-core/collections/storages.rb +9 -0
- data/lib/ey-core/collections/tasks.rb +9 -0
- data/lib/ey-core/collections/tokens.rb +8 -0
- data/lib/ey-core/collections/untracked_addresses.rb +4 -0
- data/lib/ey-core/collections/untracked_servers.rb +9 -0
- data/lib/ey-core/collections/users.rb +12 -0
- data/lib/ey-core/collections/volumes.rb +9 -0
- data/lib/ey-core/logger.rb +31 -0
- data/lib/ey-core/memory_cache.rb +17 -0
- data/lib/ey-core/mock/helper.rb +104 -0
- data/lib/ey-core/mock/params.rb +31 -0
- data/lib/ey-core/mock/resources.rb +92 -0
- data/lib/ey-core/mock/searching.rb +111 -0
- data/lib/ey-core/mock/util.rb +23 -0
- data/lib/ey-core/model.rb +39 -0
- data/lib/ey-core/models/account.rb +65 -0
- data/lib/ey-core/models/account_cancellation.rb +6 -0
- data/lib/ey-core/models/account_referral.rb +8 -0
- data/lib/ey-core/models/account_trial.rb +15 -0
- data/lib/ey-core/models/addon.rb +37 -0
- data/lib/ey-core/models/address.rb +57 -0
- data/lib/ey-core/models/alert.rb +94 -0
- data/lib/ey-core/models/application.rb +32 -0
- data/lib/ey-core/models/application_archive.rb +67 -0
- data/lib/ey-core/models/application_deployment.rb +18 -0
- data/lib/ey-core/models/backup_file.rb +52 -0
- data/lib/ey-core/models/billing.rb +27 -0
- data/lib/ey-core/models/component.rb +11 -0
- data/lib/ey-core/models/contact.rb +14 -0
- data/lib/ey-core/models/cost.rb +16 -0
- data/lib/ey-core/models/database_plan_usage.rb +10 -0
- data/lib/ey-core/models/database_server.rb +56 -0
- data/lib/ey-core/models/database_server_revision.rb +10 -0
- data/lib/ey-core/models/database_server_snapshot.rb +43 -0
- data/lib/ey-core/models/database_server_usage.rb +15 -0
- data/lib/ey-core/models/database_service.rb +52 -0
- data/lib/ey-core/models/environment.rb +143 -0
- data/lib/ey-core/models/environment_plan_usage.rb +10 -0
- data/lib/ey-core/models/feature.rb +33 -0
- data/lib/ey-core/models/firewall.rb +46 -0
- data/lib/ey-core/models/firewall_rule.rb +41 -0
- data/lib/ey-core/models/gem.rb +5 -0
- data/lib/ey-core/models/keypair.rb +38 -0
- data/lib/ey-core/models/keypair_deployment.rb +26 -0
- data/lib/ey-core/models/legacy_alert.rb +12 -0
- data/lib/ey-core/models/load_balancer.rb +43 -0
- data/lib/ey-core/models/load_balancer_node.rb +17 -0
- data/lib/ey-core/models/load_balancer_service.rb +22 -0
- data/lib/ey-core/models/log.rb +33 -0
- data/lib/ey-core/models/logical_database.rb +40 -0
- data/lib/ey-core/models/membership.rb +49 -0
- data/lib/ey-core/models/message.rb +27 -0
- data/lib/ey-core/models/plan_usage.rb +14 -0
- data/lib/ey-core/models/provider.rb +59 -0
- data/lib/ey-core/models/provider_location.rb +11 -0
- data/lib/ey-core/models/request.rb +93 -0
- data/lib/ey-core/models/server.rb +76 -0
- data/lib/ey-core/models/server_event.rb +11 -0
- data/lib/ey-core/models/server_usage.rb +15 -0
- data/lib/ey-core/models/service.rb +10 -0
- data/lib/ey-core/models/ssl_certificate.rb +44 -0
- data/lib/ey-core/models/storage.rb +38 -0
- data/lib/ey-core/models/storage_user.rb +44 -0
- data/lib/ey-core/models/support_trial.rb +10 -0
- data/lib/ey-core/models/task.rb +35 -0
- data/lib/ey-core/models/token.rb +20 -0
- data/lib/ey-core/models/untracked_address.rb +24 -0
- data/lib/ey-core/models/untracked_server.rb +45 -0
- data/lib/ey-core/models/user.rb +35 -0
- data/lib/ey-core/models/volume.rb +20 -0
- data/lib/ey-core/request.rb +21 -0
- data/lib/ey-core/request_failure.rb +11 -0
- data/lib/ey-core/requests/attach_address.rb +53 -0
- data/lib/ey-core/requests/authorized_channel.rb +22 -0
- data/lib/ey-core/requests/boot_environment.rb +131 -0
- data/lib/ey-core/requests/bootstrap_logical_database.rb +80 -0
- data/lib/ey-core/requests/cancel_account.rb +33 -0
- data/lib/ey-core/requests/create_account.rb +33 -0
- data/lib/ey-core/requests/create_addon.rb +35 -0
- data/lib/ey-core/requests/create_address.rb +53 -0
- data/lib/ey-core/requests/create_alert.rb +63 -0
- data/lib/ey-core/requests/create_application.rb +72 -0
- data/lib/ey-core/requests/create_application_archive.rb +44 -0
- data/lib/ey-core/requests/create_backup_file.rb +52 -0
- data/lib/ey-core/requests/create_database_server.rb +72 -0
- data/lib/ey-core/requests/create_database_service.rb +57 -0
- data/lib/ey-core/requests/create_database_service_snapshot.rb +69 -0
- data/lib/ey-core/requests/create_environment.rb +69 -0
- data/lib/ey-core/requests/create_firewall.rb +62 -0
- data/lib/ey-core/requests/create_firewall_rule.rb +60 -0
- data/lib/ey-core/requests/create_keypair.rb +42 -0
- data/lib/ey-core/requests/create_keypair_deployment.rb +36 -0
- data/lib/ey-core/requests/create_load_balancer.rb +62 -0
- data/lib/ey-core/requests/create_log.rb +53 -0
- data/lib/ey-core/requests/create_logical_database.rb +56 -0
- data/lib/ey-core/requests/create_membership.rb +47 -0
- data/lib/ey-core/requests/create_message.rb +35 -0
- data/lib/ey-core/requests/create_password_reset.rb +38 -0
- data/lib/ey-core/requests/create_provider.rb +90 -0
- data/lib/ey-core/requests/create_ssl_certificate.rb +83 -0
- data/lib/ey-core/requests/create_storage.rb +64 -0
- data/lib/ey-core/requests/create_storage_user.rb +64 -0
- data/lib/ey-core/requests/create_task.rb +55 -0
- data/lib/ey-core/requests/create_token.rb +24 -0
- data/lib/ey-core/requests/create_untracked_address.rb +48 -0
- data/lib/ey-core/requests/create_untracked_server.rb +39 -0
- data/lib/ey-core/requests/create_user.rb +43 -0
- data/lib/ey-core/requests/deploy_environment_application.rb +43 -0
- data/lib/ey-core/requests/deprovision_environment.rb +17 -0
- data/lib/ey-core/requests/destroy_addon.rb +24 -0
- data/lib/ey-core/requests/destroy_database_server.rb +41 -0
- data/lib/ey-core/requests/destroy_database_server_snapshot.rb +42 -0
- data/lib/ey-core/requests/destroy_database_service.rb +57 -0
- data/lib/ey-core/requests/destroy_environment.rb +43 -0
- data/lib/ey-core/requests/destroy_firewall.rb +41 -0
- data/lib/ey-core/requests/destroy_firewall_rule.rb +41 -0
- data/lib/ey-core/requests/destroy_load_balancer.rb +30 -0
- data/lib/ey-core/requests/destroy_logical_database.rb +41 -0
- data/lib/ey-core/requests/destroy_provider.rb +34 -0
- data/lib/ey-core/requests/destroy_server.rb +46 -0
- data/lib/ey-core/requests/destroy_ssl_certificate.rb +28 -0
- data/lib/ey-core/requests/destroy_storage.rb +33 -0
- data/lib/ey-core/requests/destroy_storage_user.rb +38 -0
- data/lib/ey-core/requests/destroy_user.rb +29 -0
- data/lib/ey-core/requests/detach_address.rb +48 -0
- data/lib/ey-core/requests/disable_feature.rb +30 -0
- data/lib/ey-core/requests/discover_database_server.rb +66 -0
- data/lib/ey-core/requests/discover_database_server_snapshots.rb +69 -0
- data/lib/ey-core/requests/discover_provider_location.rb +57 -0
- data/lib/ey-core/requests/download_file.rb +25 -0
- data/lib/ey-core/requests/enable_feature.rb +35 -0
- data/lib/ey-core/requests/get_account.rb +29 -0
- data/lib/ey-core/requests/get_account_cancellation.rb +21 -0
- data/lib/ey-core/requests/get_account_referrals.rb +28 -0
- data/lib/ey-core/requests/get_account_trial.rb +31 -0
- data/lib/ey-core/requests/get_accounts.rb +42 -0
- data/lib/ey-core/requests/get_addon.rb +25 -0
- data/lib/ey-core/requests/get_addons.rb +24 -0
- data/lib/ey-core/requests/get_address.rb +25 -0
- data/lib/ey-core/requests/get_addresses.rb +27 -0
- data/lib/ey-core/requests/get_alert.rb +21 -0
- data/lib/ey-core/requests/get_alerting_environments.rb +37 -0
- data/lib/ey-core/requests/get_alerts.rb +44 -0
- data/lib/ey-core/requests/get_api_token.rb +19 -0
- data/lib/ey-core/requests/get_application.rb +21 -0
- data/lib/ey-core/requests/get_application_archive.rb +32 -0
- data/lib/ey-core/requests/get_application_archives.rb +29 -0
- data/lib/ey-core/requests/get_application_deployment.rb +21 -0
- data/lib/ey-core/requests/get_application_deployments.rb +28 -0
- data/lib/ey-core/requests/get_applications.rb +28 -0
- data/lib/ey-core/requests/get_backup_file.rb +21 -0
- data/lib/ey-core/requests/get_backup_files.rb +28 -0
- data/lib/ey-core/requests/get_billing.rb +24 -0
- data/lib/ey-core/requests/get_component.rb +21 -0
- data/lib/ey-core/requests/get_components.rb +29 -0
- data/lib/ey-core/requests/get_contacts.rb +34 -0
- data/lib/ey-core/requests/get_costs.rb +25 -0
- data/lib/ey-core/requests/get_current_user.rb +19 -0
- data/lib/ey-core/requests/get_database_plan_usages.rb +24 -0
- data/lib/ey-core/requests/get_database_server.rb +21 -0
- data/lib/ey-core/requests/get_database_server_revisions.rb +27 -0
- data/lib/ey-core/requests/get_database_server_snapshot.rb +20 -0
- data/lib/ey-core/requests/get_database_server_snapshots.rb +39 -0
- data/lib/ey-core/requests/get_database_server_usages.rb +24 -0
- data/lib/ey-core/requests/get_database_servers.rb +30 -0
- data/lib/ey-core/requests/get_database_servers_firewalls.rb +30 -0
- data/lib/ey-core/requests/get_database_service.rb +20 -0
- data/lib/ey-core/requests/get_database_services.rb +55 -0
- data/lib/ey-core/requests/get_environment.rb +21 -0
- data/lib/ey-core/requests/get_environment_database_services.rb +21 -0
- data/lib/ey-core/requests/get_environment_logical_databases.rb +20 -0
- data/lib/ey-core/requests/get_environment_plan_usages.rb +24 -0
- data/lib/ey-core/requests/get_environments.rb +29 -0
- data/lib/ey-core/requests/get_feature.rb +21 -0
- data/lib/ey-core/requests/get_features.rb +28 -0
- data/lib/ey-core/requests/get_firewall.rb +21 -0
- data/lib/ey-core/requests/get_firewall_rule.rb +21 -0
- data/lib/ey-core/requests/get_firewall_rules.rb +29 -0
- data/lib/ey-core/requests/get_firewalls.rb +45 -0
- data/lib/ey-core/requests/get_gem.rb +24 -0
- data/lib/ey-core/requests/get_keypair.rb +21 -0
- data/lib/ey-core/requests/get_keypair_deployment.rb +21 -0
- data/lib/ey-core/requests/get_keypair_deployments.rb +29 -0
- data/lib/ey-core/requests/get_keypairs.rb +34 -0
- data/lib/ey-core/requests/get_legacy_alert.rb +21 -0
- data/lib/ey-core/requests/get_legacy_alerts.rb +29 -0
- data/lib/ey-core/requests/get_load_balancer.rb +21 -0
- data/lib/ey-core/requests/get_load_balancer_node.rb +21 -0
- data/lib/ey-core/requests/get_load_balancer_nodes.rb +30 -0
- data/lib/ey-core/requests/get_load_balancer_service.rb +21 -0
- data/lib/ey-core/requests/get_load_balancer_services.rb +30 -0
- data/lib/ey-core/requests/get_load_balancers.rb +29 -0
- data/lib/ey-core/requests/get_log.rb +21 -0
- data/lib/ey-core/requests/get_logical_database.rb +23 -0
- data/lib/ey-core/requests/get_logical_databases.rb +36 -0
- data/lib/ey-core/requests/get_logs.rb +37 -0
- data/lib/ey-core/requests/get_membership.rb +21 -0
- data/lib/ey-core/requests/get_memberships.rb +29 -0
- data/lib/ey-core/requests/get_message.rb +28 -0
- data/lib/ey-core/requests/get_messages.rb +27 -0
- data/lib/ey-core/requests/get_metadata.rb +22 -0
- data/lib/ey-core/requests/get_operational_contact.rb +21 -0
- data/lib/ey-core/requests/get_operational_contacts.rb +20 -0
- data/lib/ey-core/requests/get_plan_usages.rb +24 -0
- data/lib/ey-core/requests/get_possible_provider_locations.rb +19 -0
- data/lib/ey-core/requests/get_provider.rb +21 -0
- data/lib/ey-core/requests/get_provider_location.rb +29 -0
- data/lib/ey-core/requests/get_provider_locations.rb +28 -0
- data/lib/ey-core/requests/get_providers.rb +28 -0
- data/lib/ey-core/requests/get_request.rb +71 -0
- data/lib/ey-core/requests/get_requests.rb +29 -0
- data/lib/ey-core/requests/get_server.rb +34 -0
- data/lib/ey-core/requests/get_server_event.rb +20 -0
- data/lib/ey-core/requests/get_server_events.rb +28 -0
- data/lib/ey-core/requests/get_server_usages.rb +24 -0
- data/lib/ey-core/requests/get_servers.rb +25 -0
- data/lib/ey-core/requests/get_ssl_certificate.rb +23 -0
- data/lib/ey-core/requests/get_ssl_certificates.rb +28 -0
- data/lib/ey-core/requests/get_storage.rb +21 -0
- data/lib/ey-core/requests/get_storage_user.rb +21 -0
- data/lib/ey-core/requests/get_storage_users.rb +28 -0
- data/lib/ey-core/requests/get_storages.rb +28 -0
- data/lib/ey-core/requests/get_support_trial.rb +51 -0
- data/lib/ey-core/requests/get_task.rb +21 -0
- data/lib/ey-core/requests/get_tasks.rb +28 -0
- data/lib/ey-core/requests/get_untracked_server.rb +18 -0
- data/lib/ey-core/requests/get_untracked_servers.rb +24 -0
- data/lib/ey-core/requests/get_user.rb +21 -0
- data/lib/ey-core/requests/get_users.rb +42 -0
- data/lib/ey-core/requests/get_volume.rb +21 -0
- data/lib/ey-core/requests/get_volumes.rb +28 -0
- data/lib/ey-core/requests/reboot_server.rb +39 -0
- data/lib/ey-core/requests/request_callback.rb +26 -0
- data/lib/ey-core/requests/reset_password.rb +31 -0
- data/lib/ey-core/requests/run_cluster_application_action.rb +28 -0
- data/lib/ey-core/requests/run_environment_application_action.rb +29 -0
- data/lib/ey-core/requests/signup.rb +56 -0
- data/lib/ey-core/requests/update_addon.rb +28 -0
- data/lib/ey-core/requests/update_address.rb +29 -0
- data/lib/ey-core/requests/update_alert.rb +32 -0
- data/lib/ey-core/requests/update_application_archive.rb +23 -0
- data/lib/ey-core/requests/update_billing.rb +26 -0
- data/lib/ey-core/requests/update_connector.rb +32 -0
- data/lib/ey-core/requests/update_membership.rb +29 -0
- data/lib/ey-core/requests/update_server.rb +29 -0
- data/lib/ey-core/requests/update_ssl_certificate.rb +25 -0
- data/lib/ey-core/requests/update_untracked_server.rb +24 -0
- data/lib/ey-core/requests/upload_file.rb +44 -0
- data/lib/ey-core/response.rb +55 -0
- data/lib/ey-core/response_cache.rb +29 -0
- data/lib/ey-core/subscribable.rb +49 -0
- data/lib/ey-core/token_authentication.rb +13 -0
- data/lib/ey-core/version.rb +5 -0
- data/spec/account_trial_spec.rb +17 -0
- data/spec/accounts_referrals_spec.rb +20 -0
- data/spec/accounts_spec.rb +113 -0
- data/spec/addons_and_vars_spec.rb +62 -0
- data/spec/addresses_spec.rb +56 -0
- data/spec/alerts_spec.rb +148 -0
- data/spec/application_archives_spec.rb +39 -0
- data/spec/applications_spec.rb +65 -0
- data/spec/billing_spec.rb +31 -0
- data/spec/client_spec.rb +16 -0
- data/spec/collection_spec.rb +43 -0
- data/spec/costs_spec.rb +22 -0
- data/spec/database_plan_usage_spec.rb +39 -0
- data/spec/database_server_snapshots_spec.rb +41 -0
- data/spec/database_server_usage_spec.rb +49 -0
- data/spec/database_servers_spec.rb +61 -0
- data/spec/database_services_spec.rb +76 -0
- data/spec/environment_plan_usage_spec.rb +38 -0
- data/spec/environments_spec.rb +106 -0
- data/spec/features_spec.rb +79 -0
- data/spec/firewalls_spec.rb +84 -0
- data/spec/gems_spec.rb +11 -0
- data/spec/keypair_deployments_spec.rb +33 -0
- data/spec/keypairs_spec.rb +51 -0
- data/spec/legacy_alerts_spec.rb +44 -0
- data/spec/load_balancers_spec.rb +31 -0
- data/spec/logical_databases_spec.rb +38 -0
- data/spec/logs_spec.rb +44 -0
- data/spec/memberships_spec.rb +70 -0
- data/spec/messages_spec.rb +27 -0
- data/spec/metadata_spec.rb +11 -0
- data/spec/plan_usage_spec.rb +65 -0
- data/spec/provider_locations_spec.rb +64 -0
- data/spec/providers_spec.rb +105 -0
- data/spec/requests/upload_file_spec.rb +25 -0
- data/spec/requests_spec.rb +23 -0
- data/spec/reset_password_spec.rb +22 -0
- data/spec/server_events_spec.rb +31 -0
- data/spec/server_usage_spec.rb +70 -0
- data/spec/servers_spec.rb +55 -0
- data/spec/services_spec.rb +9 -0
- data/spec/signups_spec.rb +45 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/ssl_certificates_spec.rb +94 -0
- data/spec/storages_spec.rb +57 -0
- data/spec/support/account_helper.rb +71 -0
- data/spec/support/alert_helper.rb +14 -0
- data/spec/support/client_helper.rb +38 -0
- data/spec/support/core.rb +23 -0
- data/spec/support/coverage.rb +43 -0
- data/spec/support/resource_helper.rb +190 -0
- data/spec/support/timecop.rb +8 -0
- data/spec/support_trial_spec.rb +33 -0
- data/spec/tokens_spec.rb +19 -0
- data/spec/untracked_servers_spec.rb +59 -0
- data/spec/users_spec.rb +82 -0
- metadata +574 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
module Ey::Core::Associations
|
2
|
+
def assoc_coverage(options)
|
3
|
+
if defined? Cistern::Coverage
|
4
|
+
call = Cistern::Coverage.find_caller_before("ey-core/associations.rb")
|
5
|
+
|
6
|
+
if call and call.label.start_with?("<class:")
|
7
|
+
options[:coverage_file] = call.absolute_path
|
8
|
+
options[:coverage_line] = call.lineno
|
9
|
+
options[:coverage_hits] = 0
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def associations
|
15
|
+
@associations ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def assoc_reader(name, options={})
|
19
|
+
assoc_key = options[:key] || "#{name}_id"
|
20
|
+
collection = options[:collection] || "#{name}s"
|
21
|
+
resource = options[:resource] || name
|
22
|
+
assoc_name = options[:assoc_name] || resource
|
23
|
+
|
24
|
+
# handle polymorphic assocations
|
25
|
+
#
|
26
|
+
# really only used for connector sources, as they may be cluster_components or addons
|
27
|
+
disambiguate = Proc.new do |object, url, index=0|
|
28
|
+
if object.is_a?(Array) && index > (object.size - 1)
|
29
|
+
raise "No matching object found in #{object}"
|
30
|
+
elsif object.is_a?(Array) && url
|
31
|
+
url_pieces = URI.parse(url).path.split("/").map { |piece| piece.gsub(/-|_/,'') } # "/cluster-components/x" => ["clustercomponents", "x"]
|
32
|
+
|
33
|
+
object.find do |model|
|
34
|
+
normalized_model = model.to_s.gsub(/-|_/, '') # [:cluster_components, :addons] => ["clustercomponents", "addons"]
|
35
|
+
url_pieces.find { |piece| piece.include?(normalized_model) }
|
36
|
+
end
|
37
|
+
elsif object.is_a?(Array)
|
38
|
+
object[index]
|
39
|
+
else
|
40
|
+
object
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
define_method(name) do
|
45
|
+
url = self.send("#{name}_url")
|
46
|
+
id = send(assoc_key)
|
47
|
+
|
48
|
+
if id || url
|
49
|
+
begin
|
50
|
+
index ||= 0
|
51
|
+
this_resource = disambiguate[resource, url, index]
|
52
|
+
this_assoc_name = disambiguate[assoc_name, url, index]
|
53
|
+
this_collection = disambiguate[collection, url, index]
|
54
|
+
|
55
|
+
fetched = self.connection.send("get_#{this_assoc_name}", {"id" => id, "url" => url}).body
|
56
|
+
rescue RuntimeError => e
|
57
|
+
if e.message.match(/url needed/i)
|
58
|
+
index += 1
|
59
|
+
retry if index < 3
|
60
|
+
else
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
rescue Ey::Core::Response::NotFound
|
64
|
+
index += 1
|
65
|
+
index < 3 ? retry : raise
|
66
|
+
end
|
67
|
+
|
68
|
+
unless fetched[this_resource.to_s]
|
69
|
+
raise "Expected a '#{this_resource.to_s}' in '#{fetched.inspect}'"
|
70
|
+
end
|
71
|
+
|
72
|
+
attributes = fetched[this_resource.to_s]
|
73
|
+
|
74
|
+
if self.connection.respond_to?(this_collection)
|
75
|
+
attributes = attributes.merge(collection: self.connection.send(this_collection))
|
76
|
+
end
|
77
|
+
|
78
|
+
self.connection.send(this_assoc_name, attributes)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def assoc_writer(name, options={})
|
84
|
+
assoc_key = options[:key] || "#{name}_id"
|
85
|
+
url_key = options[:key] || "#{name}_url"
|
86
|
+
|
87
|
+
attr_accessor assoc_key
|
88
|
+
|
89
|
+
define_method("#{name}=") do |assoc|
|
90
|
+
if assoc.respond_to?(:identity)
|
91
|
+
self.send("#{assoc_key}=", assoc.identity)
|
92
|
+
elsif assoc.is_a?(String) && assoc.match(URI::regexp)
|
93
|
+
self.send("#{url_key}=", assoc)
|
94
|
+
else
|
95
|
+
self.send("#{assoc_key}=", assoc)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def assoc_accessor(name, options={})
|
101
|
+
assoc_coverage(options)
|
102
|
+
|
103
|
+
if self.associations[name]
|
104
|
+
raise ArgumentError, "#{self.name} association[#{name}] specified more than once"
|
105
|
+
else
|
106
|
+
self.associations[name] = options
|
107
|
+
end
|
108
|
+
|
109
|
+
aliases = Array(options[:aliases] || name.to_s)
|
110
|
+
|
111
|
+
attribute(:"#{name}_url", aliases: aliases, parser: lambda { |v,_| v.is_a?(String) && v })
|
112
|
+
|
113
|
+
assoc_reader(name, options)
|
114
|
+
assoc_writer(name, options)
|
115
|
+
end
|
116
|
+
|
117
|
+
alias has_one assoc_accessor
|
118
|
+
|
119
|
+
def collection_reader(name, options={})
|
120
|
+
assoc_coverage(options)
|
121
|
+
|
122
|
+
if self.associations[name]
|
123
|
+
raise ArgumentError, "#{self.name} association[#{name}] specified more than once"
|
124
|
+
else
|
125
|
+
self.associations[name] = options
|
126
|
+
end
|
127
|
+
|
128
|
+
attribute(:"#{name}_url", aliases: options[:aliases] || [name.to_s])
|
129
|
+
|
130
|
+
assoc_key = options[:key] || name
|
131
|
+
collection_key = options[:model] || assoc_key
|
132
|
+
|
133
|
+
define_method(name) do
|
134
|
+
value = self.send("#{name}_url")
|
135
|
+
|
136
|
+
if self.identity && !value
|
137
|
+
raise "Cannot load #{name} association: #{name}_url is not set"
|
138
|
+
end
|
139
|
+
|
140
|
+
# @fixme this allows collections to be stored in a url variable on create before being replaced
|
141
|
+
# by a url entry after create upon {#merge_attributes}
|
142
|
+
if value.nil?
|
143
|
+
[]
|
144
|
+
elsif value.is_a?(String) && value.match(URI::regexp)
|
145
|
+
self.connection.send(collection_key, {"url" => value})
|
146
|
+
elsif value.is_a?(Hash)
|
147
|
+
[value]
|
148
|
+
else
|
149
|
+
Array(value)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
alias has_many collection_reader
|
155
|
+
end
|
data/lib/ey-core/cli.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'ey-core'
|
4
|
+
require 'awesome_print'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
Cistern.formatter = Cistern::Formatter::AwesomePrint
|
8
|
+
|
9
|
+
class Ey::Core::Cli
|
10
|
+
|
11
|
+
def self.stdout
|
12
|
+
@stdout ||= STDOUT
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.say(*args)
|
16
|
+
self.stdout.puts(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :options, :action, :resource, :client
|
20
|
+
|
21
|
+
def initialize(args=ARGV)
|
22
|
+
@action, @options = parse(args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse(args)
|
26
|
+
options = {}
|
27
|
+
|
28
|
+
action, resource_name, resource_id = OptionParser.new do |opts|
|
29
|
+
opts.banner = "Usage: ey-core ACTION RESOURCE RESOURCE_ID [options]"
|
30
|
+
|
31
|
+
opts.separator ""
|
32
|
+
opts.separator "Specific options:"
|
33
|
+
|
34
|
+
opts.on("-t", "--token [TOKEN]",
|
35
|
+
"Use specific token. Defaults to core url entry in ~/.ey-core yaml file") do |token|
|
36
|
+
options[:token] = token
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-u", "--url [URL]",
|
40
|
+
"Use specific core URL. Defaults to 'https://api.engineyard.com'") do |url|
|
41
|
+
options[:url] = url
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
45
|
+
options[:logger] = v ? Logger.new(STDOUT) : Logger.new(nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.separator ""
|
49
|
+
opts.separator "Common options:"
|
50
|
+
|
51
|
+
# No argument, shows at tail. This will print an options summary.
|
52
|
+
# Try it and see!
|
53
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
54
|
+
puts opts
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
# Another typical switch to print the version.
|
59
|
+
opts.on_tail("--version", "Show version") do
|
60
|
+
puts Ey::Core::VERSION
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
end.parse!(args)
|
64
|
+
|
65
|
+
set_client(options)
|
66
|
+
|
67
|
+
set_resource(action, resource_name, resource_id) if resource_name && resource_id
|
68
|
+
|
69
|
+
[action, (options.to_hash || {})]
|
70
|
+
end
|
71
|
+
|
72
|
+
def run
|
73
|
+
public_send(action)
|
74
|
+
end
|
75
|
+
|
76
|
+
def console
|
77
|
+
Pry.config.prompt = proc { |obj, nest_level, _| "ey-core:> " }
|
78
|
+
self.pry
|
79
|
+
end
|
80
|
+
|
81
|
+
def show
|
82
|
+
Ey::Core::Cli.say(resource.ai)
|
83
|
+
end
|
84
|
+
|
85
|
+
def destroy
|
86
|
+
response = resource.destroy!
|
87
|
+
|
88
|
+
if response.is_a?(Ey::Core::Client::Request)
|
89
|
+
response.wait_for!(response.service.timeout, response.service.poll_interval) do |request|
|
90
|
+
Ey::Core::Cli.say "Waiting ... #{Time.now}"
|
91
|
+
Ey::Core::Cli.say(response.ai) unless request.ready?
|
92
|
+
request.ready?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Ey::Core::Cli.say(response.ai)
|
97
|
+
end
|
98
|
+
|
99
|
+
def current_user
|
100
|
+
@current_user ||= @client.users.current
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_client(options)
|
104
|
+
@client ||= Ey::Core::Client.new(options)
|
105
|
+
end
|
106
|
+
|
107
|
+
def set_resource(action, resource_name, resource_id)
|
108
|
+
action = 'show' if action == 'console'
|
109
|
+
action || raise(ArgumentError.new("Missing action"))
|
110
|
+
Ey::Core::Client.models.find { |m,_| m.to_s == resource_name } || raise(ArgumentError.new("Unknown resource: #{resource_name}"))
|
111
|
+
%w[show destroy].include?(action) || raise(ArgumentError.new("Unknown action: #{action}"))
|
112
|
+
|
113
|
+
# TODO: irregular inflections and all that
|
114
|
+
collection = "#{resource_name.to_s}s"
|
115
|
+
|
116
|
+
@resource = client.public_send(collection).get!(resource_id)
|
117
|
+
end
|
118
|
+
end # class Ey::Core::Cli
|
@@ -0,0 +1,402 @@
|
|
1
|
+
class Ey::Core::Client < Cistern::Service
|
2
|
+
NotPermitted = Class.new(StandardError)
|
3
|
+
|
4
|
+
collection_path "ey-core/collections"
|
5
|
+
model_path "ey-core/models"
|
6
|
+
request_path "ey-core/requests"
|
7
|
+
|
8
|
+
collection :account_cancellations
|
9
|
+
collection :account_referrals
|
10
|
+
collection :accounts
|
11
|
+
collection :addons
|
12
|
+
collection :addresses
|
13
|
+
collection :alerts
|
14
|
+
collection :application_archives
|
15
|
+
collection :application_deployments
|
16
|
+
collection :applications
|
17
|
+
collection :backup_files
|
18
|
+
collection :components
|
19
|
+
collection :contacts
|
20
|
+
collection :costs
|
21
|
+
collection :database_plan_usages
|
22
|
+
collection :database_server_revisions
|
23
|
+
collection :database_server_snapshots
|
24
|
+
collection :database_server_usages
|
25
|
+
collection :database_servers
|
26
|
+
collection :database_services
|
27
|
+
collection :environment_plan_usages
|
28
|
+
collection :environments
|
29
|
+
collection :features
|
30
|
+
collection :firewall_rules
|
31
|
+
collection :firewalls
|
32
|
+
collection :gems
|
33
|
+
collection :keypair_deployments
|
34
|
+
collection :keypairs
|
35
|
+
collection :legacy_alerts
|
36
|
+
collection :load_balancer_nodes
|
37
|
+
collection :load_balancer_services
|
38
|
+
collection :load_balancers
|
39
|
+
collection :logical_databases
|
40
|
+
collection :logs
|
41
|
+
collection :memberships
|
42
|
+
collection :messages
|
43
|
+
collection :plan_usages
|
44
|
+
collection :provider_locations
|
45
|
+
collection :providers
|
46
|
+
collection :requests
|
47
|
+
collection :server_events
|
48
|
+
collection :server_usages
|
49
|
+
collection :servers
|
50
|
+
collection :services
|
51
|
+
collection :ssl_certificates
|
52
|
+
collection :storage_users
|
53
|
+
collection :storages
|
54
|
+
collection :tasks
|
55
|
+
collection :tokens
|
56
|
+
collection :untracked_addresses
|
57
|
+
collection :untracked_servers
|
58
|
+
collection :users
|
59
|
+
collection :volumes
|
60
|
+
|
61
|
+
model :account
|
62
|
+
model :account_cancellation
|
63
|
+
model :account_referral
|
64
|
+
model :account_trial
|
65
|
+
model :addon
|
66
|
+
model :address
|
67
|
+
model :alert
|
68
|
+
model :application
|
69
|
+
model :application_archive
|
70
|
+
model :application_deployment
|
71
|
+
model :backup_file
|
72
|
+
model :billing
|
73
|
+
model :component
|
74
|
+
model :contact
|
75
|
+
model :cost
|
76
|
+
model :database_plan_usage
|
77
|
+
model :database_server
|
78
|
+
model :database_server_revision
|
79
|
+
model :database_server_snapshot
|
80
|
+
model :database_server_usage
|
81
|
+
model :database_service
|
82
|
+
model :environment
|
83
|
+
model :environment_plan_usage
|
84
|
+
model :feature
|
85
|
+
model :firewall
|
86
|
+
model :firewall_rule
|
87
|
+
model :gem
|
88
|
+
model :keypair
|
89
|
+
model :keypair_deployment
|
90
|
+
model :legacy_alert
|
91
|
+
model :load_balancer
|
92
|
+
model :load_balancer_node
|
93
|
+
model :load_balancer_service
|
94
|
+
model :log
|
95
|
+
model :logical_database
|
96
|
+
model :membership
|
97
|
+
model :message
|
98
|
+
model :plan_usage
|
99
|
+
model :provider
|
100
|
+
model :provider_location
|
101
|
+
model :request
|
102
|
+
model :server
|
103
|
+
model :server_event
|
104
|
+
model :server_usage
|
105
|
+
model :service
|
106
|
+
model :ssl_certificate
|
107
|
+
model :storage
|
108
|
+
model :storage_user
|
109
|
+
model :support_trial
|
110
|
+
model :task
|
111
|
+
model :token
|
112
|
+
model :untracked_address
|
113
|
+
model :untracked_server
|
114
|
+
model :user
|
115
|
+
model :volume
|
116
|
+
|
117
|
+
request :attach_address
|
118
|
+
request :authorized_channel
|
119
|
+
request :boot_environment
|
120
|
+
request :bootstrap_logical_database
|
121
|
+
request :cancel_account
|
122
|
+
request :create_account
|
123
|
+
request :create_addon
|
124
|
+
request :create_address
|
125
|
+
request :create_alert
|
126
|
+
request :create_application
|
127
|
+
request :create_application_archive
|
128
|
+
request :create_backup_file
|
129
|
+
request :create_database_server
|
130
|
+
request :create_database_service
|
131
|
+
request :create_database_service_snapshot
|
132
|
+
request :create_environment
|
133
|
+
request :create_firewall
|
134
|
+
request :create_firewall_rule
|
135
|
+
request :create_keypair
|
136
|
+
request :create_keypair_deployment
|
137
|
+
request :create_load_balancer
|
138
|
+
request :create_log
|
139
|
+
request :create_logical_database
|
140
|
+
request :create_membership
|
141
|
+
request :create_message
|
142
|
+
request :create_password_reset
|
143
|
+
request :create_provider
|
144
|
+
request :create_ssl_certificate
|
145
|
+
request :create_storage
|
146
|
+
request :create_storage_user
|
147
|
+
request :create_task
|
148
|
+
request :create_token
|
149
|
+
request :create_untracked_address
|
150
|
+
request :create_untracked_server
|
151
|
+
request :create_user
|
152
|
+
request :deploy_environment_application
|
153
|
+
request :deprovision_environment
|
154
|
+
request :destroy_addon
|
155
|
+
request :destroy_database_server
|
156
|
+
request :destroy_database_server_snapshot
|
157
|
+
request :destroy_database_service
|
158
|
+
request :destroy_environment
|
159
|
+
request :destroy_firewall
|
160
|
+
request :destroy_firewall_rule
|
161
|
+
request :destroy_load_balancer
|
162
|
+
request :destroy_logical_database
|
163
|
+
request :destroy_provider
|
164
|
+
request :destroy_server
|
165
|
+
request :destroy_ssl_certificate
|
166
|
+
request :destroy_storage
|
167
|
+
request :destroy_storage_user
|
168
|
+
request :destroy_user
|
169
|
+
request :detach_address
|
170
|
+
request :disable_feature
|
171
|
+
request :discover_database_server
|
172
|
+
request :discover_database_server_snapshots
|
173
|
+
request :discover_provider_location
|
174
|
+
request :download_file
|
175
|
+
request :enable_feature
|
176
|
+
request :get_account
|
177
|
+
request :get_account_cancellation
|
178
|
+
request :get_account_referrals
|
179
|
+
request :get_account_trial
|
180
|
+
request :get_accounts
|
181
|
+
request :get_addon
|
182
|
+
request :get_addons
|
183
|
+
request :get_address
|
184
|
+
request :get_addresses
|
185
|
+
request :get_alert
|
186
|
+
request :get_alerting_environments
|
187
|
+
request :get_alerts
|
188
|
+
request :get_api_token
|
189
|
+
request :get_application
|
190
|
+
request :get_application_archive
|
191
|
+
request :get_application_archives
|
192
|
+
request :get_application_deployment
|
193
|
+
request :get_application_deployments
|
194
|
+
request :get_applications
|
195
|
+
request :get_backup_file
|
196
|
+
request :get_backup_files
|
197
|
+
request :get_billing
|
198
|
+
request :get_component
|
199
|
+
request :get_components
|
200
|
+
request :get_contacts
|
201
|
+
request :get_costs
|
202
|
+
request :get_current_user
|
203
|
+
request :get_database_plan_usages
|
204
|
+
request :get_database_server
|
205
|
+
request :get_database_server_revisions
|
206
|
+
request :get_database_server_snapshot
|
207
|
+
request :get_database_server_snapshots
|
208
|
+
request :get_database_server_usages
|
209
|
+
request :get_database_servers
|
210
|
+
request :get_database_servers_firewalls
|
211
|
+
request :get_database_service
|
212
|
+
request :get_database_services
|
213
|
+
request :get_environment
|
214
|
+
request :get_environment_database_services
|
215
|
+
request :get_environment_logical_databases
|
216
|
+
request :get_environment_plan_usages
|
217
|
+
request :get_environments
|
218
|
+
request :get_feature
|
219
|
+
request :get_features
|
220
|
+
request :get_firewall
|
221
|
+
request :get_firewall_rule
|
222
|
+
request :get_firewall_rules
|
223
|
+
request :get_firewalls
|
224
|
+
request :get_gem
|
225
|
+
request :get_keypair
|
226
|
+
request :get_keypair_deployment
|
227
|
+
request :get_keypair_deployments
|
228
|
+
request :get_keypairs
|
229
|
+
request :get_legacy_alert
|
230
|
+
request :get_legacy_alerts
|
231
|
+
request :get_load_balancer
|
232
|
+
request :get_load_balancer_node
|
233
|
+
request :get_load_balancer_nodes
|
234
|
+
request :get_load_balancer_service
|
235
|
+
request :get_load_balancer_services
|
236
|
+
request :get_load_balancers
|
237
|
+
request :get_log
|
238
|
+
request :get_logical_database
|
239
|
+
request :get_logical_databases
|
240
|
+
request :get_logs
|
241
|
+
request :get_membership
|
242
|
+
request :get_message
|
243
|
+
request :get_messages
|
244
|
+
request :get_metadata
|
245
|
+
request :get_plan_usages
|
246
|
+
request :get_possible_provider_locations
|
247
|
+
request :get_provider
|
248
|
+
request :get_provider_location
|
249
|
+
request :get_provider_locations
|
250
|
+
request :get_providers
|
251
|
+
request :get_request
|
252
|
+
request :get_requests
|
253
|
+
request :get_server
|
254
|
+
request :get_server_event
|
255
|
+
request :get_server_events
|
256
|
+
request :get_server_usages
|
257
|
+
request :get_servers
|
258
|
+
request :get_ssl_certificate
|
259
|
+
request :get_ssl_certificates
|
260
|
+
request :get_storage
|
261
|
+
request :get_storage_user
|
262
|
+
request :get_storage_users
|
263
|
+
request :get_storages
|
264
|
+
request :get_support_trial
|
265
|
+
request :get_task
|
266
|
+
request :get_tasks
|
267
|
+
request :get_untracked_server
|
268
|
+
request :get_untracked_servers
|
269
|
+
request :get_user
|
270
|
+
request :get_users
|
271
|
+
request :get_volumes
|
272
|
+
request :reboot_server
|
273
|
+
request :request_callback
|
274
|
+
request :reset_password
|
275
|
+
request :run_cluster_application_action
|
276
|
+
request :run_environment_application_action
|
277
|
+
request :signup
|
278
|
+
request :update_addon
|
279
|
+
request :update_address
|
280
|
+
request :update_alert
|
281
|
+
request :update_application_archive
|
282
|
+
request :update_billing
|
283
|
+
request :update_membership
|
284
|
+
request :update_server
|
285
|
+
request :update_ssl_certificate
|
286
|
+
request :update_untracked_server
|
287
|
+
request :upload_file
|
288
|
+
|
289
|
+
recognizes :token, :url, :logger, :adapter, :builder, :connection_options, :auth_id, :auth_key, :cache, :config_file
|
290
|
+
|
291
|
+
module Shared
|
292
|
+
attr_reader :authentication, :url, :cache
|
293
|
+
|
294
|
+
def setup(options)
|
295
|
+
token_dotfile = begin
|
296
|
+
if options[:config_file]
|
297
|
+
YAML.load_file(options[:config_file]) || {} # if the file is empty, yaml returns false
|
298
|
+
else
|
299
|
+
YAML.load_file(File.expand_path("~/.ey-core"))
|
300
|
+
end
|
301
|
+
rescue Errno::ENOENT
|
302
|
+
{}
|
303
|
+
end
|
304
|
+
|
305
|
+
resolved_url = options[:url] || ENV["CORE_URL"] || "https://api.engineyard.com/"
|
306
|
+
@url = File.join(resolved_url, "/") # trailing slash # consistency # hash tag you're welcome
|
307
|
+
@cache = if options[:cache] == true
|
308
|
+
Ey::Core::MemoryCache
|
309
|
+
else options[:cache]
|
310
|
+
end
|
311
|
+
|
312
|
+
@authentication = nil
|
313
|
+
@token = if options.has_key?(:token) && options[:token].nil?
|
314
|
+
@authentication = :none
|
315
|
+
else
|
316
|
+
options[:token] || token_dotfile[@url] || token_dotfile[@url.gsub(/\/$/, "")] # matching with or without trailing slash
|
317
|
+
end
|
318
|
+
|
319
|
+
# For HMAC
|
320
|
+
@auth_id = options[:auth_id]
|
321
|
+
@auth_key = options[:auth_key]
|
322
|
+
|
323
|
+
unless @authentication == :none
|
324
|
+
if !@auth_id && !@auth_key && !@token
|
325
|
+
raise "Missing token. Use Ey::Core::Client.new(token: mytoken) or add \"'#{@url}': mytoken\" to your ~/.ey-core file" unless @token
|
326
|
+
elsif options[:token] || (@token && !@auth_id) # token was explicitly provided
|
327
|
+
@authentication = :token
|
328
|
+
else
|
329
|
+
@authentication = :hmac
|
330
|
+
@token = nil
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
@logger = options[:logger] || Logger.new(nil)
|
335
|
+
end
|
336
|
+
|
337
|
+
# strong parameter emulation
|
338
|
+
def require_parameters(_params, *_requirements)
|
339
|
+
params = Cistern::Hash.stringify_keys(_params)
|
340
|
+
requirements = _requirements.map(&:to_s)
|
341
|
+
|
342
|
+
requirements.each do |requirement|
|
343
|
+
unless !params[requirement].nil?
|
344
|
+
if self.class == Ey::Core::Client::Real
|
345
|
+
raise ArgumentError, "param is missing or the value is empty: #{requirement}"
|
346
|
+
else
|
347
|
+
response(
|
348
|
+
:status => 400,
|
349
|
+
:body => "param is missing or the value is empty: #{requirement}")
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
values = params.values_at(*requirements)
|
354
|
+
values.size == 1 ? values.first : values
|
355
|
+
end
|
356
|
+
|
357
|
+
def require_arguments(_params, *_requirements)
|
358
|
+
params = Cistern::Hash.stringify_keys(_params)
|
359
|
+
requirements = _requirements.map(&:to_s)
|
360
|
+
|
361
|
+
values = requirements.map do |requirement|
|
362
|
+
if params[requirement].nil?
|
363
|
+
raise ArgumentError, "argument is missing or the value is empty: #{requirement}"
|
364
|
+
end
|
365
|
+
params[requirement]
|
366
|
+
end
|
367
|
+
[params, *values]
|
368
|
+
end
|
369
|
+
|
370
|
+
def require_argument(_params, *_requirements)
|
371
|
+
params = Cistern::Hash.stringify_keys(_params)
|
372
|
+
requirements = _requirements.map(&:to_s)
|
373
|
+
|
374
|
+
values = params.values_at(*requirements)
|
375
|
+
values.all?(&:nil?) && raise(ArgumentError.new("argument is missing or the value is empty: #{requirement}"))
|
376
|
+
values.size == 1 ? values.first : values
|
377
|
+
end
|
378
|
+
|
379
|
+
def require_argument!(_params, *_requirements)
|
380
|
+
params = Cistern::Hash.stringify_keys(_params)
|
381
|
+
requirements = _requirements.map(&:to_s)
|
382
|
+
|
383
|
+
values = params.values_at(*requirements)
|
384
|
+
values.all?(&:nil?) && raise(ArgumentError.new("argument is missing or the value is empty: #{requirement}"))
|
385
|
+
requirements.each { |r| params.delete(r) }
|
386
|
+
values.size == 1 ? values.first : values
|
387
|
+
end
|
388
|
+
|
389
|
+
def url_for(*args)
|
390
|
+
File.join(@url.to_s, *args.map(&:to_s))
|
391
|
+
end
|
392
|
+
|
393
|
+
# @deprecated will be removed in 3.x
|
394
|
+
# @see {#services}
|
395
|
+
def metadata
|
396
|
+
services.get("core")
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end # Ey::Core::Client
|
400
|
+
|
401
|
+
require 'ey-core/client/real'
|
402
|
+
require 'ey-core/client/mock'
|