Skip to content
This repository was archived by the owner on Nov 4, 2025. It is now read-only.

Commit 626ccf8

Browse files
committed
Merge branch 'hetzner-dns' into 'master'
V1 of Client See merge request dcc-public-packages/laravel-hetzner-dns-client!1
2 parents 59060e5 + e2faa8d commit 626ccf8

33 files changed

+1055
-36
lines changed

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

README.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11

2-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1" />](https://supportukrainenow.org)
3-
42
# An unofficial PHP SDK for the Hetzner DNS API.
53

64
[![Latest Version on Packagist](https://img.shields.io/packagist/v/dutchcodingcompany/laravel-hetzner-dns-api.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/laravel-hetzner-dns-api)
75
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/dutchcodingcompany/laravel-hetzner-dns-api/run-tests?label=tests)](https://github.com/dutchcodingcompany/laravel-hetzner-dns-api/actions?query=workflow%3Arun-tests+branch%3Amain)
86
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/dutchcodingcompany/laravel-hetzner-dns-api/Check%20&%20fix%20styling?label=code%20style)](https://github.com/dutchcodingcompany/laravel-hetzner-dns-api/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
97
[![Total Downloads](https://img.shields.io/packagist/dt/dutchcodingcompany/laravel-hetzner-dns-api.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/laravel-hetzner-dns-api)
108

11-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
12-
13-
## Support us
9+
This PHP/Laravel client around the [Hetzner DNS API](https://dns.hetzner.com/api-docs) support:
10+
- Zones
11+
- Records
1412

15-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-hetzner-dns-api.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-hetzner-dns-api)
13+
This SDK is based on [Saloon](https://docs.saloon.dev/), a Laravel / PHP package that helps write API integrations and SDKs.
1614

17-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
18-
19-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
2015

2116
## Installation
2217

@@ -26,13 +21,6 @@ You can install the package via composer:
2621
composer require dutchcodingcompany/laravel-hetzner-dns-api
2722
```
2823

29-
You can publish and run the migrations with:
30-
31-
```bash
32-
php artisan vendor:publish --tag="laravel-hetzner-dns-api-migrations"
33-
php artisan migrate
34-
```
35-
3624
You can publish the config file with:
3725

3826
```bash
@@ -43,44 +31,52 @@ This is the contents of the published config file:
4331

4432
```php
4533
return [
34+
'api_token' => env('HETZNER_DNS_API_TOKEN')
4635
];
4736
```
4837

49-
Optionally, you can publish the views using
50-
51-
```bash
52-
php artisan vendor:publish --tag="laravel-hetzner-dns-api-views"
38+
If you would like to store the API Token outside of the config (e.g. encrypted in the database), you can override the resolver in the `boot` method of the `AppServiceProvider`
39+
```php
40+
use DutchCodingCompany\HetznerDnsClient\HetznerDnsClient;
41+
HetznerDnsClient::resolveApiTokenUsing(fn () => 'your-token');
5342
```
5443

5544
## Usage
5645

5746
```php
58-
$hetznerDnsClient = new DutchCodingCompany\HetznerDnsClient();
59-
echo $hetznerDnsClient->echoPhrase('Hello, DutchCodingCompany!');
47+
$records = HetznerDnsClient::records()->all();
48+
// resolves to a Records DTO
6049
```
6150

62-
## Testing
51+
## ToDo
52+
- Caching
53+
- ...
6354

64-
```bash
65-
composer test
66-
```
55+
[//]: # (## Testing)
56+
57+
[//]: # ()
58+
[//]: # (```bash)
59+
60+
[//]: # (composer test)
61+
62+
[//]: # (```)
6763

6864
## Changelog
6965

7066
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
7167

7268
## Contributing
7369

74-
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
70+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
7571

7672
## Security Vulnerabilities
7773

7874
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
7975

8076
## Credits
8177

82-
- [Niek Brekelmans](https://github.com/niek)
83-
- [All Contributors](../../contributors)
78+
- [Niek Brekelmans](https://github.com/niekbr)
79+
- [All Contributors](../../graphs/hetzner-dns)
8480

8581
## License
8682

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
],
1818
"require": {
1919
"php": "^8.0",
20+
"bensampo/laravel-enum": "^4.2|^5.3",
2021
"illuminate/contracts": "^8.0|^9.0",
2122
"sammyjo20/saloon-laravel": "^1.4",
23+
"spatie/data-transfer-object": "^3.8",
2224
"spatie/laravel-package-tools": "^1.9.2"
2325
},
2426
"require-dev": {

config/hetzner-dns.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
// config for DutchCodingCompany/HetznerDnsClient
33
return [
4-
'api_token' => env('HETZNER_DNS_API_TOKEN')
4+
'api_token' => env('HETZNER_DNS_API_TOKEN'),
5+
'default_ttl' => env('HETZNER_DNS_DEFAULT_TTL', 300),
56
];

src/Enums/RecordType.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace DutchCodingCompany\HetznerDnsClient\Enums;
4+
5+
use BenSampo\Enum\Enum;
6+
7+
/**
8+
* @method static static A()
9+
* @method static static AAAA()
10+
* @method static static NS()
11+
* @method static static MX()
12+
* @method static static CNAME()
13+
* @method static static RP()
14+
* @method static static TXT()
15+
* @method static static SOA()
16+
* @method static static HINFO()
17+
* @method static static SRV()
18+
* @method static static DANE()
19+
* @method static static TLSA()
20+
* @method static static DS()
21+
* @method static static CAA()
22+
*/
23+
final class RecordType extends Enum
24+
{
25+
public const A = 'A';
26+
public const AAAA = 'AAAA';
27+
public const NS = 'NS';
28+
public const MX = 'MX';
29+
public const CNAME = 'CNAME';
30+
public const RP = 'RP';
31+
public const TXT = 'TXT';
32+
public const SOA = 'SOA';
33+
public const HINFO = 'HINFO';
34+
public const SRV = 'SRV';
35+
public const DANE = 'DANE';
36+
public const TLSA = 'TLSA';
37+
public const DS = 'DS';
38+
public const CAA = 'CAA';
39+
}

src/HetznerDnsClient.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22

33
namespace DutchCodingCompany\HetznerDnsClient;
44

5-
class HetznerDnsClient
5+
use DutchCodingCompany\HetznerDnsClient\Traits\ThrowsOnErrorsExceptNotFound;
6+
use Sammyjo20\Saloon\Http\SaloonConnector;
7+
use Sammyjo20\Saloon\Traits\Plugins\AcceptsJson;
8+
9+
/**
10+
* @method RequestCollections\ZoneCollection zones()
11+
* @method RequestCollections\RecordCollection records()
12+
*/
13+
class HetznerDnsClient extends SaloonConnector
614
{
15+
use AcceptsJson, ThrowsOnErrorsExceptNotFound;
16+
use Traits\ResolvesApiToken;
17+
18+
protected array $requests = [
19+
'zones' => RequestCollections\ZoneCollection::class,
20+
'records' => RequestCollections\RecordCollection::class,
21+
];
22+
23+
/**
24+
* The Base URL of the API.
25+
*
26+
* @return string
27+
*/
28+
public function defineBaseUrl(): string
29+
{
30+
return 'https://dns.hetzner.com/api/v1';
31+
}
32+
33+
/**
34+
* The headers that will be applied to every request.
35+
*
36+
* @return string[]
37+
*/
38+
public function defaultHeaders(): array
39+
{
40+
return [
41+
'Auth-API-Token' => self::getApiToken(),
42+
];
43+
}
744
}

src/HetznerDnsClientServiceProvider.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
use Spatie\LaravelPackageTools\Package;
66
use Spatie\LaravelPackageTools\PackageServiceProvider;
7-
use DutchCodingCompany\HetznerDnsClient\Commands\HetznerDnsClientCommand;
7+
use Illuminate\Contracts\Container\Container;
88

99
class HetznerDnsClientServiceProvider extends PackageServiceProvider
1010
{
11+
public function packageRegistered()
12+
{
13+
$this->app->singleton(HetznerDnsClient::class);
14+
$this->app->alias(HetznerDnsClient::class, 'hetnzer-dns-client');
15+
}
16+
1117
public function configurePackage(Package $package): void
1218
{
1319
/*
@@ -17,9 +23,6 @@ public function configurePackage(Package $package): void
1723
*/
1824
$package
1925
->name('laravel-hetzner-dns-api')
20-
->hasConfigFile()
21-
->hasViews()
22-
->hasMigration('create_laravel-hetzner-dns-api_table')
23-
->hasCommand(HetznerDnsClientCommand::class);
26+
->hasConfigFile('hetzner-dns');
2427
}
2528
}

src/Objects/BaseRecord.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace DutchCodingCompany\HetznerDnsClient\Objects;
4+
5+
use Carbon\Carbon;
6+
use DutchCodingCompany\HetznerDnsClient\Enums\RecordType;
7+
use Spatie\DataTransferObject\Attributes\DefaultCast;
8+
use Spatie\DataTransferObject\DataTransferObject;
9+
10+
#[
11+
DefaultCast(Carbon::class, Casters\CarbonCaster::class),
12+
DefaultCast(RecordType::class, Casters\RecordTypeCaster::class),
13+
]
14+
class BaseRecord extends DataTransferObject
15+
{
16+
public RecordType $type;
17+
public string $name;
18+
public string $value;
19+
public string $zone_id;
20+
}

src/Objects/BulkCreatedRecords.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace DutchCodingCompany\HetznerDnsClient\Objects;
4+
5+
use Spatie\DataTransferObject\Attributes\CastWith;
6+
use Spatie\DataTransferObject\Casters\ArrayCaster;
7+
use Spatie\DataTransferObject\DataTransferObject;
8+
9+
class BulkCreatedRecords extends DataTransferObject
10+
{
11+
/** @var Record[] */
12+
#[CastWith(ArrayCaster::class, itemType: BaseRecord::class)]
13+
public array $invalid_records;
14+
15+
/** @var Record[] */
16+
#[CastWith(ArrayCaster::class, itemType: Record::class)]
17+
public array $records;
18+
19+
/** @var Record[] */
20+
#[CastWith(ArrayCaster::class, itemType: BaseRecord::class)]
21+
public array $valid_records;
22+
}

src/Objects/BulkUpdatedRecords.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace DutchCodingCompany\HetznerDnsClient\Objects;
4+
5+
use Spatie\DataTransferObject\Attributes\CastWith;
6+
use Spatie\DataTransferObject\Casters\ArrayCaster;
7+
use Spatie\DataTransferObject\DataTransferObject;
8+
9+
class BulkUpdatedRecords extends DataTransferObject
10+
{
11+
/** @var Record[] */
12+
#[CastWith(ArrayCaster::class, itemType: BaseRecord::class)]
13+
public array $failed_records;
14+
15+
/** @var Record[] */
16+
#[CastWith(ArrayCaster::class, itemType: Record::class)]
17+
public array $records;
18+
}

0 commit comments

Comments
 (0)