cf 0.6.1.rc3 → 0.6.1.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/lib/cf/cli.rb +6 -3
  2. data/lib/cf/cli/populators/base.rb +14 -0
  3. data/lib/cf/cli/populators/organization.rb +23 -0
  4. data/lib/cf/cli/populators/populator_methods.rb +52 -0
  5. data/lib/cf/cli/populators/space.rb +29 -0
  6. data/lib/cf/cli/populators/target.rb +13 -0
  7. data/lib/cf/cli/service/services.rb +5 -2
  8. data/lib/cf/cli/space/base.rb +6 -0
  9. data/lib/cf/cli/space/spaces.rb +46 -44
  10. data/lib/cf/cli/start/base.rb +7 -56
  11. data/lib/cf/cli/start/login.rb +3 -8
  12. data/lib/cf/cli/start/target.rb +5 -9
  13. data/lib/cf/version.rb +1 -1
  14. data/spec/assets/hello-sinatra/main.rb +5 -3
  15. data/spec/cf/cli/app/scale_spec.rb +5 -1
  16. data/spec/cf/cli/app/start_spec.rb +5 -1
  17. data/spec/cf/cli/domain/map_spec.rb +5 -1
  18. data/spec/cf/cli/domain/unmap_spec.rb +5 -1
  19. data/spec/cf/cli/organization/orgs_spec.rb +1 -1
  20. data/spec/cf/cli/populators/organization_spec.rb +130 -0
  21. data/spec/cf/cli/populators/space_spec.rb +131 -0
  22. data/spec/cf/cli/populators/target_spec.rb +18 -0
  23. data/spec/cf/cli/route/map_spec.rb +5 -1
  24. data/spec/cf/cli/route/unmap_spec.rb +5 -1
  25. data/spec/cf/cli/service/services_spec.rb +72 -0
  26. data/spec/cf/cli/space/create_spec.rb +24 -7
  27. data/spec/cf/cli/space/rename_spec.rb +16 -5
  28. data/spec/cf/cli/space/spaces_spec.rb +12 -2
  29. data/spec/cf/cli/space/switch_space_spec.rb +18 -3
  30. data/spec/cf/cli/start/login_spec.rb +28 -81
  31. data/spec/cf/cli/start/target_spec.rb +33 -32
  32. data/spec/cf/cli/user/register_spec.rb +5 -1
  33. data/spec/cf/cli_spec.rb +21 -1
  34. data/spec/features/account_lifecycle_spec.rb +8 -3
  35. data/spec/features/login_spec.rb +16 -11
  36. data/spec/features/push_flow_spec.rb +26 -11
  37. data/spec/features/switching_targets_spec.rb +42 -2
  38. data/spec/spec_helper.rb +1 -1
  39. data/spec/support/{command_helper.rb → cli_helper.rb} +18 -25
  40. data/spec/support/shared_examples/populate_organization.rb +6 -0
  41. metadata +20 -6
  42. data/lib/cf/cli/start/target_interactions.rb +0 -37
@@ -86,11 +86,11 @@ module CF
86
86
  check_logged_in
87
87
 
88
88
  unless client.current_organization
89
- fail "Please select an organization with 'cf target --ask-org'."
89
+ fail "Please select an organization with 'cf target --organization ORGANIZATION_NAME'. (Get organization names from 'cf orgs'.)"
90
90
  end
91
91
 
92
92
  unless client.current_space
93
- fail "Please select a space with 'cf target --ask-space'."
93
+ fail "Please select a space with 'cf target --space SPACE_NAME'. (Get space names from 'cf spaces'.)"
94
94
  end
95
95
  end
96
96
 
@@ -109,7 +109,10 @@ module CF
109
109
  raise
110
110
  rescue UserFriendlyError => e
111
111
  err e.message
112
- rescue CFoundry::Forbidden, CFoundry::InvalidAuthToken => e
112
+ rescue CFoundry::InvalidAuthToken => e
113
+ line
114
+ line c("Invalid authentication token. Try logging in again with 'cf login'", :warning)
115
+ rescue CFoundry::Forbidden => e
113
116
  if !$cf_asked_auth
114
117
  $cf_asked_auth = true
115
118
 
