Return env var's value if it's public
This commit is contained in:
parent
2e8fc35e13
commit
cc291446f5
|
@ -3,7 +3,19 @@ module Travis
|
|||
module V2
|
||||
module Http
|
||||
class EnvVar < Travis::Api::Serializer
|
||||
attributes :id, :name, :public
|
||||
attributes :id, :name, :value, :public
|
||||
|
||||
def value
|
||||
if object.public?
|
||||
object.value.decrypt
|
||||
end
|
||||
end
|
||||
|
||||
def serializable_hash
|
||||
hash = super
|
||||
hash.delete :value unless object.public?
|
||||
hash
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
20
spec/unit/api/v2/http/env_var_spec.rb
Normal file
20
spec/unit/api/v2/http/env_var_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::Api::V2::Http::EnvVar do
|
||||
let(:env_var) { Repository::Settings::EnvVar.new(name: 'FOO', value: 'bar', public: true) }
|
||||
let(:data) { Travis::Api::V2::Http::EnvVar.new(env_var) }
|
||||
|
||||
it 'returns value' do
|
||||
data.as_json[:env_var][:value].should == 'bar'
|
||||
end
|
||||
|
||||
describe 'private' do
|
||||
let(:env_var) { Repository::Settings::EnvVar.new(name: 'FOO', value: 'bar', public: false) }
|
||||
|
||||
it "doesn't return the value" do
|
||||
data.to_json.should_not include('bar')
|
||||
data.as_json[:env_var].should_not have_key(:value)
|
||||
data.as_json[:env_var].should_not have_key('value')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user