diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 80fa6e26..e8b290f4 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -114,6 +114,8 @@ module Travis::Api use Travis::Api::App::Middleware::Metriks use Travis::Api::App::Middleware::Rewrite + SettingsEndpoint.subclass :ssh_keys + Endpoint.subclasses.each do |e| next if e == SettingsEndpoint # TODO: add something like abstract? method to check if # class should be registered diff --git a/lib/travis/api/v2/http.rb b/lib/travis/api/v2/http.rb index 6034ef07..ca1384cf 100644 --- a/lib/travis/api/v2/http.rb +++ b/lib/travis/api/v2/http.rb @@ -1,3 +1,5 @@ +require 'travis/api/serializer' + module Travis module Api module V2 @@ -20,6 +22,8 @@ module Travis require 'travis/api/v2/http/requests' require 'travis/api/v2/http/request' require 'travis/api/v2/http/ssl_key' + require 'travis/api/v2/http/ssh_key' + require 'travis/api/v2/http/ssh_keys' require 'travis/api/v2/http/user' require 'travis/api/v2/http/validation_error' end diff --git a/lib/travis/api/v2/http/ssh_key.rb b/lib/travis/api/v2/http/ssh_key.rb new file mode 100644 index 00000000..a785f365 --- /dev/null +++ b/lib/travis/api/v2/http/ssh_key.rb @@ -0,0 +1,11 @@ +module Travis + module Api + module V2 + module Http + class SshKey < Travis::Api::Serializer + attributes :id, :name + end + end + end + end +end diff --git a/lib/travis/api/v2/http/ssh_keys.rb b/lib/travis/api/v2/http/ssh_keys.rb new file mode 100644 index 00000000..d93829be --- /dev/null +++ b/lib/travis/api/v2/http/ssh_keys.rb @@ -0,0 +1,2 @@ +class Travis::Api::V2::Http::SshKeys < Travis::Api::ArraySerializer +end diff --git a/spec/integration/v2/settings/ssh_keys_spec.rb b/spec/integration/v2/settings/ssh_keys_spec.rb new file mode 100644 index 00000000..84566da5 --- /dev/null +++ b/spec/integration/v2/settings/ssh_keys_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe Travis::Api::App::SettingsEndpoint do + let(:repo) { Repository.by_slug('svenfuchs/minimal').first } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } + + describe 'with authenticated user' do + let(:user) { User.where(login: 'svenfuchs').first } + let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) } + let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } } + + before { user.permissions.create!(:repository_id => repo.id, :admin => true, :push => true) } + + describe 'GET /items/:id' do + it 'returns an item' do + settings = repo.settings + record = settings.ssh_keys.create(name: 'key for my repo', content: 'the key') + settings.save + + response = get '/settings/ssh_keys/' + record.id, { repository_id: repo.id }, headers + json = JSON.parse(response.body) + json['ssh_key']['name'].should == 'key for my repo' + json['ssh_key']['id'].should == record.id + json['ssh_key'].should_not have_key('secret') + end + + it 'returns 404 if ssh_key can\'t be found' do + response = get '/settings/ssh_key/123', { repository_id: repo.id }, headers + json = JSON.parse(response.body) + json['error'].should == "Could not find a requested setting" + end + end + end +end