aptly-api 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/aptly-api.gemspec +1 -3
- data/lib/aptly.rb +1 -0
- data/lib/aptly/configuration.rb +17 -1
- data/lib/aptly/connection.rb +8 -12
- data/lib/aptly/files.rb +8 -0
- data/lib/aptly/publish.rb +1 -1
- data/lib/aptly/repository.rb +29 -5
- data/lib/aptly/snapshot.rb +82 -0
- data/lib/aptly/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 626177bba4926b1d4edfe1229e5e334238cf61b4
|
4
|
+
data.tar.gz: 077010652f6d2059f85e647f89913ddbfcd23daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d07b75e5ba858305bf41f4e274db6c22a5a00f7f404dfd32b746cd5e91ae3abe41f20199a37481f3540f68091f9a10c65360dd16734a793495ff6e5d0d4b28
|
7
|
+
data.tar.gz: 9feb9b78522009ffbc8d980835d6a2b8165157cbf9e3c697ea5f6ec732a97e0d7e22c52918b052fa1b36b90084e8fa4eb33d564be80118243f206dc8fe7d9347
|
data/aptly-api.gemspec
CHANGED
@@ -14,9 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = 'https://github.com/KDEJewellers/aptly-api/'
|
15
15
|
spec.license = 'LGPL-3.0'
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject
|
18
|
-
f.match(%r{^(test|spec|features)/}) || f == 'lib/aptly/snapshot.rb'
|
19
|
-
end
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
18
|
spec.bindir = 'exe'
|
21
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
20
|
spec.require_paths = ['lib']
|
data/lib/aptly.rb
CHANGED
data/lib/aptly/configuration.rb
CHANGED
@@ -9,12 +9,28 @@ module Aptly
|
|
9
9
|
# @return [Integer] port to talk to host to on
|
10
10
|
attr_accessor :port
|
11
11
|
|
12
|
+
# @!attribute path
|
13
|
+
# @return [String] path to use (defaults to /)
|
14
|
+
attr_accessor :path
|
15
|
+
|
12
16
|
# Creates a new instance.
|
13
17
|
# @param host see {#host}
|
14
18
|
# @param port see {#port}
|
15
|
-
def initialize(host: 'localhost', port: 80)
|
19
|
+
def initialize(host: 'localhost', port: 80, path: '/')
|
16
20
|
@host = host
|
17
21
|
@port = port
|
22
|
+
@path = path
|
23
|
+
end
|
24
|
+
|
25
|
+
def uri
|
26
|
+
# FIXME: maybe we should simply configure a URI instead of configuring
|
27
|
+
# each part?
|
28
|
+
uri = URI.parse('')
|
29
|
+
uri.scheme = 'http'
|
30
|
+
uri.host = host
|
31
|
+
uri.port = port
|
32
|
+
uri.path = path
|
33
|
+
uri
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
data/lib/aptly/connection.rb
CHANGED
@@ -9,9 +9,9 @@ module Aptly
|
|
9
9
|
# This class wraps HTTP interactions for our purposes and adds general purpose
|
10
10
|
# automation on top of the raw HTTP actions.
|
11
11
|
class Connection
|
12
|
-
DEFAULT_QUERY = {}
|
13
|
-
GETISH_ACTIONS = %i(get delete)
|
14
|
-
POSTISH_ACTIONS = %i(post put)
|
12
|
+
DEFAULT_QUERY = {}.freeze
|
13
|
+
GETISH_ACTIONS = %i(get delete).freeze
|
14
|
+
POSTISH_ACTIONS = %i(post put).freeze
|
15
15
|
HTTP_ACTIONS = GETISH_ACTIONS + POSTISH_ACTIONS
|
16
16
|
|
17
17
|
CODE_ERRORS = {
|
@@ -20,16 +20,12 @@ module Aptly
|
|
20
20
|
404 => Errors::NotFoundError,
|
21
21
|
409 => Errors::ConflictError,
|
22
22
|
500 => Errors::ServerError
|
23
|
-
}
|
23
|
+
}.freeze
|
24
24
|
|
25
25
|
def initialize(**kwords)
|
26
26
|
@query = kwords.fetch(:query, DEFAULT_QUERY)
|
27
27
|
|
28
|
-
uri =
|
29
|
-
uri.scheme = 'http'
|
30
|
-
uri.host = ::Aptly.configuration.host
|
31
|
-
uri.port = ::Aptly.configuration.port
|
32
|
-
|
28
|
+
uri = ::Aptly.configuration.uri
|
33
29
|
@connection = Faraday.new(url: uri.to_s) do |c|
|
34
30
|
c.request :multipart
|
35
31
|
c.request :url_encoded
|
@@ -64,7 +60,7 @@ module Aptly
|
|
64
60
|
def mangle_post(body, headers, kwords)
|
65
61
|
if body
|
66
62
|
headers ||= {}
|
67
|
-
headers
|
63
|
+
headers['Content-Type'] = 'application/json'
|
68
64
|
else
|
69
65
|
kwords.each do |k, v|
|
70
66
|
if k.to_s.start_with?('file_')
|
@@ -104,10 +100,10 @@ module Aptly
|
|
104
100
|
elsif GETISH_ACTIONS.include?(action)
|
105
101
|
response = run_getish(action, path, kwords)
|
106
102
|
else
|
107
|
-
|
103
|
+
raise "Unknown http action: #{action}"
|
108
104
|
end
|
109
105
|
error = CODE_ERRORS.fetch(response.status, nil)
|
110
|
-
|
106
|
+
raise error, response.body if error
|
111
107
|
response
|
112
108
|
end
|
113
109
|
end
|
data/lib/aptly/files.rb
CHANGED
@@ -17,6 +17,14 @@ module Aptly
|
|
17
17
|
kwords)
|
18
18
|
JSON.parse(response.body)
|
19
19
|
end
|
20
|
+
|
21
|
+
# Delete files from remote's upload directory.
|
22
|
+
# @param path [String] path to delete (this may be a directory or a file)
|
23
|
+
# @return [nil]
|
24
|
+
def delete(path, connection = Connection.new, **kwords)
|
25
|
+
connection.send(:delete, "/files/#{path}", kwords)
|
26
|
+
nil
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/aptly/publish.rb
CHANGED
@@ -26,7 +26,7 @@ module Aptly
|
|
26
26
|
response = connection.send(:put,
|
27
27
|
"/publish/#{api_prefix}/#{self.Distribution}",
|
28
28
|
body: JSON.generate(kwords))
|
29
|
-
hash = JSON.parse(response.body)
|
29
|
+
hash = JSON.parse(response.body, symbolize_names: true)
|
30
30
|
return nil if hash == marshal_dump
|
31
31
|
marshal_load(hash)
|
32
32
|
self
|
data/lib/aptly/repository.rb
CHANGED
@@ -3,6 +3,7 @@ require 'tmpdir'
|
|
3
3
|
|
4
4
|
require_relative 'errors'
|
5
5
|
require_relative 'representation'
|
6
|
+
require_relative 'snapshot'
|
6
7
|
|
7
8
|
module Aptly
|
8
9
|
# Aptly repository representation.
|
@@ -21,19 +22,19 @@ module Aptly
|
|
21
22
|
query: kwords)
|
22
23
|
hash = JSON.parse(response.body)
|
23
24
|
error = Errors::RepositoryFileError.from_hash(hash)
|
24
|
-
|
25
|
+
raise error if error
|
25
26
|
hash['Report']['Added']
|
26
27
|
end
|
27
28
|
|
28
29
|
# FIXME: needs to support single files
|
29
|
-
# Convenience wrapper around {Files.upload}
|
30
|
+
# Convenience wrapper around {Files.upload}, {#add_file} and {Files.delete}
|
30
31
|
def upload(files)
|
31
32
|
prefix = "#{self.class.to_s.tr(':', '_')}-#{Socket.gethostname}-"
|
32
33
|
directory = Dir::Tmpname.make_tmpname(prefix, nil)
|
33
34
|
Files.upload(files, directory, connection)
|
34
35
|
add_file(directory)
|
35
36
|
ensure
|
36
|
-
|
37
|
+
Files.delete(directory, connection)
|
37
38
|
end
|
38
39
|
|
39
40
|
# List all packages in the repository
|
@@ -55,7 +56,7 @@ module Aptly
|
|
55
56
|
body: JSON.generate(PackageRefs: [*packages]))
|
56
57
|
self
|
57
58
|
end
|
58
|
-
|
59
|
+
alias add_packages add_package
|
59
60
|
|
60
61
|
# Deletes a package (by key) from the repository.
|
61
62
|
# @param packages [Array<String>, String] a list of package keys or
|
@@ -67,7 +68,7 @@ module Aptly
|
|
67
68
|
body: JSON.generate(PackageRefs: [*packages]))
|
68
69
|
self
|
69
70
|
end
|
70
|
-
|
71
|
+
alias delete_packages delete_package
|
71
72
|
|
72
73
|
# Convenience wrapper around {Aptly.publish}, publishing this repository
|
73
74
|
# locally and as only source of prefix.
|
@@ -100,6 +101,29 @@ module Aptly
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
104
|
+
# Edit this repository's attributes as per the parameters.
|
105
|
+
# @note this possibly mutates the attributes depending on the HTTP response
|
106
|
+
# @return [self] if the instance data was mutated
|
107
|
+
# @return [nil] if the instance data was not mutated
|
108
|
+
def edit!(**kwords)
|
109
|
+
response = connection.send(:put,
|
110
|
+
"/repos/#{self.Name}",
|
111
|
+
body: JSON.generate(kwords))
|
112
|
+
hash = JSON.parse(response.body, symbolize_names: true)
|
113
|
+
return nil if hash == marshal_dump
|
114
|
+
marshal_load(hash)
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
# Creates a new {Snapshot}
|
119
|
+
# @return {Snapshot} newly created instance
|
120
|
+
def snapshot(**kwords)
|
121
|
+
kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
122
|
+
response = connection.send(:post, "/repos/#{self.Name}/snapshots",
|
123
|
+
body: JSON.generate(kwords))
|
124
|
+
Aptly::Snapshot.new(::Aptly::Connection.new, JSON.parse(response.body))
|
125
|
+
end
|
126
|
+
|
103
127
|
class << self
|
104
128
|
# Get a {Repository} instance if the repository already exists.
|
105
129
|
# @param name [String] name of the repository
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative 'representation'
|
2
|
+
|
3
|
+
module Aptly
|
4
|
+
# Aptly snapshots representation.
|
5
|
+
# @see http://www.aptly.info/doc/api/snapshots/
|
6
|
+
class Snapshot < Representation
|
7
|
+
# Updates this snapshot
|
8
|
+
# @return [self] if the instance data was mutated
|
9
|
+
# @return [nil] if the instance data was not mutated
|
10
|
+
def update!(**kwords)
|
11
|
+
kwords = kwords.map { |k, v| [k.to_s.capitalize, v] }.to_h
|
12
|
+
response = @connection.send(:put,
|
13
|
+
"/snapshots/#{self.Name}",
|
14
|
+
body: JSON.generate(kwords))
|
15
|
+
hash = JSON.parse(response.body, symbolize_names: true)
|
16
|
+
return nil if hash == marshal_dump
|
17
|
+
marshal_load(hash)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delete's this snapshot
|
22
|
+
def delete(**kwords)
|
23
|
+
connection.send(:delete, "/snapshots/#{self.Name}",
|
24
|
+
query: kwords)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Find differences between this and another snapshot
|
28
|
+
# @param [Snapshot] to diff against
|
29
|
+
# @return [Array<Hash>] diff between the two snashots
|
30
|
+
def diff(other_snapshot)
|
31
|
+
endpoint = "/snapshots/#{self.Name}/diff/#{other_snapshot.Name}"
|
32
|
+
response = @connection.send(:get, endpoint)
|
33
|
+
JSON.parse(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Search for a package in this snapshot
|
37
|
+
# @return [Array<String>] list of packages found
|
38
|
+
def packages(**kwords)
|
39
|
+
response = connection.send(:get, "/snapshots/#{self.Name}/packages",
|
40
|
+
query: kwords,
|
41
|
+
query_mangle: false)
|
42
|
+
JSON.parse(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Convenience wrapper around {Aptly.publish}, publishing this snapshot
|
46
|
+
# locally and as only source of prefix.
|
47
|
+
# @param prefix [String] prefix to publish under (i.e. published snapshot name)
|
48
|
+
# @return [PublishedRepository] newly published repository
|
49
|
+
def publish(prefix, **kwords)
|
50
|
+
Aptly.publish([{ Name: self.Name }], prefix, 'snapshot', kwords)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
class << self
|
55
|
+
# List all known snapshots.
|
56
|
+
# @param connection [Connection] connection to use for the instance
|
57
|
+
# @return [Array<Snapshot>] all known snapshots
|
58
|
+
def list(connection = Connection.new, **kwords)
|
59
|
+
response = connection.send(:get, '/snapshots', query: kwords)
|
60
|
+
JSON.parse(response.body).collect { |r| new(connection, r) }
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a snapshot from package refs
|
64
|
+
# @param name [String] name of new snapshot
|
65
|
+
# @return [Snapshot] representation of new snapshot
|
66
|
+
def create(name, connection = Connection.new, **kwords)
|
67
|
+
kwords = kwords.merge(Name: name)
|
68
|
+
response = connection.send(:post, '/snapshots',
|
69
|
+
body: JSON.generate(kwords))
|
70
|
+
new(connection, JSON.parse(response.body))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Get a snapshot by name
|
74
|
+
# @param [String] name of snapshot to get
|
75
|
+
# @return [Snapshot] representation of snapshot if snapshot was found
|
76
|
+
def get(name, connection = Connection.new)
|
77
|
+
response = connection.send(:get, "/snapshots/#{name}")
|
78
|
+
new(connection, JSON.parse(response.body))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/aptly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptly-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harald Sitter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/aptly/publish.rb
|
163
163
|
- lib/aptly/repository.rb
|
164
164
|
- lib/aptly/representation.rb
|
165
|
+
- lib/aptly/snapshot.rb
|
165
166
|
- lib/aptly/version.rb
|
166
167
|
homepage: https://github.com/KDEJewellers/aptly-api/
|
167
168
|
licenses:
|