pdns-client 0.1.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 +7 -0
- data/.dockerignore +1 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/Dockerfile +15 -0
- data/Gemfile +4 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.local.yml +11 -0
- data/docker-compose.yml +31 -0
- data/docker/docker-entrypoint.sh +15 -0
- data/docker/pdns.api.conf +8 -0
- data/lib/pdns-client.rb +2 -0
- data/lib/pdns.rb +2 -0
- data/lib/pdns/client.rb +117 -0
- data/lib/pdns/client/error.rb +13 -0
- data/lib/pdns/client/version.rb +5 -0
- data/pdns-client.gemspec +28 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 100b3241c08e1c760231a4a2bfb746ae01edefbe7702c2a89c74ef543cf23ee8
|
4
|
+
data.tar.gz: 2b7babd54f1696f95eea60aa54b48a484dbdead5b02b8ab6723b06a5191bd2cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be825ef227acd339f702b271e09785eee5fb7c8e040cb708800711cb9ddea00f72f2d111120df1f87a9cbd1666dcca3f7c3f9b4bf2cd80d5ccf2d1e70caf6df2
|
7
|
+
data.tar.gz: f97e28a07bc5057a5d4d94a8b78aafa807c8d96b71f2215f582e08e02a763f6854b3672dabb7fbaf16e9f6bd143fb209acc38f358d2614fc97229200c2e811e6
|
data/.dockerignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Gemfile.lock
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
FROM ruby:2.5
|
2
|
+
|
3
|
+
RUN mkdir /usr/src/app
|
4
|
+
|
5
|
+
WORKDIR /usr/local/src
|
6
|
+
|
7
|
+
ADD docker/docker-entrypoint.sh /
|
8
|
+
ADD Gemfile pdns-client.gemspec ./
|
9
|
+
ADD lib/pdns/client/version.rb ./lib/pdns/client/version.rb
|
10
|
+
RUN bundle install --jobs=3 --retry=3
|
11
|
+
ADD . ./
|
12
|
+
|
13
|
+
ENTRYPOINT [ "/docker-entrypoint.sh" ]
|
14
|
+
|
15
|
+
CMD bundle exec rspec --force-color -fd spec
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Pdns::Client
|
2
|
+
|
3
|
+
This is a very thin wrapper over the PowerDNS REST API, providing just enough for OPF.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pdns-client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pdns-client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Example:
|
24
|
+
|
25
|
+
```
|
26
|
+
pdns = Pdns::Client.new(url: ENV.fetch("PDNS_SERVER_ROOT"), token: ENV.fetch("PDNS_SERVER_TOKEN"))
|
27
|
+
pdns.upsert_record("example.com", "www", "A", "172.16.0.1", 60)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
To run the tests in an isolated docker-compose graph:
|
37
|
+
|
38
|
+
```
|
39
|
+
docker-compose down --volumes --remove-orphans && \
|
40
|
+
docker-compose build test && \
|
41
|
+
docker-compose run test
|
42
|
+
```
|
43
|
+
|
44
|
+
To bring the PowerDNS REST API up on a local host port to run tests against it:
|
45
|
+
|
46
|
+
```
|
47
|
+
# Terminal 1
|
48
|
+
ln -s docker-compose.local.yml docker-compose.override.yml
|
49
|
+
docker-compose up pdns
|
50
|
+
|
51
|
+
# Terminal 2
|
52
|
+
export PDNS_SERVER_TOKEN=secret
|
53
|
+
export PDNS_SERVER_ROOT=http://localhost:8081/
|
54
|
+
bundle exec rspec -fd spec
|
55
|
+
```
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/webnifico/pdns-client.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pdns-client"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
version: '2.1'
|
2
|
+
|
3
|
+
services:
|
4
|
+
test:
|
5
|
+
build:
|
6
|
+
context: .
|
7
|
+
environment:
|
8
|
+
PDNS_SERVER_TOKEN: secret
|
9
|
+
PDNS_SERVER_ROOT: http://pdns:8081/
|
10
|
+
links:
|
11
|
+
- pdns
|
12
|
+
pdns:
|
13
|
+
image: psitrax/powerdns:4.1.0
|
14
|
+
restart: always
|
15
|
+
environment:
|
16
|
+
- MYSQL_HOST=db
|
17
|
+
- MYSQL_USER=root
|
18
|
+
- MYSQL_PASS=secret
|
19
|
+
volumes:
|
20
|
+
- ./docker/pdns.api.conf:/etc/pdns/conf.d/api.conf
|
21
|
+
depends_on:
|
22
|
+
- db
|
23
|
+
ports:
|
24
|
+
- 53
|
25
|
+
- "53/udp"
|
26
|
+
- 8080
|
27
|
+
- 8081
|
28
|
+
db:
|
29
|
+
image: mariadb:10.1
|
30
|
+
environment:
|
31
|
+
- MYSQL_ROOT_PASSWORD=secret
|
data/lib/pdns-client.rb
ADDED
data/lib/pdns.rb
ADDED
data/lib/pdns/client.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require "pdns/client/error"
|
2
|
+
require "http"
|
3
|
+
|
4
|
+
module Pdns
|
5
|
+
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def initialize(url:, token:, http: HTTP)
|
9
|
+
@url = url
|
10
|
+
@http = http
|
11
|
+
@token = token
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete_record(zone_name, lvalue, type)
|
15
|
+
unwrap {
|
16
|
+
http.patch(@url + "api/v1/servers/localhost/zones/#{zone_name}", json: {
|
17
|
+
"rrsets": [
|
18
|
+
{
|
19
|
+
"name": "#{lvalue}.#{zone_name}.",
|
20
|
+
"type": type,
|
21
|
+
"changetype": "DELETE",
|
22
|
+
"records": [],
|
23
|
+
}
|
24
|
+
]
|
25
|
+
})
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Only for testing
|
30
|
+
def create_zone(zone_name, nameserver_addresses)
|
31
|
+
unwrap {
|
32
|
+
http.post(@url + "api/v1/servers/localhost/zones", json: {
|
33
|
+
"kind": "Native",
|
34
|
+
"masters": [],
|
35
|
+
"id": "#{zone_name}",
|
36
|
+
"name": "#{zone_name}.",
|
37
|
+
"nameservers": nameserver_addresses,
|
38
|
+
"records": [
|
39
|
+
{
|
40
|
+
"content": "ns.#{zone_name}. hostmaster.#{zone_name}. 1 1800 900 604800 86400",
|
41
|
+
"disabled": false,
|
42
|
+
"name": "#{zone_name}.",
|
43
|
+
"ttl": 86400,
|
44
|
+
"type": "SOA"
|
45
|
+
},
|
46
|
+
]
|
47
|
+
})
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
# Only for testing
|
52
|
+
def delete_zone(zone_name)
|
53
|
+
unwrap { http.delete(@url + "api/v1/servers/localhost/zones/#{zone_name}") }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Only for testing
|
57
|
+
def get_zone(zone_name)
|
58
|
+
native = unwrap { http.get(@url + "api/v1/servers/localhost/zones/#{zone_name}") }
|
59
|
+
|
60
|
+
dapi_compatible = native["rrsets"].map { |rrset|
|
61
|
+
rrset["records"].map { |record|
|
62
|
+
{
|
63
|
+
"type" => rrset["type"],
|
64
|
+
"name" => rrset["name"].chomp(".#{zone_name}."),
|
65
|
+
"value" => record["content"],
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}.flatten
|
69
|
+
{"records" => dapi_compatible}
|
70
|
+
end
|
71
|
+
|
72
|
+
def upsert_record(zone_name, lvalue, type, rvalue, ttl = 60)
|
73
|
+
unwrap {
|
74
|
+
http.patch(@url + "api/v1/servers/localhost/zones/#{zone_name}", json: {
|
75
|
+
"rrsets": [
|
76
|
+
{
|
77
|
+
"name": "#{lvalue}.#{zone_name}.",
|
78
|
+
"type": type,
|
79
|
+
"ttl": ttl,
|
80
|
+
"changetype": "REPLACE",
|
81
|
+
"records": [
|
82
|
+
{
|
83
|
+
"content": rvalue,
|
84
|
+
"disabled": false,
|
85
|
+
"name": "#{lvalue}.#{zone_name}.",
|
86
|
+
"type": type,
|
87
|
+
"priority": 0
|
88
|
+
}
|
89
|
+
]
|
90
|
+
}
|
91
|
+
]
|
92
|
+
})
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def http
|
99
|
+
@http.headers("X-API-Key" => @token)
|
100
|
+
end
|
101
|
+
|
102
|
+
def unwrap(&block)
|
103
|
+
res = block.call
|
104
|
+
if [200, 201].include?(res.status)
|
105
|
+
JSON.parse(res.body)
|
106
|
+
elsif res.status == 204
|
107
|
+
{}
|
108
|
+
else
|
109
|
+
raise Pdns::Client::Error, "PowerDNS error: #{JSON.parse(res.body)["error"]}"
|
110
|
+
end
|
111
|
+
rescue JSON::ParserError
|
112
|
+
raise Pdns::Client::Error, "error parsing PowerDNS HTTP #{res.status} response (JSON)"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/pdns-client.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "pdns/client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "pdns-client"
|
7
|
+
spec.version = Pdns::Client::VERSION
|
8
|
+
spec.authors = ["Sheldon Hearn"]
|
9
|
+
spec.email = ["sheldonh@starjuice.net"]
|
10
|
+
|
11
|
+
spec.summary = %q{DNS API Client}
|
12
|
+
spec.description = %q{Client for PowerDNS REST API.}
|
13
|
+
spec.homepage = "https://github.com/webnifico/opf-manifold"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "http", "~> 4.1"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdns-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sheldon Hearn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
description: Client for PowerDNS REST API.
|
70
|
+
email:
|
71
|
+
- sheldonh@starjuice.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".dockerignore"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- Dockerfile
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- docker-compose.local.yml
|
86
|
+
- docker-compose.yml
|
87
|
+
- docker/docker-entrypoint.sh
|
88
|
+
- docker/pdns.api.conf
|
89
|
+
- lib/pdns-client.rb
|
90
|
+
- lib/pdns.rb
|
91
|
+
- lib/pdns/client.rb
|
92
|
+
- lib/pdns/client/error.rb
|
93
|
+
- lib/pdns/client/version.rb
|
94
|
+
- pdns-client.gemspec
|
95
|
+
homepage: https://github.com/webnifico/opf-manifold
|
96
|
+
licenses: []
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: DNS API Client
|
118
|
+
test_files: []
|