Add /settings/ssh_keys API
This commit is contained in:
parent
1b524071f4
commit
e9cdef1c9b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
11
lib/travis/api/v2/http/ssh_key.rb
Normal file
11
lib/travis/api/v2/http/ssh_key.rb
Normal file
|
@ -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
|
2
lib/travis/api/v2/http/ssh_keys.rb
Normal file
2
lib/travis/api/v2/http/ssh_keys.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class Travis::Api::V2::Http::SshKeys < Travis::Api::ArraySerializer
|
||||
end
|
34
spec/integration/v2/settings/ssh_keys_spec.rb
Normal file
34
spec/integration/v2/settings/ssh_keys_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user