Class: Kitsune::Kit::ServiceCompose
- Inherits:
-
Object
- Object
- Kitsune::Kit::ServiceCompose
- Defined in:
- lib/kitsune/kit/service_compose.rb
Defined Under Namespace
Classes: Document
Constant Summary collapse
- MAX_FILE_SIZE =
262_144- MODES =
%w[generated overlay custom].freeze
- SENSITIVE_KEY =
/(?:password|passwd|secret|token|api[_-]?key)/i- ENV_REFERENCE =
/\A\$\{[A-Z][A-Z0-9_]*\}\z/
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#security_findings ⇒ Object
readonly
Returns the value of attribute security_findings.
Instance Method Summary collapse
- #content ⇒ Object
- #display ⇒ Object
- #documents ⇒ Object
- #env_content(password) ⇒ Object
- #filenames ⇒ Object
- #fingerprint ⇒ Object
- #generated_content ⇒ Object
-
#initialize(config:, type:, service:) ⇒ ServiceCompose
constructor
A new instance of ServiceCompose.
- #metadata ⇒ Object
Constructor Details
#initialize(config:, type:, service:) ⇒ ServiceCompose
Returns a new instance of ServiceCompose.
20 21 22 23 24 25 26 27 |
# File 'lib/kitsune/kit/service_compose.rb', line 20 def initialize(config:, type:, service:) @config = config @type = type.to_s @service = service @mode = service.compose.mode @security_findings = [] validate! end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
18 19 20 |
# File 'lib/kitsune/kit/service_compose.rb', line 18 def mode @mode end |
#security_findings ⇒ Object (readonly)
Returns the value of attribute security_findings.
18 19 20 |
# File 'lib/kitsune/kit/service_compose.rb', line 18 def security_findings @security_findings end |
Instance Method Details
#content ⇒ Object
29 |
# File 'lib/kitsune/kit/service_compose.rb', line 29 def content = documents.first.content |
#display ⇒ Object
55 56 57 58 59 |
# File 'lib/kitsune/kit/service_compose.rb', line 55 def display documents.map do |document| "# --- #{document.filename} (#{document.source}) ---\n#{document.content}" end.join("\n") end |
#documents ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/kitsune/kit/service_compose.rb', line 38 def documents @documents ||= case mode when "generated" [Document.new(filename: "compose.yml", content: generated_content, source: "generated")] when "overlay" [ Document.new(filename: "compose.yml", content: generated_content, source: "generated"), Document.new(filename: "compose.override.yml", content: user_content, source: @service.compose.file) ] when "custom" [Document.new(filename: "compose.yml", content: user_content, source: @service.compose.file)] else raise Errors::ConfigurationError, "unsupported Compose mode: #{mode}" end end |
#env_content(password) ⇒ Object
31 |
# File 'lib/kitsune/kit/service_compose.rb', line 31 def env_content(password) = "#{@service.password_env}=#{JSON.generate(password)}\n" |
#filenames ⇒ Object
32 |
# File 'lib/kitsune/kit/service_compose.rb', line 32 def filenames = documents.map(&:filename) |
#fingerprint ⇒ Object
34 35 36 |
# File 'lib/kitsune/kit/service_compose.rb', line 34 def fingerprint Digest::SHA256.hexdigest([mode, *documents.flat_map { |item| [item.filename, item.content] }].join("\0")) end |
#generated_content ⇒ Object
30 |
# File 'lib/kitsune/kit/service_compose.rb', line 30 def generated_content = YAML.dump(generated_document) |
#metadata ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/kitsune/kit/service_compose.rb', line 61 def { mode: mode, files: documents.map { |document| { filename: document.filename, source: document.source } }, allow_unsafe: @service.compose.allow_unsafe, security_findings: security_findings } end |