Class: Kitsune::Kit::ServiceCompose

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#modeObject (readonly)

Returns the value of attribute mode.



18
19
20
# File 'lib/kitsune/kit/service_compose.rb', line 18

def mode
  @mode
end

#security_findingsObject (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

#contentObject



29
# File 'lib/kitsune/kit/service_compose.rb', line 29

def content = documents.first.content

#displayObject



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

#documentsObject



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"

#filenamesObject



32
# File 'lib/kitsune/kit/service_compose.rb', line 32

def filenames = documents.map(&:filename)

#fingerprintObject



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_contentObject



30
# File 'lib/kitsune/kit/service_compose.rb', line 30

def generated_content = YAML.dump(generated_document)

#metadataObject



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