forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API client can retrieve env variables for a revision
[finishes #162994516] Signed-off-by: Mona Mohebbi <[email protected]>
- Loading branch information
1 parent
20a30c1
commit 3281fb5
Showing
8 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/presenters/v3/revision_environment_variables_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'presenters/v3/app_environment_variables_presenter' | ||
require 'presenters/v3/base_presenter' | ||
|
||
module VCAP::CloudController | ||
module Presenters | ||
module V3 | ||
class RevisionEnvironmentVariablesPresenter | ||
attr_reader :revision | ||
|
||
def initialize(revision) | ||
@revision = revision | ||
end | ||
|
||
def to_hash | ||
result = { | ||
var: {}, | ||
links: build_links | ||
} | ||
|
||
env_vars&.each do |key, value| | ||
result[:var][key.to_sym] = value | ||
end | ||
|
||
result | ||
end | ||
|
||
private | ||
|
||
def env_vars | ||
revision&.environment_variables | ||
end | ||
|
||
def build_links | ||
url_builder = VCAP::CloudController::Presenters::ApiUrlBuilder.new | ||
|
||
{ | ||
self: { href: url_builder.build_url(path: "/v3/apps/#{revision.app.guid}/revisions/#{revision.guid}/environment_variables") }, | ||
revision: { href: url_builder.build_url(path: "/v3/apps/#{revision.app.guid}/revisions/#{revision.guid}") }, | ||
app: { href: url_builder.build_url(path: "/v3/apps/#{revision.app.guid}") } | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
spec/unit/presenters/v3/revision_environment_variables_presenter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'spec_helper' | ||
require 'presenters/v3/revision_environment_variables_presenter' | ||
|
||
module VCAP::CloudController::Presenters::V3 | ||
RSpec.describe RevisionEnvironmentVariablesPresenter do | ||
let(:revision) do | ||
VCAP::CloudController::RevisionModel.make( | ||
environment_variables: { 'CUSTOM_ENV_VAR' => 'hello' }, | ||
) | ||
end | ||
|
||
subject(:presenter) { RevisionEnvironmentVariablesPresenter.new(revision) } | ||
|
||
describe '#to_hash' do | ||
let(:result) { presenter.to_hash } | ||
|
||
it 'presents the app environment variables as json' do | ||
expect(result).to eq({ | ||
var: { | ||
CUSTOM_ENV_VAR: 'hello' | ||
}, | ||
links: { | ||
self: { | ||
href: "#{link_prefix}/v3/apps/#{revision.app.guid}/revisions/#{revision.guid}/environment_variables", | ||
}, | ||
revision: { | ||
href: "#{link_prefix}/v3/apps/#{revision.app.guid}/revisions/#{revision.guid}", | ||
}, | ||
app: { | ||
href: "#{link_prefix}/v3/apps/#{revision.app.guid}", | ||
}, | ||
} | ||
}) | ||
end | ||
end | ||
end | ||
end |