Class: OpenStax::Aws::SecretsSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/secrets_specification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, format: nil, top_key: nil, preparser: nil) ⇒ SecretsSpecification

Returns a new instance of SecretsSpecification.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openstax/aws/secrets_specification.rb', line 30

def initialize(content:, format: nil, top_key: nil, preparser: nil)
  case content
  when Hash
    @data = content.dup
  when String
    raise "#{format} is not yet handled" if :yml != format

    case (preparser || 'none').to_sym
    when :erb
      content = parse_erb(content)
    end

    @data = YAML.load(content)
  else
    raise "Unknown secrets specification inline content type: #{content.class}"
  end

  @data = data.with_indifferent_access
  @data = data[top_key.to_s] if top_key
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/openstax/aws/secrets_specification.rb', line 7

def data
  @data
end

Class Method Details

.from_content(content:, format: nil, top_key: nil, preparser: nil) ⇒ Object



26
27
28
# File 'lib/openstax/aws/secrets_specification.rb', line 26

def self.from_content(content:, format: nil, top_key: nil, preparser: nil)
  new(content: content, format: format, top_key: top_key, preparser: preparser)
end

.from_file_name(file_name:, format:, top_key: nil, preparser: nil) ⇒ Object



9
10
11
12
13
14
# File 'lib/openstax/aws/secrets_specification.rb', line 9

def self.from_file_name(file_name:, format:, top_key: nil, preparser: nil)
  file = File.open(file_name, "r")
  content = file.read
  file.close
  new(content: content, format: format, top_key: top_key, preparser: preparser)
end

.from_git(org_slash_repo:, sha:, path:, github_token: nil, format:, top_key: nil, preparser: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/openstax/aws/secrets_specification.rb', line 16

def self.from_git(org_slash_repo:, sha:, path:, github_token: nil, format:, top_key: nil, preparser: nil)
  content = OpenStax::Aws::GitHelper.file_content_at_sha(
              org_slash_repo: org_slash_repo,
              sha: sha,
              path: path,
              github_token: github_token
            )
  new(content: content, format: format, top_key: top_key, preparser: preparser)
end

Instance Method Details

#expanded_dataObject



51
52
53
# File 'lib/openstax/aws/secrets_specification.rb', line 51

def expanded_data
  flat_hash(@data).map{|k,v| [k.join('/'), v]}.to_h
end