jcf 0.0.9

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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +26 -0
  4. data/CHANGELOG.md +43 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Guardfile +21 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +120 -0
  9. data/Rakefile +167 -0
  10. data/cucumber.yml +1 -0
  11. data/exe/jcf +21 -0
  12. data/lib/.DS_Store +0 -0
  13. data/lib/jcf/.DS_Store +0 -0
  14. data/lib/jcf/aws/cloudwatch.rb +90 -0
  15. data/lib/jcf/cf/.DS_Store +0 -0
  16. data/lib/jcf/cf/base.rb +113 -0
  17. data/lib/jcf/cf/metric.rb +39 -0
  18. data/lib/jcf/cf/organization.rb +10 -0
  19. data/lib/jcf/cf/quota.rb +11 -0
  20. data/lib/jcf/cf/relationships.rb +88 -0
  21. data/lib/jcf/cf/service_broker.rb +10 -0
  22. data/lib/jcf/cf/service_instance.rb +10 -0
  23. data/lib/jcf/cf/service_offering.rb +10 -0
  24. data/lib/jcf/cf/service_plan.rb +10 -0
  25. data/lib/jcf/cf/space.rb +10 -0
  26. data/lib/jcf/cf/user.rb +37 -0
  27. data/lib/jcf/cf.rb +29 -0
  28. data/lib/jcf/cli/command.rb +35 -0
  29. data/lib/jcf/cli/commands/.DS_Store +0 -0
  30. data/lib/jcf/cli/commands/cf/metrics.rb +156 -0
  31. data/lib/jcf/cli/commands/cf/organizations.rb +24 -0
  32. data/lib/jcf/cli/commands/cf/quota.rb +26 -0
  33. data/lib/jcf/cli/commands/cf/service_brokers.rb +30 -0
  34. data/lib/jcf/cli/commands/cf/service_instances.rb +37 -0
  35. data/lib/jcf/cli/commands/cf/service_offerings.rb +26 -0
  36. data/lib/jcf/cli/commands/cf/service_plans.rb +30 -0
  37. data/lib/jcf/cli/commands/cf/spaces.rb +26 -0
  38. data/lib/jcf/cli/commands/cf/users.rb +24 -0
  39. data/lib/jcf/cli/commands/version.rb +16 -0
  40. data/lib/jcf/cli/commands.rb +21 -0
  41. data/lib/jcf/cli/errors.rb +17 -0
  42. data/lib/jcf/cli/output_formatters/csv.rb +35 -0
  43. data/lib/jcf/cli/output_formatters/json.rb +19 -0
  44. data/lib/jcf/cli/output_formatters/text.rb +39 -0
  45. data/lib/jcf/cli/output_formatters.rb +26 -0
  46. data/lib/jcf/cli.rb +53 -0
  47. data/lib/jcf/version.rb +5 -0
  48. data/lib/jcf.rb +9 -0
  49. data/sig/jcf.rbs +4 -0
  50. metadata +327 -0
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require_relative "../../errors"
5
+
6
+ module JCF
7
+ module CLI
8
+ module Commands
9
+ module CF
10
+ class ServiceInstances < Command
11
+ argument :name, required: false, desc: "Service Instance name"
12
+
13
+ option :org, aliases: ["-o", "--org", "--organization"], type: :string, desc: "Filter to an organization guid"
14
+ option :space, aliases: ["-s", "--space"], type: :string, desc: "Filter to a space guid"
15
+ option :service_plan, aliases: ["-p", "--plan", "--service-plan"], type: :string,
16
+ desc: "Filter to a service plan"
17
+
18
+ # rubocop:disable Metrics/MethodLength
19
+ def call(name: nil, **options)
20
+ if name
21
+ out.puts formatter.format(JCF::CF::ServiceInstance.find_by(name: name))
22
+ else
23
+ out.puts formatter.format(
24
+ JCF::CF::ServiceInstance.all(
25
+ organization_guids: options[:org],
26
+ space_guids: options[:space],
27
+ service_plan: options[:service_plan]
28
+ )
29
+ )
30
+ end
31
+ end
32
+ # rubocop:enable Metrics/MethodLength
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require_relative "../../errors"
5
+
6
+ module JCF
7
+ module CLI
8
+ module Commands
9
+ module CF
10
+ class ServiceOfferings < Command
11
+ argument :name, required: false, desc: "Service Offering name"
12
+
13
+ option :org, aliases: ["-o", "--org", "--organization"], type: :string, desc: "Filter to an organization guid"
14
+
15
+ def call(name: nil, **options)
16
+ if name
17
+ out.puts formatter.format(JCF::CF::ServiceOffering.find_by(name: name))
18
+ else
19
+ out.puts formatter.format(JCF::CF::ServiceOffering.all(organization_guids: options[:org]))
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require_relative "../../errors"
5
+
6
+ module JCF
7
+ module CLI
8
+ module Commands
9
+ module CF
10
+ class ServicePlans < Command
11
+ argument :name, required: false, desc: "Service Plan name"
12
+
13
+ option :org, aliases: ["-o", "--org", "--organization"], type: :string, desc: "Filter to an organization"
14
+
15
+ def call(name: nil, **options)
16
+ if name
17
+ out.puts formatter.format(JCF::CF::ServicePlan.find_by(name: name))
18
+ else
19
+ out.puts formatter.format(
20
+ JCF::CF::ServicePlan.all(
21
+ organization_guids: options[:org]
22
+ )
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require_relative "../../errors"
5
+
6
+ module JCF
7
+ module CLI
8
+ module Commands
9
+ module CF
10
+ class Spaces < Command
11
+ argument :name, required: false, desc: "Space name"
12
+
13
+ option :org, aliases: ["-o", "--org", "--organization"], type: :string, desc: "Filter to an organization"
14
+
15
+ def call(name: nil, **options)
16
+ if name
17
+ out.puts formatter.format(JCF::CF::Space.find_by(name: name))
18
+ else
19
+ out.puts formatter.format(JCF::CF::Space.all(organization_guids: options[:org]))
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require_relative "../../errors"
5
+
6
+ module JCF
7
+ module CLI
8
+ module Commands
9
+ module CF
10
+ class Users < Command
11
+ argument :name, required: false, desc: "Partial username"
12
+
13
+ def call(name: nil, **_options)
14
+ if name
15
+ out.puts formatter.format(JCF::CF::User.all(partial_usernames: name))
16
+ else
17
+ out.puts formatter.format(JCF::CF::User.all)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCF
4
+ module CLI
5
+ module Commands
6
+ class Version < Command
7
+ desc "Print JCF app version"
8
+
9
+ def call(*)
10
+ require "jcf/version"
11
+ out.puts "v#{JCF::VERSION}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCF
4
+ module CLI
5
+ module Commands
6
+ end
7
+
8
+ def self.register_commands!
9
+ register "version", Commands::Version, aliases: ["v", "-v", "--version"]
10
+ register "metrics", Commands::CF::Metrics, aliases: ["m"]
11
+
12
+ register "organizations", Commands::CF::Organizations, aliases: %w[o orgs organization]
13
+ register "spaces", Commands::CF::Spaces, aliases: %w[s space]
14
+ register "users", Commands::CF::Users, aliases: %w[u user]
15
+ register "service_brokers", Commands::CF::ServiceBrokers, aliases: %w[sb service_broker]
16
+ register "service_offerings", Commands::CF::ServiceOfferings, aliases: %w[so service_offering]
17
+ register "service_instances", Commands::CF::ServiceInstances, aliases: %w[si service_instance]
18
+ register "service_plans", Commands::CF::ServicePlans, aliases: %w[sp service_plan]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCF
4
+ module CLI
5
+ class Error < StandardError
6
+ end
7
+
8
+ class NotImplementedError < Error
9
+ end
10
+
11
+ class NotLoggedInError < StandardError
12
+ end
13
+
14
+ class InvalidOptionError < StandardError
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+
5
+ module JCF
6
+ module CLI
7
+ module OutputFormatters
8
+ class CSV
9
+ class << self
10
+ def format(data)
11
+ case data
12
+ in Array
13
+ array = data.collect(&:serializable_hash)
14
+ generate_csv(headers: array.first&.keys, values: array)
15
+ in Hash
16
+ generate_csv(headers: data.keys.sort, values: [data.serializable_hash])
17
+ else
18
+ generate_csv(headers: [], values: [])
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def generate_csv(headers:, values:)
25
+ ::CSV.generate(headers: headers, write_headers: true) do |csv|
26
+ values.each do |hash|
27
+ csv << hash.values
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module JCF
6
+ module CLI
7
+ module OutputFormatters
8
+ class JSON
9
+ def self.format(data)
10
+ if data.is_a?(Enumerable)
11
+ ::JSON.generate data.collect(&:serializable_hash)
12
+ else
13
+ ::JSON.generate data.serializable_hash
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-table"
4
+
5
+ module JCF
6
+ module CLI
7
+ module OutputFormatters
8
+ class Text
9
+ class << self
10
+ def format(data)
11
+ return "" if data.nil?
12
+
13
+ keys = collect_keys(data)
14
+ values = collect_values(data)
15
+
16
+ table = TTY::Table.new(keys, values)
17
+ table.render(:unicode, resize: true)
18
+ end
19
+
20
+ def collect_values(data)
21
+ if data.is_a?(Array)
22
+ data.map { |d| d.attributes.values.collect(&:to_s) }
23
+ else
24
+ [data.attributes.values.collect(&:to_s)]
25
+ end
26
+ end
27
+
28
+ def collect_keys(data)
29
+ if data.is_a?(Array)
30
+ data.first&.attributes&.keys || ["Empty result"]
31
+ else
32
+ data.attributes.keys
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCF
4
+ module CLI
5
+ module OutputFormatters
6
+ def self.formatters
7
+ @formatters ||= {}
8
+ end
9
+
10
+ def self.register_formatter(name, formatter)
11
+ formatters[name] = formatter
12
+ end
13
+
14
+ def self.formatter(name)
15
+ formatters[name]
16
+ end
17
+ end
18
+
19
+ def self.register_formatters!
20
+ Dir[File.join(__dir__, "output_formatters", "*.rb")].each { |f| require f }
21
+ OutputFormatters.constants.each do |c|
22
+ OutputFormatters.register_formatter(c.to_s.downcase, OutputFormatters.const_get(c))
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/jcf/cli.rb ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/cli"
4
+ require "zeitwerk"
5
+ require "mini_cache"
6
+ require "active_support/inflector"
7
+
8
+ module JCF
9
+ def self.root
10
+ File.expand_path("..", __dir__)
11
+ end
12
+
13
+ def self.cache
14
+ @cache ||= MiniCache::Store.new
15
+ end
16
+
17
+ module CLI
18
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
19
+ def self.loader
20
+ @loader ||= Zeitwerk::Loader.new.tap do |loader|
21
+ loader.inflector = Zeitwerk::GemInflector.new("#{JCF.root}/jcf.rb")
22
+ loader.push_dir(JCF.root)
23
+ loader.ignore(
24
+ "#{JCF.root}/jcf/cli/{errors,version}.rb"
25
+ )
26
+ loader.inflector.inflect("jcf" => "JCF")
27
+ loader.inflector.inflect("cf" => "CF")
28
+ loader.inflector.inflect("cli" => "CLI")
29
+ loader.inflector.inflect("url" => "URL")
30
+ loader.inflector.inflect("json" => "JSON")
31
+ loader.inflector.inflect("csv" => "CSV")
32
+ loader.inflector.inflect("aws" => "AWS")
33
+ end
34
+ end
35
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
36
+
37
+ loader.setup
38
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
39
+ inflect.irregular "quota", "quotas"
40
+ end
41
+
42
+ require_relative "cli/output_formatters"
43
+ require_relative "cli/commands"
44
+ require_relative "cli/errors"
45
+ # require_relative "cf.rb"
46
+ require_relative "aws/cloudwatch"
47
+
48
+ extend Dry::CLI::Registry
49
+
50
+ register_formatters!
51
+ register_commands!
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCF
4
+ VERSION = "0.0.9"
5
+ end
data/lib/jcf.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jcf/version"
4
+ require_relative "jcf/cli"
5
+ require "fileutils"
6
+
7
+ module JCF
8
+ class Error < StandardError; end
9
+ end
data/sig/jcf.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Jcf
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end