aptly-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/COPYING.lib +165 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +18 -0
- data/TODO +6 -0
- data/aptly-api.gemspec +32 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/aptly.rb +52 -0
- data/lib/aptly/configuration.rb +20 -0
- data/lib/aptly/connection.rb +107 -0
- data/lib/aptly/errors.rb +68 -0
- data/lib/aptly/files.rb +22 -0
- data/lib/aptly/publish.rb +48 -0
- data/lib/aptly/repository.rb +114 -0
- data/lib/aptly/representation.rb +17 -0
- data/lib/aptly/version.rb +4 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b9a6f4793d0c5a1b67294f67a64f0e08b46fb25
|
4
|
+
data.tar.gz: 6f2593aa555d05ed0fadcce2f94e7896cdc5cd2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bdeff0e36a55919d3ea3ab64fc05bccb35f5520e2524645dca7daa1ace4921fb336d7bb65da9382732b8e4c854303509e66c2bc1e5494af5c7d537ed7b81d36
|
7
|
+
data.tar.gz: f04f80be9061602d5943e53e4e37c493dc53ae8b6c4d60ce666854bef0436176899a05fc5db72e102307873673ea04745d1995d8dbd63c278187423532791a8b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/COPYING.lib
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Aptly API
|
2
|
+
|
3
|
+
[![Inline docs](http://inch-ci.org/github/KDEJewellers/aptly-api.svg?branch=master)](http://inch-ci.org/github/KDEJewellers/aptly-api)
|
4
|
+
[![Build Status](https://travis-ci.org/KDEJewellers/aptly-api.svg?branch=master)](https://travis-ci.org/KDEJewellers/aptly-api)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/KDEJewellers/aptly-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/KDEJewellers/aptly-api?branch=master)
|
6
|
+
[![Dependency Status](https://gemnasium.com/KDEJewellers/aptly-api.svg)](https://gemnasium.com/KDEJewellers/aptly-api)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/KDEJewellers/aptly-api/badges/gpa.svg)](https://codeclimate.com/github/KDEJewellers/aptly-api)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'aptly-api'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install aptly-api
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'aptly'
|
29
|
+
|
30
|
+
Aptly.configure do |config|
|
31
|
+
config.host = 'localhost'
|
32
|
+
config.port = 8080
|
33
|
+
end
|
34
|
+
|
35
|
+
repo = Aptly::Repository.create('kewl-new-repo')
|
36
|
+
repo.upload(['file.deb'])
|
37
|
+
repo.packages.each do |package|
|
38
|
+
puts package
|
39
|
+
end
|
40
|
+
repo.publish('public-name', Distribution: 'wily', Architectures: %w(amd64 i386))
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/KDEJewellers/aptly-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/notes/rake_task'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'yard'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
13
|
+
t.files = ['lib/**/*.rb']
|
14
|
+
t.options = ['--any', '--extra', '--opts']
|
15
|
+
t.stats_options = ['--list-undoc']
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :test
|
data/TODO
ADDED
data/aptly-api.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aptly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'aptly-api'
|
8
|
+
spec.version = Aptly::VERSION
|
9
|
+
spec.authors = ['Harald Sitter']
|
10
|
+
spec.email = ['sitter@kde.org']
|
11
|
+
|
12
|
+
spec.summary = 'REST client for the Aptly API'
|
13
|
+
spec.description = 'REST client for the Aptly API'
|
14
|
+
spec.homepage = 'https://github.com/KDEJewellers/aptly-api/'
|
15
|
+
spec.license = 'LGPL-3.0'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
26
|
+
spec.add_development_dependency 'rake-notes', '~> 0.2'
|
27
|
+
spec.add_development_dependency 'simplecov', '~> 0.11'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 1.22'
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
30
|
+
|
31
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'aptly'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/aptly.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (C) 2015 Harald Sitter <sitter@kde.org>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 3 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'aptly/configuration'
|
17
|
+
require 'aptly/connection'
|
18
|
+
require 'aptly/errors'
|
19
|
+
require 'aptly/files'
|
20
|
+
require 'aptly/publish'
|
21
|
+
require 'aptly/repository'
|
22
|
+
require 'aptly/version'
|
23
|
+
|
24
|
+
# Aptly API
|
25
|
+
module Aptly
|
26
|
+
class << self
|
27
|
+
def configure
|
28
|
+
yield configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def configuration
|
32
|
+
@configuration ||= Configuration.new
|
33
|
+
end
|
34
|
+
|
35
|
+
# Publish 1 or more sources into a public repository prefix.
|
36
|
+
# @param sources [Array<Repository>] array of repositories to source
|
37
|
+
# @param prefix [String] the prefix to publish under
|
38
|
+
# @param source_kind [String] the source kind (local or snapshot)
|
39
|
+
# @return [PublishedRepository] newly published repository
|
40
|
+
def publish(sources, prefix = '', source_kind = 'local',
|
41
|
+
connection = Connection.new, **kwords)
|
42
|
+
kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
43
|
+
options = kwords.merge(
|
44
|
+
SourceKind: source_kind,
|
45
|
+
Sources: sources
|
46
|
+
)
|
47
|
+
response = connection.send(:post, "/publish/#{prefix}",
|
48
|
+
body: JSON.generate(options))
|
49
|
+
PublishedRepository.new(connection, JSON.parse(response.body))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Aptly
|
2
|
+
# Configuration.
|
3
|
+
class Configuration
|
4
|
+
# @!attribute host
|
5
|
+
# @return [String] host name to talk to
|
6
|
+
attr_accessor :host
|
7
|
+
|
8
|
+
# @!attribute port
|
9
|
+
# @return [Integer] port to talk to host to on
|
10
|
+
attr_accessor :port
|
11
|
+
|
12
|
+
# Creates a new instance.
|
13
|
+
# @param host see {#host}
|
14
|
+
# @param port see {#port}
|
15
|
+
def initialize(host: 'localhost', port: 80)
|
16
|
+
@host = host
|
17
|
+
@port = port
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require_relative 'errors'
|
6
|
+
|
7
|
+
module Aptly
|
8
|
+
# Connection adaptor.
|
9
|
+
# This class wraps HTTP interactions for our purposes and adds general purpose
|
10
|
+
# automation on top of the raw HTTP actions.
|
11
|
+
class Connection
|
12
|
+
DEFAULT_QUERY = {}
|
13
|
+
GETISH_ACTIONS = %i(get delete)
|
14
|
+
POSTISH_ACTIONS = %i(post put)
|
15
|
+
HTTP_ACTIONS = GETISH_ACTIONS + POSTISH_ACTIONS
|
16
|
+
|
17
|
+
CODE_ERRORS = {
|
18
|
+
400 => Errors::ClientError,
|
19
|
+
401 => Errors::UnauthorizedError,
|
20
|
+
404 => Errors::NotFoundError,
|
21
|
+
409 => Errors::ConflictError,
|
22
|
+
500 => Errors::ServerError
|
23
|
+
}
|
24
|
+
|
25
|
+
def initialize(**kwords)
|
26
|
+
@query = kwords.fetch(:query, DEFAULT_QUERY)
|
27
|
+
|
28
|
+
uri = URI.parse('')
|
29
|
+
uri.scheme = 'http'
|
30
|
+
uri.host = ::Aptly.configuration.host
|
31
|
+
uri.port = ::Aptly.configuration.port
|
32
|
+
|
33
|
+
@connection = Faraday.new(url: uri.to_s) do |c|
|
34
|
+
c.request :multipart
|
35
|
+
c.request :url_encoded
|
36
|
+
c.adapter :net_http
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(symbol, *args, **kwords)
|
41
|
+
return super(symbol, *args, kwords) unless HTTP_ACTIONS.include?(symbol)
|
42
|
+
|
43
|
+
kwords[:query] = build_query(kwords)
|
44
|
+
kwords.delete(:query) if kwords[:query].empty?
|
45
|
+
|
46
|
+
relative_path = args.shift
|
47
|
+
http_call(symbol, add_api(relative_path), kwords)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :connection
|
53
|
+
|
54
|
+
def build_query(kwords)
|
55
|
+
query = @query.merge(kwords.delete(:query) { {} })
|
56
|
+
query = query.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
57
|
+
query
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_api(relative_path)
|
61
|
+
"/api#{relative_path}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def mangle_post(body, headers, kwords)
|
65
|
+
if body
|
66
|
+
headers ||= {}
|
67
|
+
headers.merge!('Content-Type' => 'application/json')
|
68
|
+
else
|
69
|
+
kwords.each do |k, v|
|
70
|
+
if k.to_s.start_with?('file_')
|
71
|
+
body ||= {}
|
72
|
+
body[k] = Faraday::UploadIO.new(v, 'application/binary')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
[body, headers]
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_postish(action, path, kwords)
|
80
|
+
body = kwords.delete(:body)
|
81
|
+
headers = kwords.delete(:headers)
|
82
|
+
|
83
|
+
body, headers = mangle_post(body, headers, kwords)
|
84
|
+
|
85
|
+
connection.send(action, path, body, headers)
|
86
|
+
end
|
87
|
+
|
88
|
+
def run_getish(action, path, kwords)
|
89
|
+
params = kwords.delete(:query)
|
90
|
+
headers = kwords.delete(:headers)
|
91
|
+
connection.send(action, path, params, headers)
|
92
|
+
end
|
93
|
+
|
94
|
+
def http_call(action, path, kwords)
|
95
|
+
if POSTISH_ACTIONS.include?(action)
|
96
|
+
response = run_postish(action, path, kwords)
|
97
|
+
elsif GETISH_ACTIONS.include?(action)
|
98
|
+
response = run_getish(action, path, kwords)
|
99
|
+
else
|
100
|
+
fail "Unknown http action: #{action}"
|
101
|
+
end
|
102
|
+
error = CODE_ERRORS.fetch(response.status, nil)
|
103
|
+
fail error, response.body if error
|
104
|
+
response
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/aptly/errors.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Aptly
|
2
|
+
# All aptly errors.
|
3
|
+
module Errors
|
4
|
+
# Generic HTTP error base.
|
5
|
+
class HTTPError < StandardError; end
|
6
|
+
|
7
|
+
# Raised when a request returns code 400.
|
8
|
+
class ClientError < HTTPError; end
|
9
|
+
|
10
|
+
# Raised when a request returns code 401.
|
11
|
+
class UnauthorizedError < HTTPError; end
|
12
|
+
|
13
|
+
# Raised when a request returns code 404.
|
14
|
+
class NotFoundError < HTTPError; end
|
15
|
+
|
16
|
+
# Raised when a request returns code 409.
|
17
|
+
class ConflictError < HTTPError; end
|
18
|
+
|
19
|
+
# Raised when a request returns code 500.
|
20
|
+
class ServerError < HTTPError; end
|
21
|
+
|
22
|
+
# Raised when a file operation had an error.
|
23
|
+
class RepositoryFileError < StandardError
|
24
|
+
# @!attribute [r] failures
|
25
|
+
# @return [Array<String>] list of failed files
|
26
|
+
attr_accessor :failures
|
27
|
+
|
28
|
+
# @!attribute [r] warnings
|
29
|
+
# @return [Array<String>] warnings from remote (one per file generally)
|
30
|
+
attr_accessor :warnings
|
31
|
+
|
32
|
+
# Create a new error instance.
|
33
|
+
# @param failures see {#failures}
|
34
|
+
# @param warnings see {#warnings}
|
35
|
+
# @param args forwarded to super
|
36
|
+
def initialize(failures, warnings, *args)
|
37
|
+
super(*args)
|
38
|
+
@failures = failures
|
39
|
+
@warnings = warnings
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] (formatted) string representation
|
43
|
+
def to_s
|
44
|
+
<<-EOF
|
45
|
+
|
46
|
+
~~~
|
47
|
+
Failed to process:
|
48
|
+
#{failures.join("\n ")}
|
49
|
+
Warnings:
|
50
|
+
#{warnings.join("\n ")}
|
51
|
+
~~~
|
52
|
+
EOF
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
# Construct a new instance from a hash
|
57
|
+
# @param hash a file operation repsonse hash
|
58
|
+
# @return [RepositoryFileError] new error
|
59
|
+
# @return [nil] if error is not applicable (hash has empty FailedFiles
|
60
|
+
# array)
|
61
|
+
def from_hash(hash, *args)
|
62
|
+
return nil if hash['FailedFiles'].empty?
|
63
|
+
new(hash['FailedFiles'], hash['Report']['Warnings'], *args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/aptly/files.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Aptly
|
2
|
+
# Aptly files management.
|
3
|
+
# @see http://www.aptly.info/doc/api/files/
|
4
|
+
class Files
|
5
|
+
class << self
|
6
|
+
# Upload files to remote
|
7
|
+
# @param files [Array<String>] paths to files to upload
|
8
|
+
# @param directory [String] name of the directory to upload to.
|
9
|
+
# @param connection [Connection] connection to use
|
10
|
+
# @return [Array<String>] list of files now on the remote
|
11
|
+
def upload(files, directory, connection = Connection.new, **kwords)
|
12
|
+
i = 0
|
13
|
+
files.each do |f|
|
14
|
+
kwords["file_#{i += 1}".to_sym] = f
|
15
|
+
end
|
16
|
+
response = connection.send(:post, "/files/#{directory}",
|
17
|
+
kwords)
|
18
|
+
JSON.parse(response.body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
require_relative 'representation'
|
4
|
+
|
5
|
+
module Aptly
|
6
|
+
# A published repository representation.
|
7
|
+
# Published repositories are not {Repository} instances as they are in fact
|
8
|
+
# comprised of one or more different repositories.
|
9
|
+
# @see http://www.aptly.info/doc/api/publish/
|
10
|
+
class PublishedRepository < Representation
|
11
|
+
def initialize(*args)
|
12
|
+
super(*args)
|
13
|
+
self.Sources.collect! { |s| Repository.new(connection, s) }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Drops a published repository. This removes the published repository
|
17
|
+
# but leaves its soures intact.
|
18
|
+
def drop(**kwords)
|
19
|
+
connection.send(:delete, "/publish/#{self.Prefix}/#{self.Distribution}",
|
20
|
+
query: kwords)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Update this published repository using new contents of Sources
|
24
|
+
# @note this possibly mutates the attributes depending on the HTTP response
|
25
|
+
# @return [self] if the instance data was mutated
|
26
|
+
# @return [nil] if the instance data was not mutated
|
27
|
+
def update!(**kwords)
|
28
|
+
response = connection.send(:put,
|
29
|
+
"/publish/#{self.Prefix}/#{self.Distribution}",
|
30
|
+
body: JSON.generate(kwords))
|
31
|
+
hash = JSON.parse(response.body)
|
32
|
+
return nil if hash == marshal_dump
|
33
|
+
marshal_load(hash)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# List all published repositories.
|
39
|
+
# @return [Array<PublishedRepository>] list of repositories
|
40
|
+
def list(connection = Connection.new, **kwords)
|
41
|
+
kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
42
|
+
response = connection.send(:get, '/publish',
|
43
|
+
query: kwords)
|
44
|
+
JSON.parse(response.body).collect { |h| new(connection, h) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
require_relative 'errors'
|
5
|
+
require_relative 'representation'
|
6
|
+
|
7
|
+
module Aptly
|
8
|
+
# Aptly repository representation.
|
9
|
+
# @see http://www.aptly.info/doc/api/repos/
|
10
|
+
class Repository < Representation
|
11
|
+
# Delete this repository.
|
12
|
+
def delete(**kwords)
|
13
|
+
connection.send(:delete, "/repos/#{self.Name}", query: kwords)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add a previously uploaded file to the Repository.
|
17
|
+
# @return [Hash] report data as specified in the API.
|
18
|
+
# FIXME: this should be called file
|
19
|
+
def add_file(path, **kwords)
|
20
|
+
response = connection.send(:post, "/repos/#{self.Name}/file/#{path}",
|
21
|
+
query: kwords)
|
22
|
+
hash = JSON.parse(response.body)
|
23
|
+
error = Errors::RepositoryFileError.from_hash(hash)
|
24
|
+
fail error if error
|
25
|
+
hash['Report']['Added']
|
26
|
+
end
|
27
|
+
|
28
|
+
# FIXME: needs to support single files
|
29
|
+
# Convenience wrapper around {Files.upload} and {#add_file}
|
30
|
+
def upload(files)
|
31
|
+
prefix = "#{self.class.to_s.tr(':', '_')}-#{Socket.gethostname}-"
|
32
|
+
directory = Dir::Tmpname.make_tmpname(prefix, nil)
|
33
|
+
Files.upload(files, directory, connection)
|
34
|
+
add_file(directory)
|
35
|
+
ensure
|
36
|
+
# FIXME: delete dir?
|
37
|
+
end
|
38
|
+
|
39
|
+
# List all packages in the repository
|
40
|
+
# @return [Array<String>] list of packages in the repository
|
41
|
+
def packages(**kwords)
|
42
|
+
response = connection.send(:get, "/repos/#{self.Name}/packages",
|
43
|
+
query: kwords)
|
44
|
+
JSON.parse(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Convenience wrapper around {Aptly.publish}, publishing this repository
|
48
|
+
# locally and as only source of prefix.
|
49
|
+
# @param prefix [String] prefix to publish under (i.e. published repo name)
|
50
|
+
# @return [PublishedRepository] newly published repository
|
51
|
+
def publish(prefix, **kwords)
|
52
|
+
Aptly.publish([{ Name: self.Name }], prefix, 'local', kwords)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean]
|
56
|
+
def published?
|
57
|
+
!published_in.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
# Lists all PublishedRepositories self is published in. Namely self must
|
61
|
+
# be a source of the published repository in order for it to appear here.
|
62
|
+
# This method always returns an array of affected published repositories.
|
63
|
+
# If you use this method with a block it will additionally yield each
|
64
|
+
# published repository that would appear in the array, making it a shorthand
|
65
|
+
# for {Array#each}.
|
66
|
+
# @yieldparam pub [PublishedRepository]
|
67
|
+
# @return [Array<PublishedRepository>]
|
68
|
+
def published_in
|
69
|
+
Aptly::PublishedRepository.list(connection).select do |pub|
|
70
|
+
pub.Sources.each do |src|
|
71
|
+
next false unless src.Name == self.Name
|
72
|
+
yield repo if block_given?
|
73
|
+
true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class << self
|
79
|
+
# Get a {Repository} instance if the repository already exists.
|
80
|
+
# @param name [String] name of the repository
|
81
|
+
# @param connection [Connection] connection to use for the instance
|
82
|
+
# @return {Repository} instance if it exists
|
83
|
+
def get(name, connection = Connection.new, **kwords)
|
84
|
+
kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
85
|
+
response = connection.send(:get, "/repos/#{name}",
|
86
|
+
query: kwords)
|
87
|
+
new(connection, JSON.parse(response.body))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Creates a new {Repository}
|
91
|
+
# @param name [String] name fo the repository
|
92
|
+
# @param connection [Connection] connection to use for the instance
|
93
|
+
# @return {Repository} newly created instance
|
94
|
+
def create(name, connection = Connection.new, **kwords)
|
95
|
+
options = kwords.merge(name: name)
|
96
|
+
options = options.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
97
|
+
response = connection.send(:post, '/repos',
|
98
|
+
body: JSON.generate(options))
|
99
|
+
new(connection, JSON.parse(response.body))
|
100
|
+
end
|
101
|
+
|
102
|
+
# Check if a repository exists.
|
103
|
+
# @param name [String] the name of the repository which might exist
|
104
|
+
# @param connection [Connection] connection to use for the instance
|
105
|
+
# @return [Boolean] whether or not the repositoryexists
|
106
|
+
def exist?(name, connection = Connection.new, **kwords)
|
107
|
+
get(name, connection, **kwords)
|
108
|
+
true
|
109
|
+
rescue Aptly::Errors::NotFoundError
|
110
|
+
false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Aptly
|
2
|
+
# Base representation class to coerce transactional types into useful
|
3
|
+
# objects.
|
4
|
+
class Representation < OpenStruct
|
5
|
+
# @!attribute connection
|
6
|
+
# @return [Connection] the connection used for instance operations
|
7
|
+
attr_accessor :connection
|
8
|
+
|
9
|
+
# Initialize a new representation
|
10
|
+
# @param connection [Connection] connection to use for instance operations
|
11
|
+
# @param hash [Hash] native hash to represent
|
12
|
+
def initialize(connection, hash = {})
|
13
|
+
@connection = connection
|
14
|
+
super(hash)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aptly-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harald Sitter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake-notes
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.11'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.22'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.22'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: faraday
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
description: REST client for the Aptly API
|
140
|
+
email:
|
141
|
+
- sitter@kde.org
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
|
+
- CODE_OF_CONDUCT.md
|
149
|
+
- COPYING.lib
|
150
|
+
- Gemfile
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- TODO
|
154
|
+
- aptly-api.gemspec
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- lib/aptly.rb
|
158
|
+
- lib/aptly/configuration.rb
|
159
|
+
- lib/aptly/connection.rb
|
160
|
+
- lib/aptly/errors.rb
|
161
|
+
- lib/aptly/files.rb
|
162
|
+
- lib/aptly/publish.rb
|
163
|
+
- lib/aptly/repository.rb
|
164
|
+
- lib/aptly/representation.rb
|
165
|
+
- lib/aptly/version.rb
|
166
|
+
homepage: https://github.com/KDEJewellers/aptly-api/
|
167
|
+
licenses:
|
168
|
+
- LGPL-3.0
|
169
|
+
metadata: {}
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 2.4.6
|
187
|
+
signing_key:
|
188
|
+
specification_version: 4
|
189
|
+
summary: REST client for the Aptly API
|
190
|
+
test_files: []
|
191
|
+
has_rdoc:
|