hetzner_dns 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/.env.example +1 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/ci.yml +22 -0
- data/.gitignore +9 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/bin/console +21 -0
- data/bin/setup +8 -0
- data/hetzner_dns.gemspec +28 -0
- data/lib/hetzner_dns/client.rb +72 -0
- data/lib/hetzner_dns/collection.rb +25 -0
- data/lib/hetzner_dns/configuration.rb +9 -0
- data/lib/hetzner_dns/error.rb +4 -0
- data/lib/hetzner_dns/models/zone.rb +19 -0
- data/lib/hetzner_dns/object.rb +19 -0
- data/lib/hetzner_dns/version.rb +3 -0
- data/lib/hetzner_dns.rb +27 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f3de9b6eca1aee08bf8664fec0eaa99eff6a6004f49cc60ba271602231b01f7
|
4
|
+
data.tar.gz: 75ca7176c3a9197993e37fb4658c696763337838f65dd34df748bc1946de37d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4acd038b83002c03d1dbec9f3dbc2951a176aac943962a4aa25fa00f264f39ced2be446caadaaea3f77bb48a4be2d1f4f1bedf90c4eee241dc13db59a5522123
|
7
|
+
data.tar.gz: ae8c660e4262b0a0b38e2d07a2b9ff6c8dcb2bc80cdeb267c272c22ca00c598c7c4654ccb44e7c3fa53357be46d9a5a98eaba24aaae3cdd03d4bfab5a77d354a
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
HETZNER_DNS_TOKEN=
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
buy_me_a_coffee: deanpcmad
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: CI
|
2
|
+
on: push
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
strategy:
|
7
|
+
fail-fast: false
|
8
|
+
matrix:
|
9
|
+
ruby_version:
|
10
|
+
- 3.1
|
11
|
+
- 3.2
|
12
|
+
- 3.3
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby_version }}
|
18
|
+
bundler: default
|
19
|
+
bundler-cache: true
|
20
|
+
|
21
|
+
- name: Run tests
|
22
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hetzner_dns (0.1.0)
|
5
|
+
faraday (~> 2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
dotenv (2.7.6)
|
11
|
+
faraday (2.9.0)
|
12
|
+
faraday-net_http (>= 2.0, < 3.2)
|
13
|
+
faraday-net_http (3.1.0)
|
14
|
+
net-http
|
15
|
+
minitest (5.15.0)
|
16
|
+
net-http (0.4.1)
|
17
|
+
uri
|
18
|
+
rake (12.3.3)
|
19
|
+
uri (0.13.0)
|
20
|
+
vcr (6.2.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
dotenv
|
27
|
+
hetzner_dns!
|
28
|
+
minitest (~> 5.0)
|
29
|
+
rake (~> 12.0)
|
30
|
+
vcr
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
2.5.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Dean Perry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# HetznerDNS
|
2
|
+
|
3
|
+
HetznerDNS is a Ruby library for the Hetzner DNS API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "hetzner_dns"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Set Client Details
|
16
|
+
|
17
|
+
Firstly you'll need to create an API Token on [Hetzner DNS](https://dns.hetzner.com/settings/api-token) site
|
18
|
+
and then configure it like below.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
HetznerDNS.configure do |config|
|
22
|
+
config.api_token = ENV["HETZNER_DNS_TOKEN"]
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
### Zones
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Retrieve a list of Zone's
|
30
|
+
HetznerDNS::Zone.list
|
31
|
+
|
32
|
+
# Create a zone
|
33
|
+
# TTL is optional
|
34
|
+
HetznerDNS::Zone.create(name: "mydomain.com", ttl: 86400)
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/hetzner_dns.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hetzner_dns"
|
5
|
+
|
6
|
+
# Load environment variables from .env file
|
7
|
+
require 'dotenv/load'
|
8
|
+
|
9
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
+
# with your gem easier. You can also use a different console, if you like.
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
HetznerDNS.configure do |config|
|
17
|
+
config.api_token = ENV["HETZNER_DNS_TOKEN"]
|
18
|
+
end
|
19
|
+
|
20
|
+
require "irb"
|
21
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hetzner_dns.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/hetzner_dns/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "hetzner_dns"
|
5
|
+
spec.version = HetznerDNS::VERSION
|
6
|
+
spec.authors = ["Dean Perry"]
|
7
|
+
spec.email = ["dean@deanpcmad.com"]
|
8
|
+
|
9
|
+
spec.summary = "A Ruby library for the HetznerDNS API"
|
10
|
+
spec.homepage = "https://deanpcmad.com"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/hetzner_dns"
|
16
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency "faraday", "~> 2.0"
|
28
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module HetznerDNS
|
2
|
+
class Client
|
3
|
+
|
4
|
+
BASE_URL = "https://dns.hetzner.com/api/v1"
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def connection
|
9
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
10
|
+
conn.headers = {
|
11
|
+
"Auth-API-Token" => HetznerDNS.config.api_token,
|
12
|
+
"User-Agent" => "hetzner_dns/v#{VERSION} (github.com/deanpcmad/hetzner_dns)"
|
13
|
+
}
|
14
|
+
|
15
|
+
conn.request :json
|
16
|
+
|
17
|
+
conn.response :json, content_type: "application/json"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_request(url, params: {}, headers: {})
|
22
|
+
handle_response connection.get(url, params, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post_request(url, body: {}, headers: {})
|
26
|
+
handle_response connection.post(url, body, headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def put_request(url, body:, headers: {})
|
30
|
+
handle_response connection.put(url, body, headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def patch_request(url, body:, headers: {})
|
34
|
+
handle_response connection.patch(url, body, headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_request(url, headers: {})
|
38
|
+
handle_response connection.delete(url, headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
def handle_response(response)
|
42
|
+
case response.status
|
43
|
+
when 400
|
44
|
+
raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
|
45
|
+
when 401
|
46
|
+
raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["message"]}'"
|
47
|
+
when 403
|
48
|
+
raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["message"]}'"
|
49
|
+
when 404
|
50
|
+
raise Error, "Error 404: No results were found for your request. '#{response.body["message"]}'"
|
51
|
+
when 409
|
52
|
+
raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
|
53
|
+
when 422
|
54
|
+
raise Error, "Error 422: Unprocessable Content. '#{response.body["message"]}'"
|
55
|
+
when 429
|
56
|
+
raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["message"]}'"
|
57
|
+
when 500
|
58
|
+
raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["message"]}'"
|
59
|
+
when 503
|
60
|
+
raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["message"]}'"
|
61
|
+
when 501
|
62
|
+
raise Error, "Error 501: This resource has not been implemented. '#{response.body["message"]}'"
|
63
|
+
when 204
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module HetznerDNS
|
2
|
+
class Collection
|
3
|
+
attr_reader :data, :total
|
4
|
+
|
5
|
+
def self.from_response(response, type:, key: nil)
|
6
|
+
body = response.body
|
7
|
+
|
8
|
+
if key.is_a?(String)
|
9
|
+
data = body[key].map { |attrs| type.new(attrs) }
|
10
|
+
else
|
11
|
+
data = body.map { |attrs| type.new(attrs) }
|
12
|
+
end
|
13
|
+
|
14
|
+
new(
|
15
|
+
data: data,
|
16
|
+
total: body.count
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(data:, total:)
|
21
|
+
@data = data
|
22
|
+
@total = total
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module HetznerDNS
|
2
|
+
class Zone < Object
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def list
|
7
|
+
response = Client.get_request("zones")
|
8
|
+
Collection.from_response(response, type: Zone, key: "zones")
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(name:, ttl: nil)
|
12
|
+
response = Client.post_request("zones", body: { name: name, ttl: ttl })
|
13
|
+
Zone.new(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module HetznerDNS
|
4
|
+
class Object < OpenStruct
|
5
|
+
def initialize(attributes)
|
6
|
+
super to_ostruct(attributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ostruct(obj)
|
10
|
+
if obj.is_a?(Hash)
|
11
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
12
|
+
elsif obj.is_a?(Array)
|
13
|
+
obj.map { |o| to_ostruct(o) }
|
14
|
+
else # Assumed to be a primitive value
|
15
|
+
obj
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/hetzner_dns.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
require_relative "hetzner_dns/version"
|
4
|
+
|
5
|
+
module HetznerDNS
|
6
|
+
|
7
|
+
autoload :Configuration, "hetzner_dns/configuration"
|
8
|
+
autoload :Client, "hetzner_dns/client"
|
9
|
+
autoload :Collection, "hetzner_dns/collection"
|
10
|
+
autoload :Error, "hetzner_dns/error"
|
11
|
+
autoload :Object, "hetzner_dns/object"
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_writer :config
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(config) if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config
|
22
|
+
@config ||= HetznerDNS::Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
autoload :Zone, "hetzner_dns/models/zone"
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hetzner_dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Perry
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- dean@deanpcmad.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".env.example"
|
35
|
+
- ".github/FUNDING.yml"
|
36
|
+
- ".github/workflows/ci.yml"
|
37
|
+
- ".gitignore"
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- hetzner_dns.gemspec
|
46
|
+
- lib/hetzner_dns.rb
|
47
|
+
- lib/hetzner_dns/client.rb
|
48
|
+
- lib/hetzner_dns/collection.rb
|
49
|
+
- lib/hetzner_dns/configuration.rb
|
50
|
+
- lib/hetzner_dns/error.rb
|
51
|
+
- lib/hetzner_dns/models/zone.rb
|
52
|
+
- lib/hetzner_dns/object.rb
|
53
|
+
- lib/hetzner_dns/version.rb
|
54
|
+
homepage: https://deanpcmad.com
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
homepage_uri: https://deanpcmad.com
|
59
|
+
source_code_uri: https://github.com/deanpcmad/hetzner_dns
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.5.11
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A Ruby library for the HetznerDNS API
|
79
|
+
test_files: []
|