Class: Foreplay::Engine::Secrets::Location
- Inherits:
-
Object
- Object
- Foreplay::Engine::Secrets::Location
show all
- Includes:
- Foreplay
- Defined in:
- lib/foreplay/engine/secrets/location.rb
Constant Summary
Constants included
from Foreplay
DEFAULT_PORT, PORT_GAP, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Foreplay
#log, #terminate
Constructor Details
#initialize(s, e) ⇒ Location
Returns a new instance of Location.
8
9
10
11
|
# File 'lib/foreplay/engine/secrets/location.rb', line 8
def initialize(s, e)
@secret_location = s
@environment = e
end
|
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
6
7
8
|
# File 'lib/foreplay/engine/secrets/location.rb', line 6
def environment
@environment
end
|
#secret_location ⇒ Object
Returns the value of attribute secret_location.
6
7
8
|
# File 'lib/foreplay/engine/secrets/location.rb', line 6
def secret_location
@secret_location
end
|
Instance Method Details
#all_secrets ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/foreplay/engine/secrets/location.rb', line 32
def all_secrets
return @all_secrets if @all_secrets
@all_secrets = url ? YAML.safe_load(raw_secrets, [Date, Symbol, Time], [], true) : {}
rescue Psych::SyntaxError => e
log "Exception caught when loading secrets from this location: #{url}"
log "#{e.class}: #{e.message}".red
@all_secrets = {}
end
|
#command ⇒ Object
45
46
47
|
# File 'lib/foreplay/engine/secrets/location.rb', line 45
def command
@command ||= "curl -k -L#{} #{url}".fake_erb
end
|
49
50
51
|
# File 'lib/foreplay/engine/secrets/location.rb', line 49
def
@header_string ||= .map { |k, v| " -H \"#{k}: #{v}\"" }.join if .is_a? Hash
end
|
53
54
55
|
# File 'lib/foreplay/engine/secrets/location.rb', line 53
def
@headers ||= secret_location['headers']
end
|
#raw_secrets ⇒ Object
41
42
43
|
# File 'lib/foreplay/engine/secrets/location.rb', line 41
def raw_secrets
@raw_secrets ||= `#{command}`
end
|
#secrets ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/foreplay/engine/secrets/location.rb', line 13
def secrets
return @secrets if @secrets
@secrets = all_secrets[environment]
case @secrets
when Hash
log "Loaded #{secrets.keys.length} secrets"
@secrets
when String
log "Unexpected secrets found: #{@secrets}"
@secrets = {}
else
url ? log("No secrets found at #{url}") : log('No url for secrets found')
log("Secrets #{all_secrets.key?(environment) ? 'has a' : 'has no'} key #{environment}") if all_secrets
@secrets = {}
end
end
|
#url ⇒ Object
57
58
59
|
# File 'lib/foreplay/engine/secrets/location.rb', line 57
def url
@url ||= @secret_location['url']
end
|