Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for project ssh keys. #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/packet/client/ssh_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def list_ssh_keys(*args)
get('ssh-keys', *args).body['ssh_keys'].map { |p| Packet::SshKey.new(p, self) }
end

def list_project_ssh_keys(project_or_id, *args)
id = project_id(project_or_id)
get("project/#{id}/ssh-keys", *args).body['ssh_keys'].map { |p| Packet::SshKey.new(p, self) }
end

def get_ssh_key(id, *args)
Packet::SshKey.new(get("ssh-keys/#{id}", *args).body, self)
end
Expand All @@ -15,6 +20,13 @@ def create_ssh_key(ssh_key)
end
end

def create_project_ssh_key(ssh_key, project_or_id)
id = project_id(project_or_id)
post("project/#{id}/ssh-keys", ssh_key.to_hash).tap do |response|
ssh_key.update_attributes(response.body)
end
end

def update_ssh_key(ssh_key)
patch("ssh-keys/#{ssh_key.id}", ssh_key.to_hash).tap do |response|
ssh_key.update_attributes(response.body)
Expand All @@ -29,6 +41,16 @@ def delete_ssh_key(ssh_key_or_id)
end
delete("ssh-keys/#{id}")
end

private

def project_id(project_or_id)
if project_or_id.is_a?(Packet::Project)
project_or_id.id
else
project_or_id
end
end
end
end
end