Skip to content

Commit

Permalink
Merge pull request #385 from dxw/vcap-redis
Browse files Browse the repository at this point in the history
Load Redis URL to the ENV from VCAP_SERVICES
  • Loading branch information
james committed Apr 16, 2019
2 parents 93342c1 + 1bd6f24 commit 6353ec6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/vcap_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def self.load_service_environment_variables!
vcap_json.fetch('aws-s3-bucket', [])
.find { |aws_config| aws_config.fetch('name').match?(/^ingest-bucket-/) }
)

load_redis_config(
vcap_json.fetch('redis', []).first
)
end

def self.load_ingest_bucket_config(ingest_bucket_config)
Expand All @@ -23,4 +27,10 @@ def self.load_ingest_bucket_config(ingest_bucket_config)
ENV['AWS_S3_REGION'] = ENV['AWS_REGION'] = ingest_bucket_config.fetch('credentials').fetch('aws_region')
ENV['AWS_S3_BUCKET'] = ingest_bucket_config.fetch('credentials').fetch('bucket_name')
end

def self.load_redis_config(redis_config)
return unless redis_config

ENV['REDIS_URL'] = redis_config.fetch('credentials').fetch('uri')
end
end
18 changes: 18 additions & 0 deletions spec/lib/vcap_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@
end
end

it 'loads redis URL to the ENV' do
vcap_json = '
{
"redis": [
{
"credentials": {
"uri": "rediss://x:REDACTED@HOST:6379"
}
}
]
}
'
ClimateControl.modify VCAP_SERVICES: vcap_json do
VcapParser.load_service_environment_variables!
expect(ENV['REDIS_URL']).to eq('rediss://x:REDACTED@HOST:6379')
end
end

it 'does not error if VCAP_SERVICES is not set' do
ClimateControl.modify VCAP_SERVICES: nil do
expect { VcapParser.load_service_environment_variables! }.to_not raise_error
Expand Down

0 comments on commit 6353ec6

Please sign in to comment.