Class: Vx::ServiceConnector::Bitbucket::DeployKeys

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/bitbucket/deploy_keys.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repoObject

Returns the value of attribute repo

Returns:

  • (Object)

    the current value of repo



4
5
6
# File 'lib/vx/service_connector/bitbucket/deploy_keys.rb', line 4

def repo
  @repo
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



4
5
6
# File 'lib/vx/service_connector/bitbucket/deploy_keys.rb', line 4

def session
  @session
end

Instance Method Details

#allObject



6
7
8
9
10
11
12
# File 'lib/vx/service_connector/bitbucket/deploy_keys.rb', line 6

def all
  begin
    session.get "api/1.0/repositories/#{repo.full_name}/deploy-keys?pagelen=100"
  rescue RequestError
    []
  end
end

#create(key_name, public_key) ⇒ Object



14
15
16
# File 'lib/vx/service_connector/bitbucket/deploy_keys.rb', line 14

def create(key_name, public_key)
  session.post "api/1.0/repositories/#{repo.full_name}/deploy-keys", label: key_name, key: public_key
end

#destroy(key_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/vx/service_connector/bitbucket/deploy_keys.rb', line 18

def destroy(key_name)
  all.select do |key|
    key['label'] == key_name
  end.map do |key|
    session.delete "api/1.0/repositories/#{repo.full_name}/deploy-keys/#{key['pk']}"
  end
end