Skip to content

Commit

Permalink
Implements adding ssh users to builds
Browse files Browse the repository at this point in the history
* Add user ssh key to a build
  • Loading branch information
mtchavez committed Dec 6, 2015
1 parent 43904cc commit 3107bf7
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 18 deletions.
47 changes: 31 additions & 16 deletions lib/circleci/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,70 @@ def self.all

##
#
# Get all recent builds for a specific project
# Build the latest master push for this project
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @return [CircleCi::Response] - Response object

def self.recent_builds username, project
CircleCi.http.get "/project/#{username}/#{project}"
def self.build username, project
CircleCi.http.post "/project/#{username}/#{project}"
end

##
#
# Build the latest master push for this project
# Build the latest push for this branch of a specific project
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @param branch [String] - Name of branch
# @param build_parameters [Hash] - Optional Build Parameters
# @return [CircleCi::Response] - Response object

def self.build username, project
CircleCi.http.post "/project/#{username}/#{project}"
def self.build_branch username, project, branch, build_parameters = {}
body = {}
body["build_parameters"] = build_parameters unless build_parameters.empty?
CircleCi.http.post "/project/#{username}/#{project}/tree/#{branch}", {}, body
end

##
#
# Get all recent builds for a specific branch of a project
# Add a ssh key to a build
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @param branch [String] - Name of branch
# @param build [String] - Build number
# @param key [String] - The ssh private key
# @param hostname [String] - The hostname identified by the key
# @return [CircleCi::Response] - Response object
def self.build_ssh_key username, project, build, key, hostname
body = { hostname: hostname, private_key: key }
CircleCi.http.post "/project/#{username}/#{project}/#{build}/ssh-users", {}, body
end

def self.recent_builds_branch username, project, branch
CircleCi.http.get "/project/#{username}/#{project}/tree/#{branch}"
##
#
# Get all recent builds for a specific project
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @return [CircleCi::Response] - Response object

def self.recent_builds username, project
CircleCi.http.get "/project/#{username}/#{project}"
end

##
#
# Build the latest push for this branch of a specific project
# Get all recent builds for a specific branch of a project
#
# @param username [String] - User or org name who owns project
# @param project [String] - Name of project
# @param branch [String] - Name of branch
# @param build_parameters [Hash] - Optional Build Parameters
# @return [CircleCi::Response] - Response object

def self.build_branch username, project, branch, build_parameters = {}
body = {}
body["build_parameters"] = build_parameters unless build_parameters.empty?
CircleCi.http.post "/project/#{username}/#{project}/tree/#{branch}", {}, body
def self.recent_builds_branch username, project, branch
CircleCi.http.get "/project/#{username}/#{project}/tree/#{branch}"
end

##
Expand Down
84 changes: 84 additions & 0 deletions spec/cassettes/project/build_ssh_key/success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions spec/circleci/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@

end

describe 'build_ssh_key' do

context 'successfully', vcr: { cassette_name: 'project/build_ssh_key/success', record: :none } do

it 'returns a response object' do
res = CircleCi::Project.build_ssh_key 'mtchavez', 'circleci', '65', 'RSA Private Key', 'hostname'
res.should be_an_instance_of(CircleCi::Response)
res.should be_success
end

end

end

describe 'recent_builds' do

context 'successfully', vcr: { cassette_name: 'project/recent_builds/success', record: :none } do
Expand Down Expand Up @@ -162,9 +176,9 @@

end

describe 'ssk_key' do
describe 'ssh_key' do

context 'successfully', vcr: { cassette_name: 'project/ssh_key/success', record: :all } do
context 'successfully', vcr: { cassette_name: 'project/ssh_key/success', record: :none } do

it 'returns a response object' do
res = CircleCi::Project.ssh_key 'mtchavez', 'circleci', 'RSA Private Key', 'hostname'
Expand Down

0 comments on commit 3107bf7

Please sign in to comment.