jdc 0.2.1 → 0.2.2.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. data/LICENSE +1277 -24
  2. data/Rakefile +13 -0
  3. data/bin/jdc +12 -2
  4. data/lib/admin/README.md +15 -0
  5. data/lib/admin/curl.rb +60 -0
  6. data/lib/admin/guid.rb +89 -0
  7. data/lib/admin/plugin.rb +6 -0
  8. data/lib/admin/service_auth_token.rb +94 -0
  9. data/lib/admin/service_broker/add.rb +47 -0
  10. data/lib/admin/service_broker/service_brokers.rb +24 -0
  11. data/lib/admin/set_quota.rb +44 -0
  12. data/lib/console/README.md +8 -0
  13. data/lib/console/console.rb +187 -0
  14. data/lib/console/plugin.rb +33 -0
  15. data/lib/jdc.rb +15 -2
  16. data/lib/jdc/cli.rb +556 -0
  17. data/lib/jdc/cli/app/app.rb +43 -0
  18. data/lib/jdc/cli/app/apps.rb +87 -0
  19. data/lib/jdc/cli/app/base.rb +72 -0
  20. data/lib/jdc/cli/app/delete.rb +95 -0
  21. data/lib/jdc/cli/app/deprecated.rb +11 -0
  22. data/lib/jdc/cli/app/env.rb +78 -0
  23. data/lib/jdc/cli/app/events.rb +45 -0
  24. data/lib/jdc/cli/app/files.rb +137 -0
  25. data/lib/jdc/cli/app/health.rb +26 -0
  26. data/lib/jdc/cli/app/instances.rb +53 -0
  27. data/lib/jdc/cli/app/logs.rb +76 -0
  28. data/lib/jdc/cli/app/push.rb +103 -0
  29. data/lib/jdc/cli/app/push/create.rb +108 -0
  30. data/lib/jdc/cli/app/push/interactions.rb +86 -0
  31. data/lib/jdc/cli/app/push/sync.rb +57 -0
  32. data/lib/jdc/cli/app/rename.rb +35 -0
  33. data/lib/jdc/cli/app/restart.rb +31 -0
  34. data/lib/jdc/cli/app/scale.rb +63 -0
  35. data/lib/jdc/cli/app/start.rb +161 -0
  36. data/lib/jdc/cli/app/stats.rb +67 -0
  37. data/lib/jdc/cli/app/stop.rb +27 -0
  38. data/lib/jdc/cli/domain/base.rb +9 -0
  39. data/lib/jdc/cli/domain/domains.rb +40 -0
  40. data/lib/jdc/cli/domain/map.rb +55 -0
  41. data/lib/jdc/cli/domain/unmap.rb +56 -0
  42. data/lib/jdc/cli/help.rb +15 -0
  43. data/lib/jdc/cli/interactive.rb +105 -0
  44. data/lib/jdc/cli/login_requirements.rb +15 -0
  45. data/lib/jdc/cli/organization/base.rb +14 -0
  46. data/lib/jdc/cli/organization/create.rb +37 -0
  47. data/lib/jdc/cli/organization/delete.rb +63 -0
  48. data/lib/jdc/cli/organization/org.rb +45 -0
  49. data/lib/jdc/cli/organization/orgs.rb +30 -0
  50. data/lib/jdc/cli/organization/rename.rb +37 -0
  51. data/lib/jdc/cli/populators/base.rb +16 -0
  52. data/lib/jdc/cli/populators/organization.rb +32 -0
  53. data/lib/jdc/cli/populators/populator_methods.rb +64 -0
  54. data/lib/jdc/cli/populators/space.rb +33 -0
  55. data/lib/jdc/cli/populators/target.rb +13 -0
  56. data/lib/jdc/cli/route/base.rb +9 -0
  57. data/lib/jdc/cli/route/delete.rb +28 -0
  58. data/lib/jdc/cli/route/map.rb +68 -0
  59. data/lib/jdc/cli/route/routes.rb +26 -0
  60. data/lib/jdc/cli/route/unmap.rb +56 -0
  61. data/lib/jdc/cli/service/base.rb +9 -0
  62. data/lib/jdc/cli/service/bind.rb +44 -0
  63. data/lib/jdc/cli/service/create.rb +159 -0
  64. data/lib/jdc/cli/service/delete.rb +83 -0
  65. data/lib/jdc/cli/service/rename.rb +36 -0
  66. data/lib/jdc/cli/service/service.rb +42 -0
  67. data/lib/jdc/cli/service/service_instance_helper.rb +99 -0
  68. data/lib/jdc/cli/service/services.rb +111 -0
  69. data/lib/jdc/cli/service/unbind.rb +37 -0
  70. data/lib/jdc/cli/space/base.rb +29 -0
  71. data/lib/jdc/cli/space/create.rb +67 -0
  72. data/lib/jdc/cli/space/delete.rb +56 -0
  73. data/lib/jdc/cli/space/rename.rb +38 -0
  74. data/lib/jdc/cli/space/space.rb +66 -0
  75. data/lib/jdc/cli/space/spaces.rb +57 -0
  76. data/lib/jdc/cli/space/switch.rb +19 -0
  77. data/lib/jdc/cli/start/base.rb +41 -0
  78. data/lib/jdc/cli/start/colors.rb +13 -0
  79. data/lib/jdc/cli/start/target.rb +50 -0
  80. data/lib/jdc/cli/start/target_prettifier.rb +17 -0
  81. data/lib/jdc/cli/start/targets.rb +16 -0
  82. data/lib/jdc/cli/user/base.rb +30 -0
  83. data/lib/jdc/cli/user/create.rb +52 -0
  84. data/lib/jdc/cli/user/passwd.rb +37 -0
  85. data/lib/jdc/cli/user/register.rb +43 -0
  86. data/lib/jdc/cli/user/users.rb +32 -0
  87. data/lib/jdc/constants.rb +11 -0
  88. data/lib/jdc/errors.rb +19 -0
  89. data/lib/jdc/object_extensions.rb +15 -0
  90. data/lib/jdc/plugin.rb +56 -0
  91. data/lib/jdc/spacing.rb +89 -0
  92. data/lib/jdc/spec_helper.rb +1 -0
  93. data/lib/jdc/test_support.rb +6 -0
  94. data/lib/jdc/version.rb +3 -0
  95. data/lib/manifests/errors.rb +35 -0
  96. data/lib/manifests/loader.rb +31 -0
  97. data/lib/manifests/loader/builder.rb +39 -0
  98. data/lib/manifests/loader/normalizer.rb +145 -0
  99. data/lib/manifests/loader/resolver.rb +79 -0
  100. data/lib/manifests/manifests.rb +344 -0
  101. data/lib/manifests/plugin.rb +140 -0
  102. data/lib/micro/README.md +9 -0
  103. data/lib/micro/errors.rb +4 -0
  104. data/lib/{jdc → micro}/micro.rb +15 -15
  105. data/lib/micro/plugin.rb +197 -0
  106. data/lib/micro/switcher/base.rb +79 -0
  107. data/lib/{jdc/micro → micro}/switcher/darwin.rb +5 -3
  108. data/lib/{jdc/micro → micro}/switcher/dummy.rb +1 -1
  109. data/lib/micro/switcher/linux.rb +16 -0
  110. data/lib/{jdc/micro → micro}/switcher/windows.rb +5 -5
  111. data/lib/{jdc/micro → micro}/vmrun.rb +26 -19
  112. data/lib/tasks/gem_release.rake +42 -0
  113. data/lib/tunnel/README.md +29 -0
  114. data/{config → lib/tunnel/config}/clients.yml +2 -2
  115. data/lib/tunnel/helper-app/Gemfile +10 -0
  116. data/lib/tunnel/helper-app/Gemfile.lock +48 -0
  117. data/{caldecott_helper → lib/tunnel/helper-app}/server.rb +5 -5
  118. data/lib/tunnel/plugin.rb +183 -0
  119. data/lib/tunnel/tunnel.rb +295 -0
  120. metadata +371 -210
  121. data/README.md +0 -102
  122. data/config/micro/paths.yml +0 -22
  123. data/config/micro/refresh_ip.rb +0 -20
  124. data/lib/cli.rb +0 -53
  125. data/lib/cli/commands/admin.rb +0 -58
  126. data/lib/cli/commands/apps.rb +0 -1129
  127. data/lib/cli/commands/base.rb +0 -228
  128. data/lib/cli/commands/manifest.rb +0 -56
  129. data/lib/cli/commands/micro.rb +0 -115
  130. data/lib/cli/commands/misc.rb +0 -126
  131. data/lib/cli/commands/services.rb +0 -178
  132. data/lib/cli/commands/user.rb +0 -14
  133. data/lib/cli/config.rb +0 -173
  134. data/lib/cli/console_helper.rb +0 -170
  135. data/lib/cli/core_ext.rb +0 -122
  136. data/lib/cli/errors.rb +0 -19
  137. data/lib/cli/frameworks.rb +0 -265
  138. data/lib/cli/manifest_helper.rb +0 -300
  139. data/lib/cli/runner.rb +0 -505
  140. data/lib/cli/services_helper.rb +0 -84
  141. data/lib/cli/tunnel_helper.rb +0 -332
  142. data/lib/cli/usage.rb +0 -86
  143. data/lib/cli/version.rb +0 -7
  144. data/lib/cli/zip_util.rb +0 -77
  145. data/lib/jdc/client.rb +0 -457
  146. data/lib/jdc/const.rb +0 -25
  147. data/lib/jdc/micro/switcher/base.rb +0 -97
  148. data/lib/jdc/micro/switcher/linux.rb +0 -16
  149. data/lib/jdc/signature/version.rb +0 -27
  150. data/lib/jdc/signer.rb +0 -13
  151. data/lib/jdc/timer.rb +0 -12
