zilla 0.2.1 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42000f50525f6778f9716b61a752ca838f2b273cb1d32e25f66ce25d37f298ac
4
- data.tar.gz: fa89ba54836a145629ceefa5ce2619cf4c2d7df4c66f7989b1ae56af371c4b5d
3
+ metadata.gz: 37772f0d8cd6098d9f0b6dbd6e9fee49d5cb76ebdd3e02f7ceec7caba65727cd
4
+ data.tar.gz: d35e2a75c7813fde9a97f5a655a29175d4e0b28b69ab381bafc67e0c6f39603f
5
5
  SHA512:
6
- metadata.gz: 2c12636b69c39827d5841cd700cab021bce42df00000a9fd4d64c38edaf451184ea4fa2f565bd73fddcfcca9034ec13729cc2a94d47f3a3393b0caf1b6477249
7
- data.tar.gz: 53dc9ced782088c1f1bca4bfd9111e50bbc5b720b7c8ebc39e0d37aa0530987f36d606add9a1dfd4f5cad89b4b5cad2fc9ba2611b8cf4b3a8844ddd129a05d5d
6
+ metadata.gz: 52e8973e70df7169a4c2bbe211a490cb1871c45620e0e08cf89f47aed53a313ffb17b9d9e23ef2696f655ab8627483a1f1234941b9fafa2e227266abb2ad1c58
7
+ data.tar.gz: 26988b9409281f1d5a79382b86c0e5d3cf6c041caa262d7ddd52cf129dc0502856bdc8bb70f6bf56f0c1418777d6bce1ba4913cbd4458118394cc42fc935111e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zilla (0.2.1)
4
+ zilla (0.2.3)
5
5
  faraday (>= 1.0.1, < 3.0)
6
6
  faraday-multipart (~> 1.0.0)
7
7
 
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zilla
4
+ def self.const_missing(name)
5
+ require "zilla/models/#{name.to_s.underscore}"
6
+ Zilla.const_get(name)
7
+ end
8
+
9
+ class Kubernetes
10
+ SERVICE_ACCOUNT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount'
11
+
12
+ TOKEN_PATH = "#{SERVICE_ACCOUNT_PATH}/token".freeze
13
+ CERT_PATH = "#{SERVICE_ACCOUNT_PATH}/ca.crt".freeze
14
+ NAMESPACE_PATH = "#{SERVICE_ACCOUNT_PATH}/namespace".freeze
15
+
16
+ # https://github.com/rails/rails/blob/7-0-stable/activesupport/lib/active_support/inflector/methods.rb#LL96-L104C8
17
+ def self._underscore_string(camel_cased_word)
18
+ return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
19
+
20
+ word = camel_cased_word.to_s.gsub('::', '/')
21
+ word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) { "#{::Regexp.last_match(1) && '_'}#{::Regexp.last_match(2).downcase}" }
22
+ word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (::Regexp.last_match(1) || ::Regexp.last_match(2)) << '_' }
23
+ word.tr!('-', '_')
24
+ word.downcase!
25
+ word
26
+ end
27
+
28
+ def initialize(host: nil, scheme: :http, config: nil, token: nil, current_namespace: nil)
29
+ if [host, config].all?(&:nil?) || [host, config].none?(&:nil?)
30
+ raise ArgumentError, 'either host or config must be passed'
31
+ end
32
+
33
+ @host = host
34
+ @scheme = scheme
35
+ @config = config
36
+ @token = token
37
+ @current_namespace = current_namespace
38
+ end
39
+
40
+ def current_namespace = @current_namespace ||= ENV.fetch('KUBERNETES_NAMESPACE') { read_file(NAMESPACE_PATH) }
41
+
42
+ # for every single available API define methods like
43
+ # def apps_v1_api = @apps_v1_api ||= Zilla::AppsV1Api.new(client)
44
+ Zilla.constants(false).each do |class_name|
45
+ next unless class_name.end_with?('Api')
46
+
47
+ define_method(_underscore_string(class_name.to_s)) do
48
+ var = "@#{class_name}"
49
+ return instance_variable_get(var) if instance_variable_defined?(var)
50
+
51
+ instance_variable_set(var, Zilla.const_get(class_name).new(client))
52
+ end
53
+ end
54
+
55
+ def client = @client ||= Zilla::ApiClient.new(config)
56
+
57
+ def in_cluster? = [TOKEN_PATH, CERT_PATH, NAMESPACE_PATH].all?(File.method(:exist?))
58
+
59
+ def config
60
+ @config ||= Zilla::Configuration.new.tap do |cfg|
61
+ cfg.host = @host
62
+ cfg.scheme = @scheme
63
+ cfg.server_index = nil
64
+ cfg.api_key_prefix['BearerToken'] = 'Bearer'
65
+
66
+ next unless in_cluster?
67
+
68
+ cfg.ssl_ca_file = CERT_PATH
69
+ cfg.api_key['BearerToken'] = token
70
+ end
71
+ end
72
+
73
+ def token = @token ||= read_file(TOKEN_PATH)
74
+
75
+ private
76
+
77
+ def read_file(path) = File.read(path)
78
+ end
79
+ end
data/lib/zilla/version.rb CHANGED
@@ -11,5 +11,5 @@
11
11
  #
12
12
 
13
13
  module Zilla
14
- VERSION = '0.2.1'
14
+ VERSION = '0.2.3'
15
15
  end
data/lib/zilla.rb CHANGED
@@ -575,6 +575,9 @@ require 'zilla/api/storage_v1beta1_api'
575
575
  require 'zilla/api/version_api'
576
576
  require 'zilla/api/well_known_api'
577
577
 
578
+ # Custom files
579
+ require 'zilla/kubernetes'
580
+
578
581
  module Zilla
579
582
  class << self
580
583
  # Customize default settings for the SDK using block.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenAPI-Generator
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-23 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -138,6 +138,7 @@ files:
138
138
  - lib/zilla/api_client.rb
139
139
  - lib/zilla/api_error.rb
140
140
  - lib/zilla/configuration.rb
141
+ - lib/zilla/kubernetes.rb
141
142
  - lib/zilla/models/io_k8s_api_admissionregistration_v1_mutating_webhook.rb
142
143
  - lib/zilla/models/io_k8s_api_admissionregistration_v1_mutating_webhook_configuration.rb
143
144
  - lib/zilla/models/io_k8s_api_admissionregistration_v1_mutating_webhook_configuration_list.rb