diff --git a/lib/travis/api/v2/http/env_var.rb b/lib/travis/api/v2/http/env_var.rb index 0b3e98c0..81bd7d3c 100644 --- a/lib/travis/api/v2/http/env_var.rb +++ b/lib/travis/api/v2/http/env_var.rb @@ -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 diff --git a/spec/unit/api/v2/http/env_var_spec.rb b/spec/unit/api/v2/http/env_var_spec.rb new file mode 100644 index 00000000..20f69863 --- /dev/null +++ b/spec/unit/api/v2/http/env_var_spec.rb @@ -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