trucker-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +1277 -0
- data/Rakefile +13 -0
- data/bin/truck +18 -0
- data/lib/admin/README.md +30 -0
- data/lib/admin/curl.rb +59 -0
- data/lib/admin/guid.rb +89 -0
- data/lib/admin/plugin.rb +8 -0
- data/lib/admin/service_auth_token.rb +93 -0
- data/lib/admin/service_broker/add.rb +54 -0
- data/lib/admin/service_broker/remove.rb +33 -0
- data/lib/admin/service_broker/service_brokers.rb +29 -0
- data/lib/admin/service_broker/update.rb +60 -0
- data/lib/admin/set_quota.rb +44 -0
- data/lib/cf.rb +14 -0
- data/lib/cf/cli.rb +495 -0
- data/lib/cf/cli/app/app.rb +43 -0
- data/lib/cf/cli/app/apps.rb +87 -0
- data/lib/cf/cli/app/base.rb +72 -0
- data/lib/cf/cli/app/delete.rb +95 -0
- data/lib/cf/cli/app/deprecated.rb +11 -0
- data/lib/cf/cli/app/env.rb +99 -0
- data/lib/cf/cli/app/events.rb +45 -0
- data/lib/cf/cli/app/files.rb +137 -0
- data/lib/cf/cli/app/health.rb +26 -0
- data/lib/cf/cli/app/instances.rb +53 -0
- data/lib/cf/cli/app/logs.rb +76 -0
- data/lib/cf/cli/app/push.rb +104 -0
- data/lib/cf/cli/app/push/create.rb +108 -0
- data/lib/cf/cli/app/push/interactions.rb +90 -0
- data/lib/cf/cli/app/push/sync.rb +57 -0
- data/lib/cf/cli/app/rename.rb +35 -0
- data/lib/cf/cli/app/restart.rb +31 -0
- data/lib/cf/cli/app/scale.rb +63 -0
- data/lib/cf/cli/app/start.rb +175 -0
- data/lib/cf/cli/app/stats.rb +66 -0
- data/lib/cf/cli/app/stop.rb +27 -0
- data/lib/cf/cli/domain/base.rb +9 -0
- data/lib/cf/cli/domain/domains.rb +40 -0
- data/lib/cf/cli/domain/map.rb +55 -0
- data/lib/cf/cli/domain/unmap.rb +56 -0
- data/lib/cf/cli/help.rb +15 -0
- data/lib/cf/cli/interactive.rb +104 -0
- data/lib/cf/cli/login_requirements.rb +13 -0
- data/lib/cf/cli/organization/base.rb +12 -0
- data/lib/cf/cli/organization/create.rb +36 -0
- data/lib/cf/cli/organization/delete.rb +61 -0
- data/lib/cf/cli/organization/org.rb +45 -0
- data/lib/cf/cli/organization/orgs.rb +30 -0
- data/lib/cf/cli/organization/rename.rb +36 -0
- data/lib/cf/cli/populators/base.rb +16 -0
- data/lib/cf/cli/populators/organization.rb +32 -0
- data/lib/cf/cli/populators/populator_methods.rb +64 -0
- data/lib/cf/cli/populators/space.rb +33 -0
- data/lib/cf/cli/populators/target.rb +14 -0
- data/lib/cf/cli/route/base.rb +9 -0
- data/lib/cf/cli/route/delete.rb +28 -0
- data/lib/cf/cli/route/map.rb +68 -0
- data/lib/cf/cli/route/routes.rb +26 -0
- data/lib/cf/cli/route/unmap.rb +56 -0
- data/lib/cf/cli/service/base.rb +9 -0
- data/lib/cf/cli/service/bind.rb +43 -0
- data/lib/cf/cli/service/create.rb +158 -0
- data/lib/cf/cli/service/delete.rb +82 -0
- data/lib/cf/cli/service/rename.rb +35 -0
- data/lib/cf/cli/service/service.rb +40 -0
- data/lib/cf/cli/service/service_helper.rb +25 -0
- data/lib/cf/cli/service/service_instance_helper.rb +100 -0
- data/lib/cf/cli/service/services.rb +110 -0
- data/lib/cf/cli/service/unbind.rb +36 -0
- data/lib/cf/cli/space/base.rb +27 -0
- data/lib/cf/cli/space/create.rb +66 -0
- data/lib/cf/cli/space/delete.rb +55 -0
- data/lib/cf/cli/space/rename.rb +38 -0
- data/lib/cf/cli/space/space.rb +66 -0
- data/lib/cf/cli/space/spaces.rb +57 -0
- data/lib/cf/cli/space/switch.rb +18 -0
- data/lib/cf/cli/start/base.rb +35 -0
- data/lib/cf/cli/start/colors.rb +13 -0
- data/lib/cf/cli/start/login.rb +104 -0
- data/lib/cf/cli/start/logout.rb +17 -0
- data/lib/cf/cli/start/target.rb +50 -0
- data/lib/cf/cli/start/target_prettifier.rb +35 -0
- data/lib/cf/cli/start/targets.rb +16 -0
- data/lib/cf/cli/user/base.rb +29 -0
- data/lib/cf/cli/user/create.rb +51 -0
- data/lib/cf/cli/user/passwd.rb +36 -0
- data/lib/cf/cli/user/register.rb +42 -0
- data/lib/cf/cli/user/users.rb +32 -0
- data/lib/cf/constants.rb +10 -0
- data/lib/cf/errors.rb +19 -0
- data/lib/cf/plugin.rb +56 -0
- data/lib/cf/spacing.rb +89 -0
- data/lib/cf/spec_helper.rb +1 -0
- data/lib/cf/test_support.rb +6 -0
- data/lib/cf/version.rb +3 -0
- data/lib/console/README.md +16 -0
- data/lib/console/console.rb +187 -0
- data/lib/console/plugin.rb +32 -0
- data/lib/manifests/errors.rb +35 -0
- data/lib/manifests/loader.rb +31 -0
- data/lib/manifests/loader/builder.rb +39 -0
- data/lib/manifests/loader/normalizer.rb +145 -0
- data/lib/manifests/loader/resolver.rb +79 -0
- data/lib/manifests/manifests.rb +343 -0
- data/lib/manifests/plugin.rb +140 -0
- data/lib/micro/README.md +25 -0
- data/lib/micro/errors.rb +4 -0
- data/lib/micro/micro.rb +56 -0
- data/lib/micro/plugin.rb +197 -0
- data/lib/micro/switcher/base.rb +79 -0
- data/lib/micro/switcher/darwin.rb +21 -0
- data/lib/micro/switcher/dummy.rb +15 -0
- data/lib/micro/switcher/linux.rb +16 -0
- data/lib/micro/switcher/windows.rb +31 -0
- data/lib/micro/vmrun.rb +175 -0
- data/lib/tasks/gem_release.rake +56 -0
- data/lib/tasks/windows_build.rake +14 -0
- data/lib/tunnel/README.md +29 -0
- data/lib/tunnel/config/clients.yml +17 -0
- data/lib/tunnel/helper-app/Gemfile +10 -0
- data/lib/tunnel/helper-app/Gemfile.lock +48 -0
- data/lib/tunnel/helper-app/server.rb +43 -0
- data/lib/tunnel/plugin.rb +183 -0
- data/lib/tunnel/tunnel.rb +295 -0
- data/spec/admin/curl_spec.rb +52 -0
- data/spec/admin/guid_spec.rb +85 -0
- data/spec/admin/service_broker/add_spec.rb +64 -0
- data/spec/admin/service_broker/remove_spec.rb +46 -0
- data/spec/admin/service_broker/service_brokers_spec.rb +34 -0
- data/spec/admin/service_broker/update_spec.rb +51 -0
- data/spec/admin/set_quota_spec.rb +89 -0
- data/spec/assets/env/Gemfile +4 -0
- data/spec/assets/env/Gemfile.lock +20 -0
- data/spec/assets/env/env_test.rb +58 -0
- data/spec/assets/hello-sinatra/Gemfile +3 -0
- data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
- data/spec/assets/hello-sinatra/config.ru +3 -0
- data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
- data/spec/assets/hello-sinatra/main.rb +8 -0
- data/spec/assets/rails328_ruby187_app/Gemfile +39 -0
- data/spec/assets/rails328_ruby187_app/README.rdoc +261 -0
- data/spec/assets/rails328_ruby187_app/Rakefile +7 -0
- data/spec/assets/rails328_ruby187_app/app/assets/images/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/app/assets/javascripts/application.js +15 -0
- data/spec/assets/rails328_ruby187_app/app/assets/stylesheets/application.css +13 -0
- data/spec/assets/rails328_ruby187_app/app/controllers/application_controller.rb +3 -0
- data/spec/assets/rails328_ruby187_app/app/helpers/application_helper.rb +2 -0
- data/spec/assets/rails328_ruby187_app/app/views/layouts/application.html.erb +14 -0
- data/spec/assets/rails328_ruby187_app/config.ru +4 -0
- data/spec/assets/rails328_ruby187_app/config/application.rb +62 -0
- data/spec/assets/rails328_ruby187_app/config/boot.rb +6 -0
- data/spec/assets/rails328_ruby187_app/config/database.yml +25 -0
- data/spec/assets/rails328_ruby187_app/config/environment.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/environments/development.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/environments/production.rb +67 -0
- data/spec/assets/rails328_ruby187_app/config/environments/test.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/inflections.rb +15 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/mime_types.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/secret_token.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/session_store.rb +8 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/assets/rails328_ruby187_app/config/locales/en.yml +5 -0
- data/spec/assets/rails328_ruby187_app/config/routes.rb +58 -0
- data/spec/assets/rails328_ruby187_app/db/seeds.rb +7 -0
- data/spec/assets/rails328_ruby187_app/doc/README_FOR_APP +2 -0
- data/spec/assets/rails328_ruby187_app/manifest.yml +7 -0
- data/spec/assets/rails328_ruby187_app/public/404.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/422.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/500.html +25 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/manifest.yml +4 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails-be8732dac73d845ac5b142c8fb5f9fb0.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/favicon.ico +0 -0
- data/spec/assets/rails328_ruby187_app/public/index.html +241 -0
- data/spec/assets/rails328_ruby187_app/public/robots.txt +5 -0
- data/spec/assets/rails328_ruby187_app/script/rails +6 -0
- data/spec/assets/rails328_ruby187_app/test/performance/browsing_test.rb +12 -0
- data/spec/assets/rails328_ruby187_app/test/test_helper.rb +13 -0
- data/spec/cf/cli/app/base_spec.rb +17 -0
- data/spec/cf/cli/app/delete_spec.rb +197 -0
- data/spec/cf/cli/app/env_spec.rb +261 -0
- data/spec/cf/cli/app/events_spec.rb +72 -0
- data/spec/cf/cli/app/help_spec.rb +39 -0
- data/spec/cf/cli/app/instances_spec.rb +69 -0
- data/spec/cf/cli/app/push/create_spec.rb +444 -0
- data/spec/cf/cli/app/push/interactions_spec.rb +32 -0
- data/spec/cf/cli/app/push_spec.rb +332 -0
- data/spec/cf/cli/app/rename_spec.rb +108 -0
- data/spec/cf/cli/app/restart_spec.rb +47 -0
- data/spec/cf/cli/app/scale_spec.rb +63 -0
- data/spec/cf/cli/app/start_spec.rb +255 -0
- data/spec/cf/cli/app/stats_spec.rb +66 -0
- data/spec/cf/cli/domain/help_spec.rb +39 -0
- data/spec/cf/cli/domain/map_spec.rb +140 -0
- data/spec/cf/cli/domain/unmap_spec.rb +77 -0
- data/spec/cf/cli/help_spec.rb +21 -0
- data/spec/cf/cli/organization/create_spec.rb +121 -0
- data/spec/cf/cli/organization/delete_spec.rb +105 -0
- data/spec/cf/cli/organization/help_spec.rb +39 -0
- data/spec/cf/cli/organization/orgs_spec.rb +116 -0
- data/spec/cf/cli/organization/rename_spec.rb +116 -0
- data/spec/cf/cli/populators/organization_spec.rb +179 -0
- data/spec/cf/cli/populators/space_spec.rb +156 -0
- data/spec/cf/cli/populators/target_spec.rb +39 -0
- data/spec/cf/cli/route/delete_spec.rb +92 -0
- data/spec/cf/cli/route/help_spec.rb +32 -0
- data/spec/cf/cli/route/map_spec.rb +148 -0
- data/spec/cf/cli/route/unmap_spec.rb +114 -0
- data/spec/cf/cli/service/bind_spec.rb +25 -0
- data/spec/cf/cli/service/create_spec.rb +147 -0
- data/spec/cf/cli/service/delete_spec.rb +22 -0
- data/spec/cf/cli/service/help_spec.rb +39 -0
- data/spec/cf/cli/service/rename_spec.rb +103 -0
- data/spec/cf/cli/service/service_helper_spec.rb +66 -0
- data/spec/cf/cli/service/service_instance_helper_spec.rb +155 -0
- data/spec/cf/cli/service/service_spec.rb +23 -0
- data/spec/cf/cli/service/services_spec.rb +156 -0
- data/spec/cf/cli/service/unbind_spec.rb +25 -0
- data/spec/cf/cli/space/base_spec.rb +49 -0
- data/spec/cf/cli/space/create_spec.rb +144 -0
- data/spec/cf/cli/space/delete_spec.rb +109 -0
- data/spec/cf/cli/space/help_spec.rb +39 -0
- data/spec/cf/cli/space/rename_spec.rb +110 -0
- data/spec/cf/cli/space/space_spec.rb +80 -0
- data/spec/cf/cli/space/spaces_spec.rb +107 -0
- data/spec/cf/cli/space/switch_space_spec.rb +57 -0
- data/spec/cf/cli/start/help_spec.rb +39 -0
- data/spec/cf/cli/start/login_spec.rb +142 -0
- data/spec/cf/cli/start/logout_spec.rb +49 -0
- data/spec/cf/cli/start/target_prettifier_spec.rb +78 -0
- data/spec/cf/cli/start/target_spec.rb +123 -0
- data/spec/cf/cli/user/create_spec.rb +98 -0
- data/spec/cf/cli/user/help_spec.rb +32 -0
- data/spec/cf/cli/user/passwd_spec.rb +94 -0
- data/spec/cf/cli/user/register_spec.rb +145 -0
- data/spec/cf/cli_spec.rb +474 -0
- data/spec/console/console_spec.rb +189 -0
- data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/clients_factory.rb +7 -0
- data/spec/factories/cfoundry/v2/domains_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/managed_service_instances_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/organizations_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/quota_definitions.rb +13 -0
- data/spec/factories/cfoundry/v2/routes_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_brokers_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_plans_factory.rb +17 -0
- data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/spaces_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/user_provided_service_instances_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/users_factory.rb +7 -0
- data/spec/features/backspace_spec.rb +46 -0
- data/spec/features/create_user_spec.rb +74 -0
- data/spec/features/delete_orphaned_service_spec.rb +64 -0
- data/spec/features/login_spec.rb +65 -0
- data/spec/features/manifests_spec.rb +86 -0
- data/spec/features/org_spec.rb +50 -0
- data/spec/features/push_flow_spec.rb +169 -0
- data/spec/features/service_brokers_spec.rb +173 -0
- data/spec/features/services_spec.rb +122 -0
- data/spec/features/space_spec.rb +107 -0
- data/spec/features/switching_targets_spec.rb +70 -0
- data/spec/manifests/errors_spec.rb +43 -0
- data/spec/manifests/loader/builder_spec.rb +80 -0
- data/spec/manifests/loader/normalizer_spec.rb +158 -0
- data/spec/manifests/manifests_spec.rb +335 -0
- data/spec/manifests/plugin_spec.rb +410 -0
- data/spec/micro/plugin_spec.rb +64 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/support/cli_helper.rb +87 -0
- data/spec/support/config_helper.rb +15 -0
- data/spec/support/factory_girl.rb +6 -0
- data/spec/support/fake_home_dir.rb +55 -0
- data/spec/support/features_helper.rb +99 -0
- data/spec/support/interact_helper.rb +27 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/mock_commands/mock_restart.rb +16 -0
- data/spec/support/mock_commands/mock_start.rb +17 -0
- data/spec/support/shared_examples/errors.rb +40 -0
- data/spec/support/shared_examples/input.rb +14 -0
- data/spec/tunnel/plugin_spec.rb +31 -0
- data/spec/tunnel/tunnel_spec.rb +54 -0
- metadata +814 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require "cf/cli"
|
2
|
+
|
3
|
+
module CFAdmin
|
4
|
+
class SetQuota < CF::CLI
|
5
|
+
def precondition
|
6
|
+
check_target
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Change the quota definition for the given (or current) organization."
|
10
|
+
group :admin
|
11
|
+
input :quota_definition, :argument => :optional,
|
12
|
+
:from_given => by_name(:quota_definition),
|
13
|
+
:desc => "Quota definition to set on the organization"
|
14
|
+
input :organization, :aliases => %w(org o), :argument => :optional,
|
15
|
+
:from_given => by_name(:organization),
|
16
|
+
:default => proc { client.current_organization || interact },
|
17
|
+
:desc => "Organization to update"
|
18
|
+
def set_quota
|
19
|
+
org = input[:organization]
|
20
|
+
quota = input[:quota_definition]
|
21
|
+
|
22
|
+
with_progress(<<MESSAGE.chomp) do
|
23
|
+
Setting quota of #{c(org.name, :name)} to #{c(quota.name, :name)}
|
24
|
+
MESSAGE
|
25
|
+
org.quota_definition = quota
|
26
|
+
org.update!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def ask_quota_definition
|
33
|
+
ask("Quota",
|
34
|
+
:choices => client.quota_definitions,
|
35
|
+
:display => proc(&:name))
|
36
|
+
end
|
37
|
+
|
38
|
+
def ask_organization
|
39
|
+
ask("Organization",
|
40
|
+
:choices => client.organizations,
|
41
|
+
:display => proc(&:name))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/cf.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "cf/version"
|
2
|
+
|
3
|
+
require "cf/cli"
|
4
|
+
|
5
|
+
command_files = "../cf/cli/{app,route,domain,organization,space,service,start,user}/*.rb"
|
6
|
+
Dir[File.expand_path(command_files, __FILE__)].each do |file|
|
7
|
+
require file unless File.basename(file) == 'base.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
require "manifests/plugin"
|
11
|
+
require "admin/plugin"
|
12
|
+
require "console/plugin"
|
13
|
+
require "tunnel/plugin"
|
14
|
+
require "micro/plugin"
|
data/lib/cf/cli.rb
ADDED
@@ -0,0 +1,495 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "socket"
|
3
|
+
require "net/http"
|
4
|
+
require "json/ext"
|
5
|
+
require "multi_json"
|
6
|
+
require "multi_json/adapters/json_gem"
|
7
|
+
require "fileutils"
|
8
|
+
require "mothership"
|
9
|
+
|
10
|
+
require "cfoundry"
|
11
|
+
|
12
|
+
require "cf/constants"
|
13
|
+
require "cf/errors"
|
14
|
+
require "cf/spacing"
|
15
|
+
|
16
|
+
require "cf/cli/help"
|
17
|
+
require "cf/cli/interactive"
|
18
|
+
require "cf/cli/login_requirements"
|
19
|
+
|
20
|
+
|
21
|
+
$cf_asked_auth = false
|
22
|
+
|
23
|
+
module CF
|
24
|
+
class CLI < Mothership
|
25
|
+
include CF::Interactive
|
26
|
+
include CF::Spacing
|
27
|
+
|
28
|
+
option :help, :desc => "Show command usage", :alias => "-h",
|
29
|
+
:default => false
|
30
|
+
|
31
|
+
option :http_proxy, :desc => "Connect with an http proxy server", :alias => "--http-proxy",
|
32
|
+
:value => :http_proxy
|
33
|
+
|
34
|
+
option :https_proxy, :desc => "Connect with an https proxy server", :alias => "--https-proxy",
|
35
|
+
:value => :https_proxy
|
36
|
+
|
37
|
+
option :version, :desc => "Print version number", :alias => "-v",
|
38
|
+
:default => false
|
39
|
+
|
40
|
+
option :verbose, :desc => "Print extra information", :alias => "-V",
|
41
|
+
:default => false
|
42
|
+
|
43
|
+
option :force, :desc => "Skip interaction when possible", :alias => "-f",
|
44
|
+
:type => :boolean, :default => proc { input[:script] }
|
45
|
+
|
46
|
+
option :debug, :desc => "Print full stack trace (instead of crash log)",
|
47
|
+
:type => :boolean, :default => false
|
48
|
+
|
49
|
+
option :quiet, :desc => "Simplify output format", :alias => "-q",
|
50
|
+
:type => :boolean, :default => proc { input[:script] }
|
51
|
+
|
52
|
+
option :script, :desc => "Shortcut for --quiet and --force",
|
53
|
+
:type => :boolean, :default => proc { !$stdout.tty? }
|
54
|
+
|
55
|
+
option :color, :desc => "Use colorful output",
|
56
|
+
:type => :boolean, :default => proc { !input[:quiet] }
|
57
|
+
|
58
|
+
option :trace, :desc => "Show API traffic", :alias => "-t",
|
59
|
+
:default => false
|
60
|
+
|
61
|
+
|
62
|
+
def default_action
|
63
|
+
if input[:version]
|
64
|
+
line "cf #{VERSION}"
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_target
|
71
|
+
unless client && client.target
|
72
|
+
fail "Please select a target with 'truck target'."
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_logged_in
|
77
|
+
check_target
|
78
|
+
unless client.logged_in?
|
79
|
+
if force?
|
80
|
+
fail "Please log in with 'truck login'."
|
81
|
+
else
|
82
|
+
line c("Please log in first to proceed.", :warning)
|
83
|
+
line
|
84
|
+
invoke :login
|
85
|
+
invalidate_client
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "Help!"
|
91
|
+
input :command, :argument => :optional
|
92
|
+
def help
|
93
|
+
if name = input[:command]
|
94
|
+
if cmd = @@commands[name.gsub("-", "_").to_sym]
|
95
|
+
Mothership::Help.command_help(cmd)
|
96
|
+
else
|
97
|
+
unknown_command(name)
|
98
|
+
end
|
99
|
+
elsif Help.has_groups?
|
100
|
+
puts "#{help_header}"
|
101
|
+
|
102
|
+
Mothership::Help.print_help_groups(@@global, true)
|
103
|
+
else
|
104
|
+
Mothership::Help.basic_help(@@commands, @@global)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def help_header
|
109
|
+
<<EOS
|
110
|
+
Cloud Foundry Command Line Interface, version [#{CF::VERSION}]
|
111
|
+
Use 'truck help [command]' for command details.
|
112
|
+
For docs and support visit http://support.cloudfoundry.com
|
113
|
+
|
114
|
+
USAGE EXAMPLES
|
115
|
+
$ cf target api.trucker.io <-- sets the CF instance target where your app will be pushed
|
116
|
+
$ cf push <-- deploys app to current app space on current target
|
117
|
+
$ cf target -s staging <-- changes currently targeted app space to 'staging'
|
118
|
+
|
119
|
+
EOS
|
120
|
+
end
|
121
|
+
|
122
|
+
def wrap_errors
|
123
|
+
yield
|
124
|
+
rescue CFoundry::Timeout => e
|
125
|
+
err(e.message)
|
126
|
+
rescue Interrupt
|
127
|
+
exit_status 130
|
128
|
+
rescue Mothership::Error
|
129
|
+
raise
|
130
|
+
rescue UserError => e
|
131
|
+
log_error(e)
|
132
|
+
err e.message
|
133
|
+
rescue SystemExit
|
134
|
+
raise
|
135
|
+
rescue UserFriendlyError => e
|
136
|
+
err e.message
|
137
|
+
rescue CFoundry::InvalidAuthToken => e
|
138
|
+
line
|
139
|
+
line c("Invalid authentication token. Try logging in again with 'truck login'. If problems continue, please contact your Cloud Operator.", :warning)
|
140
|
+
rescue CFoundry::Forbidden => e
|
141
|
+
if !$cf_asked_auth
|
142
|
+
$cf_asked_auth = true
|
143
|
+
|
144
|
+
line
|
145
|
+
line c("Not authenticated! Try logging in:", :warning)
|
146
|
+
|
147
|
+
# TODO: there's no color here; global flags not being passed
|
148
|
+
# through (mothership bug?)
|
149
|
+
invoke :login
|
150
|
+
|
151
|
+
retry
|
152
|
+
end
|
153
|
+
|
154
|
+
log_error(e)
|
155
|
+
|
156
|
+
err "Denied: #{e.description}"
|
157
|
+
rescue CFoundry::StagingError => e
|
158
|
+
message = "Application failed to stage"
|
159
|
+
formatted_exception_output(e, message)
|
160
|
+
rescue CFoundry::APIError => e
|
161
|
+
formatted_exception_output(e, add_exception_name_to_msg(e))
|
162
|
+
rescue Exception => e
|
163
|
+
log_error_and_dump_crashlog(e)
|
164
|
+
end
|
165
|
+
|
166
|
+
def log_error_and_dump_crashlog(e)
|
167
|
+
log_error(e)
|
168
|
+
err File.open(File.expand_path(CF::CRASH_FILE)).readlines.join("")
|
169
|
+
|
170
|
+
raise if debug?
|
171
|
+
end
|
172
|
+
|
173
|
+
def formatted_exception_output(e, msg)
|
174
|
+
log_error(e)
|
175
|
+
err msg
|
176
|
+
|
177
|
+
raise if debug?
|
178
|
+
end
|
179
|
+
|
180
|
+
def add_exception_name_to_msg(e)
|
181
|
+
msg = e.class.name
|
182
|
+
msg << ": #{e}" unless e.to_s.empty?
|
183
|
+
msg
|
184
|
+
end
|
185
|
+
|
186
|
+
def execute(cmd, argv, global = {})
|
187
|
+
if input[:help]
|
188
|
+
invoke :help, :command => cmd.name.to_s
|
189
|
+
else
|
190
|
+
wrap_errors do
|
191
|
+
@command = cmd
|
192
|
+
precondition if respond_to? :precondition
|
193
|
+
|
194
|
+
save_token_if_it_changes do
|
195
|
+
super
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def save_token_if_it_changes
|
202
|
+
return yield unless client && client.token
|
203
|
+
|
204
|
+
before_token = client.token
|
205
|
+
|
206
|
+
yield
|
207
|
+
|
208
|
+
after_token = client.token
|
209
|
+
|
210
|
+
return unless after_token
|
211
|
+
|
212
|
+
if before_token != after_token
|
213
|
+
info = target_info
|
214
|
+
info[:token] = after_token.auth_header
|
215
|
+
save_target_info(info)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def log_error(e)
|
220
|
+
ensure_config_dir
|
221
|
+
|
222
|
+
msg = e.class.name
|
223
|
+
msg << ": #{e}" unless e.to_s.empty?
|
224
|
+
|
225
|
+
crash_file = File.expand_path(CF::CRASH_FILE)
|
226
|
+
|
227
|
+
FileUtils.mkdir_p(File.dirname(crash_file))
|
228
|
+
|
229
|
+
File.open(crash_file, "w") do |f|
|
230
|
+
f.puts "Time of crash:"
|
231
|
+
f.puts " #{Time.now}"
|
232
|
+
f.puts ""
|
233
|
+
f.puts msg
|
234
|
+
f.puts ""
|
235
|
+
|
236
|
+
if e.respond_to?(:request_trace)
|
237
|
+
f.puts "<<<"
|
238
|
+
f.puts e.request_trace
|
239
|
+
end
|
240
|
+
|
241
|
+
if e.respond_to?(:response_trace)
|
242
|
+
f.puts e.response_trace
|
243
|
+
f.puts ">>>"
|
244
|
+
f.puts ""
|
245
|
+
end
|
246
|
+
|
247
|
+
cf_dir = File.expand_path("../../../..", __FILE__) + "/"
|
248
|
+
e.backtrace.each do |loc|
|
249
|
+
if loc =~ /\/gems\//
|
250
|
+
f.puts loc.sub(/.*\/gems\//, "")
|
251
|
+
else
|
252
|
+
f.puts loc.sub(cf_dir, "")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def quiet?
|
259
|
+
input[:quiet]
|
260
|
+
end
|
261
|
+
|
262
|
+
def force?
|
263
|
+
input[:force]
|
264
|
+
end
|
265
|
+
|
266
|
+
def debug?
|
267
|
+
!!input[:debug]
|
268
|
+
end
|
269
|
+
|
270
|
+
def color_enabled?
|
271
|
+
input[:color]
|
272
|
+
end
|
273
|
+
|
274
|
+
def verbose?
|
275
|
+
input[:verbose]
|
276
|
+
end
|
277
|
+
|
278
|
+
def user_colors
|
279
|
+
return @user_colors if @user_colors
|
280
|
+
|
281
|
+
colors = File.expand_path(COLORS_FILE)
|
282
|
+
|
283
|
+
@user_colors = super.dup
|
284
|
+
|
285
|
+
# most terminal schemes are stupid, so use cyan instead
|
286
|
+
@user_colors.each do |k, v|
|
287
|
+
if v == :blue
|
288
|
+
@user_colors[k] = :cyan
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
if File.exists?(colors)
|
293
|
+
YAML.load_file(colors).each do |k, v|
|
294
|
+
@user_colors[k.to_sym] = v.to_sym
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
@user_colors
|
299
|
+
end
|
300
|
+
|
301
|
+
def err(msg, status = 1)
|
302
|
+
$stderr.puts c(msg, :error)
|
303
|
+
exit_status status
|
304
|
+
end
|
305
|
+
|
306
|
+
def fail(msg)
|
307
|
+
raise UserError, msg
|
308
|
+
end
|
309
|
+
|
310
|
+
def table(headers, rows)
|
311
|
+
tabular(
|
312
|
+
!quiet? && headers.collect { |h| h && b(h) },
|
313
|
+
*rows)
|
314
|
+
end
|
315
|
+
|
316
|
+
def name_list(xs)
|
317
|
+
if xs.empty?
|
318
|
+
d("none")
|
319
|
+
else
|
320
|
+
xs.collect { |x| c(x.name, :name) }.join(", ")
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def sane_target_url(url)
|
325
|
+
url = "https://#{url}" if url !~ /^http/
|
326
|
+
url.gsub(/\/$/, "")
|
327
|
+
end
|
328
|
+
|
329
|
+
def one_of(*paths)
|
330
|
+
paths.each do |p|
|
331
|
+
exp = File.expand_path(p)
|
332
|
+
return exp if File.exist? exp
|
333
|
+
end
|
334
|
+
|
335
|
+
File.expand_path(paths.first)
|
336
|
+
end
|
337
|
+
|
338
|
+
def client_target
|
339
|
+
return File.read(target_file).chomp if File.exists?(target_file)
|
340
|
+
end
|
341
|
+
|
342
|
+
def ensure_config_dir
|
343
|
+
config = File.expand_path(CF::CONFIG_DIR)
|
344
|
+
FileUtils.mkdir_p(config) unless File.exist? config
|
345
|
+
end
|
346
|
+
|
347
|
+
def set_target(url)
|
348
|
+
ensure_config_dir
|
349
|
+
|
350
|
+
File.open(File.expand_path(CF::TARGET_FILE), "w") do |f|
|
351
|
+
f.write(url)
|
352
|
+
end
|
353
|
+
|
354
|
+
invalidate_client
|
355
|
+
end
|
356
|
+
|
357
|
+
def targets_info
|
358
|
+
new_toks = File.expand_path(CF::TOKENS_FILE)
|
359
|
+
|
360
|
+
info =
|
361
|
+
if File.exist? new_toks
|
362
|
+
YAML.load_file(new_toks)
|
363
|
+
end
|
364
|
+
|
365
|
+
info ||= {}
|
366
|
+
|
367
|
+
normalize_targets_info(info)
|
368
|
+
end
|
369
|
+
|
370
|
+
def normalize_targets_info(info_by_url)
|
371
|
+
info_by_url.reduce({}) do |hash, pair|
|
372
|
+
key, value = pair
|
373
|
+
hash[key] = value.is_a?(String) ? { :token => value } : value
|
374
|
+
hash
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def target_info(target = client_target)
|
379
|
+
targets_info[target] || {}
|
380
|
+
end
|
381
|
+
|
382
|
+
def save_targets(ts)
|
383
|
+
ensure_config_dir
|
384
|
+
|
385
|
+
File.open(File.expand_path(CF::TOKENS_FILE), "w") do |io|
|
386
|
+
YAML.dump(ts, io)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
def save_target_info(info, target = client_target)
|
391
|
+
ts = targets_info
|
392
|
+
ts[target] = info
|
393
|
+
save_targets(ts)
|
394
|
+
end
|
395
|
+
|
396
|
+
def remove_target_info(target = client_target)
|
397
|
+
ts = targets_info
|
398
|
+
ts.delete target
|
399
|
+
save_targets(ts)
|
400
|
+
end
|
401
|
+
|
402
|
+
def invalidate_client
|
403
|
+
@@client = nil
|
404
|
+
client
|
405
|
+
end
|
406
|
+
|
407
|
+
def client(target = client_target)
|
408
|
+
return @@client if defined?(@@client) && @@client
|
409
|
+
return unless target
|
410
|
+
|
411
|
+
info = target_info(target)
|
412
|
+
token = info[:token] && CFoundry::AuthToken.from_hash(info)
|
413
|
+
|
414
|
+
fail "V1 targets are no longer supported." if info[:version] == 1
|
415
|
+
|
416
|
+
@@client = build_client(target, token)
|
417
|
+
|
418
|
+
@@client.trace = input[:trace]
|
419
|
+
|
420
|
+
uri = URI.parse(target)
|
421
|
+
@@client.log = File.expand_path("#{LOGS_DIR}/#{uri.host}.log")
|
422
|
+
|
423
|
+
unless info.key? :version
|
424
|
+
info[:version] = @@client.version
|
425
|
+
save_target_info(info, target)
|
426
|
+
end
|
427
|
+
|
428
|
+
@@client.current_organization = @@client.organization(info[:organization]) if info[:organization]
|
429
|
+
@@client.current_space = @@client.space(info[:space]) if info[:space]
|
430
|
+
|
431
|
+
@@client
|
432
|
+
rescue CFoundry::InvalidTarget
|
433
|
+
end
|
434
|
+
|
435
|
+
def build_client(target, token = nil)
|
436
|
+
client = CFoundry::V2::Client.new(target, token)
|
437
|
+
client.http_proxy = input[:http_proxy] || ENV['HTTP_PROXY'] || ENV['http_proxy']
|
438
|
+
client.https_proxy = input[:https_proxy] || ENV['HTTPS_PROXY'] || ENV['https_proxy']
|
439
|
+
client
|
440
|
+
end
|
441
|
+
|
442
|
+
def fail_unknown(display, name)
|
443
|
+
fail("Unknown #{display} '#{name}'.")
|
444
|
+
end
|
445
|
+
|
446
|
+
class << self
|
447
|
+
def client
|
448
|
+
@@client
|
449
|
+
end
|
450
|
+
|
451
|
+
def client=(c)
|
452
|
+
@@client = c
|
453
|
+
end
|
454
|
+
|
455
|
+
private
|
456
|
+
|
457
|
+
def find_by_name(display, &blk)
|
458
|
+
proc { |name, *args|
|
459
|
+
choices, _ = args
|
460
|
+
choices ||= instance_exec(&blk) if block_given?
|
461
|
+
|
462
|
+
choices.find { |c| c.name == name } ||
|
463
|
+
fail_unknown(display, name)
|
464
|
+
}
|
465
|
+
end
|
466
|
+
|
467
|
+
def by_name(what, display = what)
|
468
|
+
proc { |name, *_|
|
469
|
+
client.send(:"#{what}_by_name", name) ||
|
470
|
+
fail_unknown(display, name)
|
471
|
+
}
|
472
|
+
end
|
473
|
+
|
474
|
+
def find_by_name_insensitive(display, &blk)
|
475
|
+
proc { |name, *args|
|
476
|
+
choices, _ = args
|
477
|
+
choices ||= instance_exec(&blk) if block_given?
|
478
|
+
|
479
|
+
choices.find { |c| c.name.upcase == name.upcase } ||
|
480
|
+
fail_unknown(display, name)
|
481
|
+
}
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
private
|
486
|
+
|
487
|
+
def target_file
|
488
|
+
File.expand_path(CF::TARGET_FILE)
|
489
|
+
end
|
490
|
+
|
491
|
+
def tokens_file
|
492
|
+
File.expand_path(CF::TOKENS_FILE)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|