@@ -0,0 +1,30 @@
1
+ require "jdc/cli/organization/base"
2
+
3
+ module JDC::Organization
4
+ class Orgs < Base
5
+ desc "List available organizations"
6
+ group :organizations
7
+ input :full, :desc => "Show full information for apps, services, etc.",
8
+ :default => false
9
+ def orgs
10
+ orgs =
11
+ with_progress("Getting organizations") do
12
+ client.organizations(:depth => 0).sort_by(&:name)
13
+ end
14
+
15
+ return if orgs.empty?
16
+
17
+ line unless quiet?
18
+
19
+ if input[:full]
20
+ orgs.each do |o|
21
+ invoke :org, :organization => o, :full => true
22
+ end
23
+ else
24
+ table(
25
+ %w{name},
26
+ orgs.collect { |o| [c(o.name, :name)] })
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ require "jdc/cli/organization/base"
2
+ =begin
3
+ module JDC::Organization
4
+ class Rename < Base
5
+ desc "Rename an organization"
6
+ group :organizations
7
+ input :organization, :desc => "Organization to rename",
8
+ :aliases => ["--org", "-o"], :argument => :optional,
9
+ :from_given => by_name(:organization)
10
+ input :name, :desc => "New organization name", :argument => :optional
11
+ def rename_org
12
+ organization = input[:organization]
13
+ name = input[:name]
14
+
15
+ organization.name = name
16
+
17
+ with_progress("Renaming to #{c(name, :name)}") do
18
+ organization.update!
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def ask_name
25
+ ask("New name")
26
+ end
27
+
28
+ def ask_organization
29
+ organizations = client.organizations(:depth => 0)
30
+ fail "No organizations." if organizations.empty?
31
+
32
+ ask("Rename which organization?", :choices => organizations.sort_by(&:name),
33
+ :display => proc(&:name))
34
+ end
35
+ end
36
+ end
37
+ =end
@@ -0,0 +1,16 @@
1
+ require "jdc/cli"
2
+
3
+ module JDC
4
+ module Populators
5
+ class Base < JDC::CLI
6
+ include LoginRequirements
7
+
8
+ attr_reader :input, :info
9
+
10
+ def initialize(input)
11
+ @input = input
12
+ @info = target_info
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require "jdc/cli/populators/base"
2
+ require "jdc/cli/populators/populator_methods"
3
+
4
+ module JDC
5
+ module Populators
6
+ class Organization < Base
7
+ include PopulatorMethods
8
+
9
+ def changed
10
+ info[:space] = nil
11
+ end
12
+
13
+ private
14
+
15
+ def choices
16
+ organization_response = client.organizations_first_page(:depth => 0)
17
+ if organization_response[:next_page]
18
+ "Login successful. Too many organizations (>50) to list. Remember to set your target organization using 'target -o [ORGANIZATION]'."
19
+ else
20
+ organization_response[:results]
21
+ end
22
+ end
23
+
24
+ def valid?(organization)
25
+ return false unless organization.guid
26
+ organization.users.include? client.current_user
27
+ rescue JFoundry::APIError
28
+ false
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,64 @@
1
+ module JDC
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 unless obj.nil?
15
+ save_target_info(info)
16
+ invalidate_client
17
+
18
+ obj
19
+ end
20
+
21
+ private
22
+
23
+ def get_object
24
+ previous_object = client.send(type, (info[type])) if info[type]
25
+
26
+ if input.has?(type)
27
+ if respond_to?(:finder_argument, true)
28
+ object = input[type, finder_argument]
29
+ else
30
+ object = input[type]
31
+ end
32
+
33
+ with_progress("Switching to #{type} #{c(object.name, :name)}") {}
34
+ elsif info[type]
35
+ object = previous_object if valid?(previous_object)
36
+ end
37
+
38
+ object ||= prompt_user
39
+
40
+ if (previous_object != object) && respond_to?(:changed, true)
41
+ changed
42
+ end
43
+
44
+ object
45
+ end
46
+
47
+ def prompt_user
48
+ object_choices = choices
49
+
50
+ if object_choices.empty?
51
+ with_progress("There are no #{type}s. You may want to create one with #{c("create-#{type == :organization ? "org" : type}", :good)}.") {}
52
+ elsif object_choices.is_a?(String)
53
+ raise JDC::UserFriendlyError.new(object_choices)
54
+ elsif object_choices.size == 1 && !input.interactive?(type)
55
+ object_choices.first
56
+ else
57
+ ask(type.to_s.capitalize, :choices => object_choices.sort_by(&:name), :display => proc(&:name)).tap do |object|
58
+ with_progress("Switching to #{type} #{c(object.name, :name)}") {}
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,33 @@
1
+ require "jdc/cli/populators/base"
2
+ require "jdc/cli/populators/populator_methods"
3
+
4
+ module JDC
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 JFoundry::APIError
21
+ false
22
+ end
23
+
24
+ def choices
25
+ organization.spaces(:depth => 0)
26
+ end
27
+
28
+ def finder_argument
29
+ organization
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ require "jdc/cli/populators/organization"
2
+ require "jdc/cli/populators/space"
3
+
4
+ module JDC
5
+ module Populators
6
+ class Target < Base
7
+ def populate_and_save!
8
+ organization = JDC::Populators::Organization.new(input).populate_and_save!
9
+ JDC::Populators::Space.new(input, organization).populate_and_save!
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require "jdc/cli"
2
+
3
+ module JDC
4
+ module Route
5
+ class Base < CLI
6
+ include LoginRequirements
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require "jdc/cli/route/base"
2
+
3
+ module JDC::Route
4
+ class Delete < Base
5
+ desc "Delete a route"
6
+ group :routes
7
+ input :route, :desc => "Route to unmap", :argument => true,
8
+ :from_given => find_by_name("route") { client.routes }
9
+ input :really, :type => :boolean, :forget => true, :hidden => true,
10
+ :default => proc { force? || interact }
11
+
12
+ def delete_route
13
+ route = input[:route, client.routes]
14
+
15
+ return unless input[:really, route]
16
+
17
+ with_progress("Deleting route #{c(route.name, :name)}") do
18
+ route.delete!
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def ask_really(route)
25
+ ask("Really delete #{c(route.name, :name)}?", :default => false)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,68 @@
1
+ require "jdc/cli/route/base"
2
+
3
+ module JDC::Route
4
+ class Map < Base
5
+ desc "Add a URL mapping"
6
+ group :apps, :info
7
+ input :app, :desc => "Application to add the URL to",
8
+ :argument => :optional, :from_given => by_name(:app)
9
+ input :host, :desc => "Host name for the route",
10
+ :argument => :optional, :default => ""
11
+ input :domain, :desc => "Domain to add the route to",
12
+ :argument => true,
13
+ :from_given => proc { |name, space|
14
+ space.domain_by_name(name) ||
15
+ fail_unknown("domain", name)
16
+ }
17
+ def map
18
+ app = input[:app]
19
+ space = app.space
20
+
21
+ host = input[:host]
22
+ domain = input[:domain, space]
23
+
24
+ route = find_or_create_route(domain, host, space)
25
+
26
+ bind_route(route, app) if app
27
+ end
28
+
29
+ private
30
+
31
+ def bind_route(route, app)
32
+ with_progress("Binding #{c(route.name, :name)} to #{c(app.name, :name)}") do
33
+ app.add_route(route)
34
+ end
35
+ end
36
+
37
+ def find_or_create_route(domain, host, space)
38
+ find_route(domain, host) || create_route(domain, host, space)
39
+ end
40
+
41
+ def find_route(domain, host)
42
+ client.routes_by_host(host, :depth => 0).find { |r| r.domain == domain }
43
+ end
44
+
45
+ def create_route(domain, host, space)
46
+ route = client.route
47
+ route.host = host
48
+ route.domain = domain
49
+ route.space = space
50
+
51
+ with_progress("Creating route #{c(route.name, :name)}") do
52
+ route.create!
53
+ end
54
+
55
+ route
56
+ end
57
+
58
+ def find_domain(space, name)
59
+ domain = space.domain_by_name(name, :depth => 0)
60
+ fail "Invalid domain '#{name}'" unless domain
61
+ domain
62
+ end
63
+
64
+ def ask_app
65
+ ask("Which application?", :choices => client.apps, :display => proc(&:name))
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,26 @@
1
+ require "jdc/cli/route/base"
2
+
3
+ module JDC::Route
4
+ class Routes < Base
5
+ desc "List routes in a space"
6
+ group :routes
7
+
8
+ def routes
9
+ # TODO: scope to space once space.routes is possible
10
+ routes =
11
+ with_progress("Getting routes") do
12
+ client.routes
13
+ end
14
+
15
+ line unless quiet?
16
+
17
+ table(
18
+ %w{host domain},
19
+ routes.sort_by { |r| "#{r.domain.name} #{r.host}" }.collect { |r|
20
+ [c(r.host, :name),
21
+ r.domain.name
22
+ ]
23
+ })
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ require "jdc/cli/route/base"
2
+
3
+ module JDC::Route
4
+ class Unmap < Base
5
+ desc "Remove a URL mapping"
6
+ group :apps, :info
7
+ input :url, :desc => "URL to unmap", :argument => :optional,
8
+ :from_given => find_by_name("route") { client.routes }
9
+ input :app, :desc => "Application to remove the URL from",
10
+ :argument => :optional, :from_given => by_name(:app)
11
+ input :all, :desc => "Act on all routes", :type => :boolean
12
+ input :really, :type => :boolean, :forget => true, :hidden => true,
13
+ :default => proc { force? || interact }
14
+
15
+ def unmap
16
+ if input[:all]
17
+ if input.has?(:app)
18
+ app = target = input[:app]
19
+ else
20
+ target = client
21
+ end
22
+
23
+ target.routes.each do |r|
24
+ begin
25
+ invoke :unmap, :url => r, :really => true, :app => app
26
+ rescue JFoundry::APIError => e
27
+ err "#{e.class}: #{e.message}"
28
+ end
29
+ end
30
+
31
+ return
32
+ end
33
+
34
+ app = input[:app]
35
+ url = input[:url, app ? app.routes : client.routes]
36
+
37
+ if app
38
+ with_progress("Unbinding #{c(url.name, :name)} from #{c(app.name, :name)}") do
39
+ app.remove_route(url)
40
+ end
41
+ else
42
+ fail "Missing --app."
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def ask_url(choices)
49
+ ask("Which URL?", :choices => choices.sort_by(&:name), :display => proc(&:name))
50
+ end
51
+
52
+ def ask_really(name, color)
53
+ ask("Really delete #{c(name, color)}?", :default => false)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ require "jdc/cli"
2
+
3
+ module JDC
4
+ module Service
5
+ class Base < CLI
6
+ include LoginRequirements
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ require "jdc/cli/service/base"
2
+ =begin
3
+ module JDC::Service
4
+ class Bind < Base
5
+ desc "Bind a service to an application"
6
+ group :services, :manage
7
+ input :service, :desc => "Service to bind", :argument => :optional,
8
+ :from_given => by_name(:service_instance, "service")
9
+ input :app, :desc => "Application to bind to", :argument => :optional,
10
+ :from_given => by_name(:app)
11
+ def bind_service
12
+ app = input[:app]
13
+ service = input[:service, app]
14
+ finalize
15
+
16
+ with_progress(
17
+ "Binding #{c(service.name, :name)} to #{c(app.name, :name)}") do |s|
18
+ if app.binds?(service)
19
+ s.skip do
20
+ err "App #{b(app.name)} already binds #{b(service.name)}."
21
+ end
22
+ else
23
+ app.bind(service)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def ask_service(app)
31
+ services = client.service_instances
32
+ fail "No services." if services.empty?
33
+
34
+ ask "Which service?", :choices => services - app.services,
35
+ :display => proc(&:name)
36
+ end
37
+
38
+ def ask_app
39
+ ask "Which application?", :choices => client.apps,
40
+ :display => proc(&:name)
41
+ end
42
+ end
43
+ end
44
+ =end