@@ -0,0 +1,14 @@
1
+ require "cf/cli"
2
+
3
+ module CF
4
+ module Populators
5
+ class Base < CF::CLI
6
+ attr_reader :input, :info
7
+
8
+ def initialize(input)
9
+ @input = input
10
+ @info = target_info
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require "cf/cli/populators/base"
2
+ require "cf/cli/populators/populator_methods"
3
+
4
+ module CF
5
+ module Populators
6
+ class Organization < Base
7
+ include PopulatorMethods
8
+
9
+ private
10
+
11
+ def choices
12
+ client.organizations(:depth => 0)
13
+ end
14
+
15
+ def valid?(organization)
16
+ return false unless organization.guid
17
+ organization.users.include? client.current_user
18
+ rescue CFoundry::APIError
19
+ false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ module CF
2
+ module Populators
3
+ module PopulatorMethods
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ define_method(:type) do
7
+ klass.name.split("::").last.downcase.to_sym
8
+ end
9
+ end
10
+ end
11
+
12
+ def populate_and_save!
13
+ obj = get_object
14
+ info[type] = obj.guid
15
+ save_target_info(info)
16
+ invalidate_client
17
+
18
+ obj
19
+ end
20
+
21
+ private
22
+
23
+ def get_object
24
+ if input.has?(type)
25
+ object = input[type]
26
+ with_progress("Switching to #{type} #{c(object.name, :name)}") {}
27
+ elsif info[type]
28
+ previous_object = client.send(type, (info[type]))
29
+ object = previous_object if valid?(previous_object)
30
+ end
31
+
32
+ object || prompt_user
33
+ end
34
+
35
+ def prompt_user
36
+ object_choices = choices
37
+
38
+ if object_choices.empty?
39
+ raise CF::UserFriendlyError.new(
40
+ "There are no #{type}s. You may want to create one with #{c("create-#{type}", :good)}."
41
+ )
42
+ elsif object_choices.size == 1 && !input.interactive?(type)
43
+ object_choices.first
44
+ else
45
+ ask(type.to_s.capitalize, :choices => object_choices.sort_by(&:name), :display => proc(&:name)).tap do |object|
46
+ with_progress("Switching to #{type} #{c(object.name, :name)}") {}
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,29 @@
1
+ require "cf/cli/populators/base"
2
+ require "cf/cli/populators/populator_methods"
3
+
4
+ module CF
5
+ module Populators
6
+ class Space < Base
7
+ attr_reader :organization
8
+ include PopulatorMethods
9
+
10
+ def initialize(input, organization)
11
+ super(input)
12
+ @organization = organization
13
+ end
14
+
15
+ private
16
+
17
+ def valid?(space)
18
+ return false unless space.guid
19
+ space.developers.include? client.current_user
20
+ rescue CFoundry::APIError
21
+ false
22
+ end
23
+
24
+ def choices
25
+ organization.spaces(:depth => 0)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require "cf/cli/populators/organization"
2
+ require "cf/cli/populators/space"
3
+
4
+ module CF
5
+ module Populators
6
+ class Target < Base
7
+ def populate_and_save!
8
+ organization = CF::Populators::Organization.new(input).populate_and_save!
9
+ CF::Populators::Space.new(input, organization).populate_and_save!
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,7 +2,7 @@ require "cf/cli/service/base"
2
2
 
3
3
  module CF::Service
4
4
  class Services < Base
5
- desc "List your service"
5
+ desc "List your services"
6
6
  group :services
7
7
  input :space, :desc => "Show services in given space",
8
8
  :from_given => by_name(:space),
@@ -15,6 +15,7 @@ module CF::Service
15
15
  input :app, :desc => "Limit to application's service bindings",
16
16
  :from_given => by_name(:app)
17
17
  input :full, :desc => "Verbose output format", :default => false
18
+
18
19
  def services
19
20
  msg =
20
21
  if space = input[:space]
@@ -45,7 +46,7 @@ module CF::Service
45
46
  end
46
47
  else
