zilla 0.2.1 → 0.2.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/zilla/kubernetes.rb +74 -0
- data/lib/zilla/version.rb +1 -1
- data/lib/zilla.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fb607c85e1db49bbd53ccb44d3ec15f6c01b8287e24e54f67d0ec83ae954b3d
|
4
|
+
data.tar.gz: 26149adaa9b61ba54a61be617e81c2fd4bf1629674fe2931547d97c3c9d69c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3d8b5e02b2ef451ca9fb68c6e97f7bb898efc4db2e4a3bcd78486e3bf1aa78806a5bf9d402096a9b33107a02c85e220477293d021b0f4be39dff67c540289bb
|
7
|
+
data.tar.gz: 7b55b43f27e823c6fbd83ba4b8f3893ee1ea1be62e1b003fad92d42b98ca523137dcbce58eed3ab9fb8e8c3766a55fe52a4d5862e74e076052a4cf398f152923
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zilla
|
4
|
+
class Kubernetes
|
5
|
+
SERVICE_ACCOUNT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount'
|
6
|
+
|
7
|
+
TOKEN_PATH = "#{SERVICE_ACCOUNT_PATH}/token".freeze
|
8
|
+
CERT_PATH = "#{SERVICE_ACCOUNT_PATH}/ca.crt".freeze
|
9
|
+
NAMESPACE_PATH = "#{SERVICE_ACCOUNT_PATH}/namespace".freeze
|
10
|
+
|
11
|
+
# https://github.com/rails/rails/blob/7-0-stable/activesupport/lib/active_support/inflector/methods.rb#LL96-L104C8
|
12
|
+
def self._underscore_string(camel_cased_word)
|
13
|
+
return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
|
14
|
+
|
15
|
+
word = camel_cased_word.to_s.gsub('::', '/')
|
16
|
+
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) { "#{::Regexp.last_match(1) && '_'}#{::Regexp.last_match(2).downcase}" }
|
17
|
+
word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (::Regexp.last_match(1) || ::Regexp.last_match(2)) << '_' }
|
18
|
+
word.tr!('-', '_')
|
19
|
+
word.downcase!
|
20
|
+
word
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(host: nil, scheme: :http, config: nil, token: nil, current_namespace: nil)
|
24
|
+
if [host, config].all?(&:nil?) || [host, config].none?(&:nil?)
|
25
|
+
raise ArgumentError, 'either host or config must be passed'
|
26
|
+
end
|
27
|
+
|
28
|
+
@host = host
|
29
|
+
@scheme = scheme
|
30
|
+
@config = config
|
31
|
+
@token = token
|
32
|
+
@current_namespace = current_namespace
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_namespace = @current_namespace ||= ENV.fetch('KUBERNETES_NAMESPACE') { read_file(NAMESPACE_PATH) }
|
36
|
+
|
37
|
+
# for every single available API define methods like
|
38
|
+
# def apps_v1_api = @apps_v1_api ||= Zilla::AppsV1Api.new(client)
|
39
|
+
Zilla.constants(false).each do |class_name|
|
40
|
+
next unless class_name.end_with?('Api')
|
41
|
+
|
42
|
+
define_method(_underscore_string(class_name.to_s)) do
|
43
|
+
var = "@#{class_name}"
|
44
|
+
return instance_variable_get(var) if instance_variable_defined?(var)
|
45
|
+
|
46
|
+
instance_variable_set(var, Zilla.const_get(class_name).new(client))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def client = @client ||= Zilla::ApiClient.new(config)
|
51
|
+
|
52
|
+
def in_cluster? = [TOKEN_PATH, CERT_PATH, NAMESPACE_PATH].all?(File.method(:exist?))
|
53
|
+
|
54
|
+
def config
|
55
|
+
@config ||= Zilla::Configuration.new.tap do |cfg|
|
56
|
+
cfg.host = @host
|
57
|
+
cfg.scheme = @scheme
|
58
|
+
cfg.server_index = nil
|
59
|
+
cfg.api_key_prefix['BearerToken'] = 'Bearer'
|
60
|
+
|
61
|
+
next unless in_cluster?
|
62
|
+
|
63
|
+
cfg.ssl_ca_file = CERT_PATH
|
64
|
+
cfg.api_key['BearerToken'] = token
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def token = @token ||= read_file(TOKEN_PATH)
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def read_file(path) = File.read(path)
|
73
|
+
end
|
74
|
+
end
|
data/lib/zilla/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2023-03-07 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
|