Module: NexusCli::RepositoryActions

Included in:
OSSRemote, ProRemote
Defined in:
lib/nexus_cli/mixins/repository_actions.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#add_to_group_repository(group_id, repository_to_add_id) ⇒ Boolean

Adds the given [repository_to_add_id] to the given group repository, [group_id].

Parameters:

  • group_id (String)

    the group repository to add to

  • repository_to_add_id (String)

    the repository to added to the group

Returns:

  • (Boolean)

    true if the repository is successfully added, false otherwise

Raises:



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 132

def add_to_group_repository(group_id, repository_to_add_id)
  raise RepositoryInGroupException if repository_in_group?(group_id, repository_to_add_id)
  response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_add_to_group_repository_json(group_id, repository_to_add_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 200
    return true
  when 400
    raise RepositoryNotFoundException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#create_group_repository(name, id, provider) ⇒ Boolean

Creates a group repository with the given name.

Parameters:

  • name (String)

    the name to give the new repository

  • id (String)

    an alternative id to use for the new repository

  • provider (String)

    the type of Maven provider for this repository

Returns:

  • (Boolean)

    true if the group repository is created, false otherwise



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 81

def create_group_repository(name, id, provider)
  response = nexus.post(nexus_url("service/local/repo_groups"), :body => create_group_repository_json(name, id, provider), :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 201
    return true
  when 400
    raise CreateRepsitoryException.new(response.content)
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#create_repository(name, proxy, url, id, policy, provider) ⇒ Boolean

Creates a repository that the Nexus uses to hold artifacts.

Parameters:

  • name (String)

    the name of the repository to create

  • proxy (Boolean)

    true if this is a proxy repository

  • url (String)

    the url for the proxy repository to point to

  • id (String)

    the id of repository

  • policy (String)

    repository policy (RELEASE|SNAPSHOT)

  • provider (String)

    repo provider (maven2 by default)

Returns:

  • (Boolean)

    returns true on success



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 17

def create_repository(name, proxy, url, id, policy, provider)
  json = if proxy
    create_proxy_repository_json(name, url, id, policy, provider)
  else
    create_hosted_repository_json(name, id, policy, provider)
  end
  response = nexus.post(nexus_url("service/local/repositories"), :body => json, :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 201
    return true
  when 400
    raise CreateRepsitoryException.new(response.content)
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#delete_group_repository(group_id) ⇒ Boolean

Deletes the given group repository.

Parameters:

  • group_id (String)

    the group repository to delete

Returns:

  • (Boolean)

    true if the group repository is deleted, false otherwise



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 168

def delete_group_repository(group_id)
  response = nexus.delete(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"))
  case response.status
  when 204
    return true
  when 404
    raise RepositoryNotFoundException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#delete_repository(name) ⇒ Boolean

Deletes the given repository

into an id.

Parameters:

  • name (String)

    the name of the repositroy to delete, transformed

Returns:

  • (Boolean)

    true if the repository is deleted, false otherwise.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 40

def delete_repository(name)
  response = nexus.delete(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
  case response.status
  when 204
    return true
  when 404
    raise RepositoryDoesNotExistException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#get_group_repository(group_id) ⇒ String

Gets information about the given group repository with the given [group_id].

Parameters:

  • group_id (String)

    the id of the group repository to find

Returns:

  • (String)

    a JSON String of information about the given group repository



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 99

def get_group_repository(group_id)
  response = nexus.get(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :header => DEFAULT_ACCEPT_HEADER)
  case response.status
  when 200
    return response.content
  when 404
    raise RepositoryNotFoundException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#get_repository_info(name) ⇒ String

Find information about the repository with the given [name].

into an id.

repository.

Parameters:

  • name (String)

    the name of the repository, transformed

Returns:

  • (String)

    A String of XML with information about the desired



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 60

def get_repository_info(name)
  response = nexus.get(nexus_url("service/local/repositories/#{sanitize_for_id(name)}"))
  case response.status
  when 200
    return response.content
  when 404
    raise RepositoryNotFoundException
  when 503
    raise CouldNotConnectToNexusException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#remove_from_group_repository(group_id, repository_to_remove_id) ⇒ Boolean

Removes the given [repository_to_remove_id] from the group repository, [group_id].

Parameters:

  • group_id (String)

    the group repository to remove from

  • repository_to_remove_id (String)

    the repository to remove from the group

Returns:

  • (Boolean)

    true if the repisotory is successfully remove, false otherwise

Raises:



152
153
154
155
156
157
158
159
160
161
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 152

def remove_from_group_repository(group_id, repository_to_remove_id)
  raise RepositoryNotInGroupException unless repository_in_group?(group_id, repository_to_remove_id)
  response = nexus.put(nexus_url("service/local/repo_groups/#{sanitize_for_id(group_id)}"), :body => create_remove_from_group_repository_json(group_id, repository_to_remove_id), :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 200
    return true
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#repository_in_group?(group_id, repository_to_check) ⇒ Boolean

Checks if a the given [repository_to_check] is a member of the given group repository - [group_ip].

Parameters:

  • group_id (String)

    the group repository to look in

  • repository_to_check (String)

    the repository that might be a member of the group

Returns:

  • (Boolean)

    true if the [repository_to_check] is a member of group repository, false otherwise



118
119
120
121
122
123
# File 'lib/nexus_cli/mixins/repository_actions.rb', line 118

def repository_in_group?(group_id, repository_to_check)
  group_repository = JSON.parse(get_group_repository(group_id))
  repositories_in_group = group_repository["data"]["repositories"]

  repositories_in_group.find{|repository| repository["id"] == sanitize_for_id(repository_to_check)}
end