47
48
  table(
48
- ["name", "service", "version", "plan", "bound apps"],
49
+ ["name", "service", "provider", "version", "plan", "bound apps"],
49
50
  services.collect { |i|
50
51
  plan = i.service_plan
51
52
  service = plan.service
@@ -53,9 +54,11 @@ module CF::Service
53
54
  label = service.label
54
55
  version = service.version
55
56
  apps = name_list(i.service_bindings.collect(&:app))
57
+ provider = service.provider
56
58
 
57
59
  [ c(i.name, :name),
58
60
  label,
61
+ provider,
59
62
  version,
60
63
  plan.name,
61
64
  apps
@@ -1,4 +1,5 @@
1
1
  require "cf/cli"
2
+ require "cf/cli/populators/organization"
2
3
 
3
4
  module CF
4
5
  module Space
@@ -6,6 +7,11 @@ module CF
6
7
  def precondition
7
8
  check_target
8
9
  check_logged_in
10
+ check_organization
11
+ end
12
+
13
+ def check_organization
14
+ CF::Populators::Organization.new(input).populate_and_save!
9
15
  end
10
16
 
11
17
  def self.space_by_name
@@ -1,55 +1,57 @@
1
1
  require "cf/cli/space/base"
2
2
 
3
- module CF::Space
4
- class Spaces < Base
5
- desc "List spaces in an organization"
6
- group :spaces
7
- input :organization, :desc => "Organization to list spaces from",
8
- :aliases => %w{--org -o}, :argument => :optional,
9
- :from_given => by_name(:organization),
10
- :default => proc { client.current_organization }
11
- input :name, :desc => "Filter by name"
12
- input :full, :desc => "Show full information for apps, services, etc.",
13
- :default => false
14
- def spaces
15
- org = input[:organization]
16
- spaces =
17
- with_progress("Getting spaces in #{c(org.name, :name)}") do
18
- org.spaces(:depth => quiet? ? 0 : 1).sort_by(&:name)
3
+ module CF
4
+ module Space
5
+ class Spaces < Base
6
+ desc "List spaces in an organization"
7
+ group :spaces
8
+ input :organization, :desc => "Organization to list spaces from",
9
+ :aliases => %w{--org -o}, :argument => :optional,
10
+ :from_given => by_name(:organization),
11
+ :default => proc { client.current_organization }
12
+ input :name, :desc => "Filter by name"
13
+ input :full, :desc => "Show full information for apps, services, etc.",
14
+ :default => false
15
+ def spaces
16
+ org = input[:organization]
17
+ spaces =
18
+ with_progress("Getting spaces in #{c(org.name, :name)}") do
19
+ org.spaces(:depth => quiet? ? 0 : 1).sort_by(&:name)
20
+ end
21
+
22
+ return if spaces.empty?
23
+
24
+ line unless quiet?
25
+
26
+ spaces.reject! do |s|
27
+ !space_matches?(s, input)
19
28
  end
20
29
 
21
- return if spaces.empty?
22
-
23
- line unless quiet?
24
-
25
- spaces.reject! do |s|
26
- !space_matches?(s, input)
27
- end
28
-
29
- if input[:full]
30
- spaced(spaces) do |s|
31
- invoke :space, :space => s, :full => input[:full]
30
+ if input[:full]
31
+ spaced(spaces) do |s|
32
+ invoke :space, :space => s, :full => input[:full]
33
+ end
34
+ else
35
+ table(
36
+ %w{name apps services},
37
+ spaces.collect { |s|
38
+ [c(s.name, :name),
39
+ name_list(s.apps),
40
+ name_list(s.service_instances)
41
+ ]
42
+ })
32
43
  end
33
- else
34
- table(
35
- %w{name apps services},
36
- spaces.collect { |s|
37
- [ c(s.name, :name),
38
- name_list(s.apps),
39
- name_list(s.service_instances)
40
- ]
41
- })
42
44
  end
43
- end
44
45
 
45
- private
46
+ private
46
47
 
47
- def space_matches?(s, options)
48
- if name = options[:name]
49
- return false if s.name !~ /#{name}/
50
- end
48
+ def space_matches?(s, options)
49
+ if name = options[:name]
50
+ return false if s.name !~ /#{name}/
51
+ end
51
52
 
52
- true
53
+ true
54
+ end
53
55
  end
54
56
  end
55
- end
57
+ end
@@ -12,7 +12,8 @@ module CF
12
12
 
13
13
 
14
14
  # These commands don't require authentication.
15
- def precondition; end
15
+ def precondition;
16
+ end
16
17
 
17
18
  private
18
19
 
@@ -27,67 +28,17 @@ module CF
27
28
  end
28
29
 
29
30
  def display_target
31
+ if client.nil?
32
+ fail "No target has been specified."
33
+ return
34
+ end
35
+
30
36
  if quiet?
31
37
  line client.target
32
38
  else
33
39
  line "target: #{c(client.target, :name)}"
34
40
  end
35
41
  end
36
-
37
- def select_org(input, info)
38
- if input.has?(:organization) || !org_valid?(info[:organization])
39
- org = input[:organization]
40
- if org
41
- with_progress("Switching to organization #{c(org.name, :name)}") {}
42
- client.current_organization = org
43
- end
44
- info[:organization] = org ? org.guid : nil
45
- !!org
46
- else
47
- info[:organization] = nil
48
- client.current_organization = nil
49
- false
50
- end
51
- end
52
-
53
- def select_space(input, info, changed_org)
54
- if input.has?(:space) || !space_valid?(info[:space])
55
- line if changed_org && !quiet?
56
- space = input[:space, client.current_organization]
57
- if space
58
- with_progress("Switching to space #{c(space.name, :name)}") {}
59
- client.current_space = space
60
- end
61
- info[:space] = space ? space.guid : nil
62
- else
63
- info[:space] = nil
64
- client.current_space = nil
65
- end
66
- end
67
-
68
- def select_org_and_space(input, info)
69
- changed_org = select_org(input, info)
70
- if client.current_organization
71
- select_space(input, info, changed_org)
72
- else
73
- info[:space] = nil
74
- client.current_space = nil
75
- end
76
- end
77
-
78
- def org_valid?(guid, user = client.current_user)
79
- return false unless guid
80
- client.organization(guid).users.include? user
81
- rescue CFoundry::APIError
82
- false
83
- end
84
-
85
- def space_valid?(guid, user = client.current_user)
86
- return false unless guid
87
- client.space(guid).developers.include? user
88
- rescue CFoundry::APIError
89
- false
90
- end
91
42
  end
92
43
  end
93
44
  end
@@ -1,5 +1,5 @@
1
1
  require "cf/cli/start/base"
2
- require "cf/cli/start/target_interactions"
2
+ require "cf/cli/populators/target"
3
3
 
4
4
  module CF::Start
5
5
  class Login < Base
@@ -16,14 +16,10 @@ module CF::Start
16
16
  :from_given => by_name(:organization)
17
17
  input :space, :desc => "Space", :alias => "-s",
18
18
  :from_given => by_name(:space)
19
- interactions TargetInteractions
20
19
  def login
21
20
  show_context
22
21
 
23
- credentials =
24
- { :username => input[:username],
25
- :password => input[:password]
26
- }
22
+ credentials = { :username => input[:username], :password => input[:password] }
27
23
 
28
24
  prompts = client.login_prompts
29
25
 
@@ -67,9 +63,8 @@ module CF::Start
67
63
  invalidate_client
68
64
 
69
65
  line if input.interactive?(:organization) || input.interactive?(:space)
70
- select_org_and_space(input, info)
71
66
 
72
- save_target_info(info)
67
+ CF::Populators::Target.new(input).populate_and_save!
73
68
  ensure
74
69
  exit_status 1 if not authenticated
75
70
  end
@@ -1,5 +1,5 @@
1
1
  require "cf/cli/start/base"
2
- require "cf/cli/start/target_interactions"
2
+ require "cf/cli/populators/target"
3
3
 
4
4
  module CF::Start
5
5
  class Target < Base
@@ -10,7 +10,7 @@ module CF::Start
10
10
  :from_given => by_name(:organization)
11
11
  input :space, :desc => "Space", :alias => "-s",
12
12
  :from_given => by_name(:space)
13
- interactions TargetInteractions
13
+
14
14
  def target
15
15
  unless input.has?(:url) || input.has?(:organization) || \
16
16
  input.has?(:space)
@@ -37,11 +37,7 @@ module CF::Start
37
37
  return unless client.logged_in?
38
38
 
39
39
  if input.has?(:organization) || input.has?(:space)
40
- info = target_info
41
-
42
- select_org_and_space(input, info)
43
-
44
- save_target_info(info)
40
+ CF::Populators::Target.new(input).populate_and_save!
45
41
  end
46
42
 
47
43
  return if quiet?
@@ -56,11 +52,11 @@ module CF::Start
56
52
  private
57
53
 
58
54
  def display_org_and_space
59
- if org = client.current_organization
55
+ if (org = client.current_organization)
60
56
  line "organization: #{c(org.name, :name)}"
61
57
  end
62
58
 
63
- if space = client.current_space
59
+ if (space = client.current_space)
64
60
  line "space: #{c(space.name, :name)}"
65
61
  end
66
62
  rescue CFoundry::APIError