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,51 @@
|
|
1
|
+
require "cf/cli/user/base"
|
2
|
+
|
3
|
+
module CF::User
|
4
|
+
class Create < Base
|
5
|
+
desc "Create a user"
|
6
|
+
group :admin, :user
|
7
|
+
input :email, :desc => "User email", :argument => :optional
|
8
|
+
input :password, :desc => "User password"
|
9
|
+
input :verify, :desc => "Repeat password"
|
10
|
+
input :organization, :desc => "User organization",
|
11
|
+
:aliases => %w{--org -o},
|
12
|
+
:default => proc { client.current_organization },
|
13
|
+
:from_given => by_name(:organization)
|
14
|
+
|
15
|
+
def create_user
|
16
|
+
org = CF::Populators::Organization.new(input).populate_and_save!
|
17
|
+
email = input[:email]
|
18
|
+
password = input[:password]
|
19
|
+
|
20
|
+
if !force? && password != input[:verify]
|
21
|
+
fail "Passwords don't match."
|
22
|
+
end
|
23
|
+
|
24
|
+
user = nil
|
25
|
+
with_progress("Creating user") do
|
26
|
+
user = client.register(email, password)
|
27
|
+
end
|
28
|
+
|
29
|
+
with_progress("Adding user to #{org.name}") do
|
30
|
+
user.audited_organizations = user.managed_organizations = user.organizations = [org]
|
31
|
+
user.update!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_command :add_user, :create_user
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def ask_email
|
40
|
+
ask("Email")
|
41
|
+
end
|
42
|
+
|
43
|
+
def ask_password
|
44
|
+
ask("Password", :echo => "*", :forget => true)
|
45
|
+
end
|
46
|
+
|
47
|
+
def ask_verify
|
48
|
+
ask("Verify Password", :echo => "*", :forget => true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "cf/cli/user/base"
|
2
|
+
|
3
|
+
module CF::User
|
4
|
+
class Passwd < Base
|
5
|
+
desc "Update the current user's password"
|
6
|
+
group :admin, :user
|
7
|
+
input :password, :desc => "Current password"
|
8
|
+
input :new_password, :desc => "New password"
|
9
|
+
input :verify, :desc => "Repeat new password"
|
10
|
+
|
11
|
+
def passwd
|
12
|
+
password = input[:password]
|
13
|
+
new_password = input[:new_password]
|
14
|
+
|
15
|
+
validate_password! new_password
|
16
|
+
|
17
|
+
with_progress("Changing password") do
|
18
|
+
client.current_user.change_password!(new_password, password)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def ask_password
|
25
|
+
ask("Current Password", :echo => "*", :forget => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ask_new_password
|
29
|
+
ask("New Password", :echo => "*", :forget => true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ask_verify
|
33
|
+
ask("Verify Password", :echo => "*", :forget => true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "cf/cli/user/base"
|
2
|
+
|
3
|
+
module CF::User
|
4
|
+
class Register < Base
|
5
|
+
def precondition; end
|
6
|
+
|
7
|
+
desc "Create a user and log in"
|
8
|
+
group :admin, :user
|
9
|
+
input :email, :desc => "Desired email", :argument => :optional
|
10
|
+
input :password, :desc => "Desired password"
|
11
|
+
input :verify, :desc => "Repeat password"
|
12
|
+
input :login, :desc => "Automatically log in?", :default => true
|
13
|
+
def register
|
14
|
+
email = input[:email]
|
15
|
+
password = input[:password]
|
16
|
+
|
17
|
+
validate_password!(password)
|
18
|
+
|
19
|
+
with_progress("Creating user") do
|
20
|
+
client.register(email, password)
|
21
|
+
end
|
22
|
+
|
23
|
+
if input[:login]
|
24
|
+
invoke :login, :username => email, :password => password
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def ask_email
|
31
|
+
ask("Email")
|
32
|
+
end
|
33
|
+
|
34
|
+
def ask_password
|
35
|
+
ask("Password", :echo => "*", :forget => true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def ask_verify
|
39
|
+
ask("Confirm Password", :echo => "*", :forget => true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "cf/cli/user/base"
|
2
|
+
|
3
|
+
module CF::User
|
4
|
+
class Users < Base
|
5
|
+
desc "List all users"
|
6
|
+
group :admin
|
7
|
+
def users
|
8
|
+
users =
|
9
|
+
with_progress("Getting users") do
|
10
|
+
client.users(:depth => 0)
|
11
|
+
end
|
12
|
+
|
13
|
+
spaced(users) do |u|
|
14
|
+
display_user(u)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def display_user(u)
|
21
|
+
if quiet?
|
22
|
+
puts u.email
|
23
|
+
else
|
24
|
+
line "#{c(u.email, :name)}:"
|
25
|
+
|
26
|
+
indented do
|
27
|
+
line "admin?: #{c(u.admin?, u.admin? ? :yes : :no)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cf/constants.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module CF
|
2
|
+
CONFIG_DIR = "~/.truck".freeze
|
3
|
+
|
4
|
+
LOGS_DIR = "#{CONFIG_DIR}/logs".freeze
|
5
|
+
PLUGINS_FILE = "#{CONFIG_DIR}/plugins.yml".freeze
|
6
|
+
TARGET_FILE = "#{CONFIG_DIR}/target".freeze
|
7
|
+
TOKENS_FILE = "#{CONFIG_DIR}/tokens.yml".freeze
|
8
|
+
COLORS_FILE = "#{CONFIG_DIR}/colors.yml".freeze
|
9
|
+
CRASH_FILE = "#{CONFIG_DIR}/crash".freeze
|
10
|
+
end
|
data/lib/cf/errors.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module CF
|
2
|
+
class UserFriendlyError < RuntimeError
|
3
|
+
def initialize(msg)
|
4
|
+
@message = msg
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
@message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class UserError < UserFriendlyError; end
|
13
|
+
|
14
|
+
class NotAuthorized < UserError
|
15
|
+
def initialize
|
16
|
+
@message = "Not authorized."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/cf/plugin.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "set"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
require "cf/constants"
|
5
|
+
require "cf/cli"
|
6
|
+
|
7
|
+
module CF
|
8
|
+
module Plugin
|
9
|
+
@@plugins = []
|
10
|
+
|
11
|
+
def self.load_all
|
12
|
+
# auto-load gems with 'cf-plugin' in their name
|
13
|
+
matching =
|
14
|
+
if Gem::Specification.respond_to? :find_all
|
15
|
+
Gem::Specification.find_all do |s|
|
16
|
+
s.name =~ /cf-plugin/
|
17
|
+
end
|
18
|
+
else
|
19
|
+
Gem.source_index.find_name(/cf-plugin/)
|
20
|
+
end
|
21
|
+
|
22
|
+
enabled = Set.new(matching.collect(&:name))
|
23
|
+
|
24
|
+
cf_gems = Gem.loaded_specs["cf"]
|
25
|
+
((cf_gems && cf_gems.dependencies) || Gem.loaded_specs.values).each do |dep|
|
26
|
+
if dep.name =~ /cf-plugin/
|
27
|
+
require "#{dep.name}/plugin"
|
28
|
+
enabled.delete dep.name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# allow explicit enabling/disabling of gems via config
|
33
|
+
plugins = File.expand_path(CF::PLUGINS_FILE)
|
34
|
+
if File.exists?(plugins) && yaml = YAML.load_file(plugins)
|
35
|
+
enabled += yaml["enabled"] if yaml["enabled"]
|
36
|
+
enabled -= yaml["disabled"] if yaml["disabled"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# load up each gem's 'plugin' file
|
40
|
+
#
|
41
|
+
# we require this file specifically so people can require the gem
|
42
|
+
# without it plugging into CF
|
43
|
+
enabled.each do |gemname|
|
44
|
+
begin
|
45
|
+
require "#{gemname}/plugin"
|
46
|
+
rescue Gem::LoadError => e
|
47
|
+
puts "Failed to load #{gemname}:"
|
48
|
+
puts " #{e}"
|
49
|
+
puts
|
50
|
+
puts "You may need to update or remove this plugin."
|
51
|
+
puts
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/cf/spacing.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module CF
|
2
|
+
module Spacing
|
3
|
+
@@indentation = 0
|
4
|
+
|
5
|
+
def indented
|
6
|
+
@@indentation += 1
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
@@indentation -= 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def line(msg = "")
|
13
|
+
return puts "" if msg.empty?
|
14
|
+
|
15
|
+
start_line(msg)
|
16
|
+
puts ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_line(msg)
|
20
|
+
print " " * @@indentation unless quiet?
|
21
|
+
print msg
|
22
|
+
end
|
23
|
+
|
24
|
+
def lines(blob)
|
25
|
+
blob.each_line do |line|
|
26
|
+
start_line(line)
|
27
|
+
end
|
28
|
+
|
29
|
+
line
|
30
|
+
end
|
31
|
+
|
32
|
+
def quiet?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def spaced(vals)
|
37
|
+
num = 0
|
38
|
+
vals.each do |val|
|
39
|
+
line unless quiet? || num == 0
|
40
|
+
yield val
|
41
|
+
num += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def tabular(*rows)
|
46
|
+
spacings = []
|
47
|
+
rows.each do |row|
|
48
|
+
next unless row
|
49
|
+
|
50
|
+
row.each.with_index do |col, i|
|
51
|
+
next unless col
|
52
|
+
|
53
|
+
width = text_width(col)
|
54
|
+
|
55
|
+
if !spacings[i] || width > spacings[i]
|
56
|
+
spacings[i] = width
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
columns = spacings.size
|
62
|
+
rows.each do |row|
|
63
|
+
next unless row
|
64
|
+
|
65
|
+
row.each.with_index do |col, i|
|
66
|
+
next unless col
|
67
|
+
|
68
|
+
start_line justify(col, spacings[i])
|
69
|
+
print " " unless i + 1 == columns
|
70
|
+
end
|
71
|
+
|
72
|
+
line
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def trim_escapes(str)
|
77
|
+
str.gsub(/\e\[\d+m/, "")
|
78
|
+
end
|
79
|
+
|
80
|
+
def text_width(str)
|
81
|
+
trim_escapes(str).size
|
82
|
+
end
|
83
|
+
|
84
|
+
def justify(str, width)
|
85
|
+
trimmed = trim_escapes(str)
|
86
|
+
str.ljust(width + (str.size - trimmed.size))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path("../../../spec/spec_helper", __FILE__)
|
data/lib/cf/version.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/cloudfoundry/console-cf-plugin.png)](https://travis-ci.org/cloudfoundry/console-cf-plugin)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/console-cf-plugin.png)](http://badge.fury.io/rb/console-cf-plugin)
|
3
|
+
|
4
|
+
## Console
|
5
|
+
### Info
|
6
|
+
This plugin lets you connect to a Cloud Foundry application via telnet.
|
7
|
+
|
8
|
+
### Installation
|
9
|
+
```
|
10
|
+
gem install console-cf-plugin
|
11
|
+
```
|
12
|
+
|
13
|
+
### Usage
|
14
|
+
```
|
15
|
+
console APP Open a console connected to your app
|
16
|
+
```
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require "net/telnet"
|
2
|
+
require "readline"
|
3
|
+
|
4
|
+
require "tunnel/tunnel"
|
5
|
+
|
6
|
+
class CFConsole < CFTunnel
|
7
|
+
def initialize(client, app, port = 10000)
|
8
|
+
@client = client
|
9
|
+
@app = app
|
10
|
+
@port = port
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_connection_info(auth)
|
14
|
+
instances = @app.instances
|
15
|
+
if instances.empty?
|
16
|
+
raise "App has no running instances; try starting it."
|
17
|
+
end
|
18
|
+
|
19
|
+
unless console = instances[0].console
|
20
|
+
raise "App does not have console access; try restarting it."
|
21
|
+
end
|
22
|
+
|
23
|
+
{ "hostname" => console[:ip],
|
24
|
+
"port" => console[:port]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_credentials
|
29
|
+
YAML.load(@app.file("app", "cf-rails-console", ".consoleaccess"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def start_console
|
33
|
+
prompt = login
|
34
|
+
|
35
|
+
init_readline
|
36
|
+
|
37
|
+
run_console prompt
|
38
|
+
end
|
39
|
+
|
40
|
+
def login(auth = get_credentials)
|
41
|
+
if !auth["username"] || !auth["password"]
|
42
|
+
raise "Unable to verify console credentials."
|
43
|
+
end
|
44
|
+
|
45
|
+
@telnet = telnet_client
|
46
|
+
|
47
|
+
prompt = nil
|
48
|
+
err_msg = "Login attempt timed out."
|
49
|
+
|
50
|
+
5.times do
|
51
|
+
begin
|
52
|
+
results = @telnet.login(
|
53
|
+
"Name" => auth["username"],
|
54
|
+
"Password" => auth["password"])
|
55
|
+
|
56
|
+
lines = results.sub("Login: Password: ", "").split("\n")
|
57
|
+
|
58
|
+
last_line = lines.pop
|
59
|
+
|
60
|
+
if last_line =~ /[$%#>] \z/n
|
61
|
+
prompt = last_line
|
62
|
+
elsif last_line =~ /Login failed/
|
63
|
+
err_msg = last_line
|
64
|
+
end
|
65
|
+
|
66
|
+
break
|
67
|
+
|
68
|
+
rescue TimeoutError
|
69
|
+
sleep 1
|
70
|
+
|
71
|
+
rescue EOFError
|
72
|
+
# This may happen if we login right after app starts
|
73
|
+
close_console
|
74
|
+
sleep 5
|
75
|
+
@telnet = telnet_client
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
unless prompt
|
80
|
+
close_console
|
81
|
+
raise err_msg
|
82
|
+
end
|
83
|
+
|
84
|
+
prompt
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def init_readline
|
90
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
91
|
+
Readline.basic_word_break_characters= " \t\n`><=;|&{("
|
92
|
+
end
|
93
|
+
|
94
|
+
Readline.completion_append_character = nil
|
95
|
+
|
96
|
+
# Assumes that sending a String ending with tab will return a non-empty
|
97
|
+
# String of comma-separated completion options, terminated by a new line
|
98
|
+
# For example, "app.\t" might result in "to_s,nil?,etc\n"
|
99
|
+
Readline.completion_proc = proc do |s|
|
100
|
+
console_tab_completion_data(s)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def run_console(prompt)
|
105
|
+
prev = trap("INT") { |x| exit_console; prev.call(x); exit }
|
106
|
+
prev = trap("TERM") { |x| exit_console; prev.call(x); exit }
|
107
|
+
|
108
|
+
loop do
|
109
|
+
cmd = readline_with_history(prompt)
|
110
|
+
|
111
|
+
if cmd == nil
|
112
|
+
exit_console
|
113
|
+
break
|
114
|
+
end
|
115
|
+
|
116
|
+
prompt = send_console_command_display_results(cmd, prompt)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def readline_with_history(prompt)
|
121
|
+
line = Readline::readline(prompt)
|
122
|
+
|
123
|
+
return if line == nil || line == 'quit' || line == 'exit'
|
124
|
+
|
125
|
+
if line !~ /^\s*$/ && Readline::HISTORY.to_a.last != line
|
126
|
+
Readline::HISTORY.push(line)
|
127
|
+
end
|
128
|
+
|
129
|
+
line
|
130
|
+
end
|
131
|
+
|
132
|
+
def send_console_command_display_results(cmd, prompt)
|
133
|
+
begin
|
134
|
+
lines = send_console_command cmd
|
135
|
+
|
136
|
+
# Assumes the last line is a prompt
|
137
|
+
prompt = lines.pop
|
138
|
+
|
139
|
+
lines.each do |line|
|
140
|
+
puts line if line != cmd
|
141
|
+
end
|
142
|
+
|
143
|
+
rescue TimeoutError
|
144
|
+
puts "Timed out sending command to server."
|
145
|
+
|
146
|
+
rescue EOFError
|
147
|
+
raise "The console connection has been terminated. Perhaps the app was stopped or deleted?"
|
148
|
+
end
|
149
|
+
|
150
|
+
prompt
|
151
|
+
end
|
152
|
+
|
153
|
+
def send_console_command(cmd)
|
154
|
+
results = @telnet.cmd(cmd)
|
155
|
+
results.split("\n")
|
156
|
+
end
|
157
|
+
|
158
|
+
def exit_console
|
159
|
+
@telnet.cmd("String" => "exit", "Timeout" => 1)
|
160
|
+
rescue TimeoutError
|
161
|
+
# TimeoutError expected, as exit doesn't return anything
|
162
|
+
ensure
|
163
|
+
close_console
|
164
|
+
end
|
165
|
+
|
166
|
+
def close_console
|
167
|
+
@telnet.close
|
168
|
+
end
|
169
|
+
|
170
|
+
def console_tab_completion_data(cmd)
|
171
|
+
begin
|
172
|
+
results = @telnet.
|
173
|
+
cmd("String" => cmd + "\t", "Match" => /\S*\n$/, "Timeout" => 10)
|
174
|
+
results.chomp.split(",")
|
175
|
+
rescue TimeoutError
|
176
|
+
[] #Just return empty results if timeout occurred on tab completion
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def telnet_client
|
181
|
+
Net::Telnet.new(
|
182
|
+
"Port" => @port,
|
183
|
+
"Prompt" => /[$%#>] \z|Login failed/n,
|
184
|
+
"Timeout" => 30,
|
185
|
+
"FailEOF" => true)
|
186
|
+
end
|
187
|
+
end
|