Skip to content

Commit

Permalink
Merge pull request #11 from DutchCodingCompany/v1
Browse files Browse the repository at this point in the history
V1
  • Loading branch information
dododedodonl authored Nov 7, 2023
2 parents 0760596 + c555df4 commit 2a0991d
Show file tree
Hide file tree
Showing 41 changed files with 512 additions and 460 deletions.
12 changes: 6 additions & 6 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
],
],
'trim_array_spaces' => true,
'types_spaces' => [
'space' => 'single',
],
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
Expand All @@ -188,12 +191,9 @@

$finder = Finder::create()
->in([
__DIR__.'/app',
__DIR__.'/config',
__DIR__.'/database',
__DIR__.'/resources',
__DIR__.'/routes',
__DIR__.'/tests',
__DIR__ . '/src',
__DIR__ . '/config',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to `laravel-hetzner-dns-api` will be documented in this file.

## 1.0.0 - 2023-11-07

### Changes
- renamed `\DutchCodingCompany\HetznerDnsClient\RequestCollections\RecordCollection` to `\DutchCodingCompany\HetznerDnsClient\Resources\RecordResource`
- renamed `\DutchCodingCompany\HetznerDnsClient\RequestCollections\ZoneCollection` to `\DutchCodingCompany\HetznerDnsClient\Resources\ZoneResource`
- removed `bensampo/laravel-enum` package, `\DutchCodingCompany\HetznerDnsClient\Enums\RecordType` is now a native enum
- dropped support for laravel 8.0
- added support for laravel 10.0
- removed `spatie/data-transfer-object`

## 0.1.0 - 2022-06-23

Initial release
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# An unofficial PHP SDK for the Hetzner DNS API.

[![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)
[![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)
[![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)
[![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)

This PHP/Laravel client around the [Hetzner DNS API](https://dns.hetzner.com/api-docs) support:
Expand All @@ -21,24 +19,36 @@ You can install the package via composer:
composer require dutchcodingcompany/laravel-hetzner-dns-api
```

Set your hetzner dns api token in your .env file:
```env
HETZNER_DNS_API_TOKEN=hetzner-dns-token-here
```

## Configuration (optional)
You can publish the config file with:

```bash
php artisan vendor:publish --tag="laravel-hetzner-dns-api-config"
php artisan vendor:publish --tag="hetzner-dns-api-config"
```

This is the contents of the published config file:

```php
return [
'api_token' => env('HETZNER_DNS_API_TOKEN')
];
```
This is the contents of the published config file [can be found here](config/hetzner-dns.php).

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`
```php
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use DutchCodingCompany\HetznerDnsClient\HetznerDnsClient;
HetznerDnsClient::resolveApiTokenUsing(fn () => 'your-token');

class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
HetznerDnsClient::resolveApiTokenUsing(fn () => 'your-token');
}
}
```

## Usage
Expand All @@ -49,18 +59,9 @@ $records = HetznerDnsClient::records()->all();
```

## ToDo
- Caching
- add caching
- ...

[//]: # (## Testing)

[//]: # ()
[//]: # (```bash)

[//]: # (composer test)

[//]: # (```)

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
"name": "Niek Brekelmans",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Tom Janssen",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"bensampo/laravel-enum": "^4.2|^5.3",
"illuminate/contracts": "^8.0|^9.0",
"sammyjo20/saloon-laravel": "^1.4",
"spatie/data-transfer-object": "^3.8",
"spatie/laravel-package-tools": "^1.9.2"
"php": "^8.1",
"illuminate/contracts": "^9.0 | ^10.0",
"saloonphp/saloon": "^3.0",
"spatie/laravel-package-tools": "^1.16.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.8",
Expand Down
3 changes: 2 additions & 1 deletion config/hetzner-dns.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// config for DutchCodingCompany/HetznerDnsClient
return [
'api_token' => env('HETZNER_DNS_API_TOKEN'),
Expand All @@ -7,5 +8,5 @@
env('HETZNER_NAMESERVER_1', 'hydrogen.ns.hetzner.com.'),
env('HETZNER_NAMESERVER_2', 'oxygen.ns.hetzner.com.'),
env('HETZNER_NAMESERVER_3', 'helium.ns.hetzner.de.'),
]
],
];
Empty file removed phpstan-baseline.neon
Empty file.
6 changes: 1 addition & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 4
level: 8
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
Expand Down
48 changes: 15 additions & 33 deletions src/Enums/RecordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,20 @@

namespace DutchCodingCompany\HetznerDnsClient\Enums;

use BenSampo\Enum\Enum;

/**
* @method static static A()
* @method static static AAAA()
* @method static static NS()
* @method static static MX()
* @method static static CNAME()
* @method static static RP()
* @method static static TXT()
* @method static static SOA()
* @method static static HINFO()
* @method static static SRV()
* @method static static DANE()
* @method static static TLSA()
* @method static static DS()
* @method static static CAA()
*/
final class RecordType extends Enum
enum RecordType: string
{
public const A = 'A';
public const AAAA = 'AAAA';
public const NS = 'NS';
public const MX = 'MX';
public const CNAME = 'CNAME';
public const RP = 'RP';
public const TXT = 'TXT';
public const SOA = 'SOA';
public const HINFO = 'HINFO';
public const SRV = 'SRV';
public const DANE = 'DANE';
public const TLSA = 'TLSA';
public const DS = 'DS';
public const CAA = 'CAA';
case A = 'A';
case AAAA = 'AAAA';
case NS = 'NS';
case MX = 'MX';
case CNAME = 'CNAME';
case RP = 'RP';
case TXT = 'TXT';
case SOA = 'SOA';
case HINFO = 'HINFO';
case SRV = 'SRV';
case DANE = 'DANE';
case TLSA = 'TLSA';
case DS = 'DS';
case CAA = 'CAA';
}
8 changes: 8 additions & 0 deletions src/Exceptions/HetznerDnsApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace DutchCodingCompany\HetznerDnsClient\Exceptions;

interface HetznerDnsApiException
{
//
}
10 changes: 10 additions & 0 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace DutchCodingCompany\HetznerDnsClient\Exceptions;

use InvalidArgumentException as BaseInvalidArgumentException;

class InvalidArgumentException extends BaseInvalidArgumentException implements HetznerDnsApiException
{
//
}
3 changes: 2 additions & 1 deletion src/Facades/HetznerDnsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DutchCodingCompany\HetznerDnsClient\Facades;

use DutchCodingCompany\HetznerDnsClient\HetznerDnsClient as Client;
use Illuminate\Support\Facades\Facade;

/**
Expand All @@ -11,6 +12,6 @@ class HetznerDnsClient extends Facade
{
protected static function getFacadeAccessor()
{
return 'laravel-hetzner-dns-api';
return Client::class;
}
}
45 changes: 29 additions & 16 deletions src/HetznerDnsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,56 @@

namespace DutchCodingCompany\HetznerDnsClient;

use DutchCodingCompany\HetznerDnsClient\Traits\ThrowsOnErrorsExceptNotFound;
use Sammyjo20\Saloon\Http\SaloonConnector;
use Sammyjo20\Saloon\Traits\Plugins\AcceptsJson;
use DutchCodingCompany\HetznerDnsClient\Resources\RecordResource;
use DutchCodingCompany\HetznerDnsClient\Resources\ZoneResource;
use Saloon\Http\Connector;
use Saloon\Traits\Plugins\AcceptsJson;

/**
* @method RequestCollections\ZoneCollection zones()
* @method RequestCollections\RecordCollection records()
*/
class HetznerDnsClient extends SaloonConnector
class HetznerDnsClient extends Connector
{
use AcceptsJson, ThrowsOnErrorsExceptNotFound;
use Traits\ThrowsOnErrorsExceptNotFound;
use Traits\ResolvesApiToken;

protected array $requests = [
'zones' => RequestCollections\ZoneCollection::class,
'records' => RequestCollections\RecordCollection::class,
];
use AcceptsJson;

/**
* The Base URL of the API.
*
* @return string
*/
public function defineBaseUrl(): string
public function resolveBaseUrl(): string
{
return 'https://dns.hetzner.com/api/v1';
}

/**
* The headers that will be applied to every request.
*
* @return string[]
* @return array<string, mixed>
*/
public function defaultHeaders(): array
{
return [
'Auth-API-Token' => self::getApiToken(),
];
}

/**
* Collection of methods for the zone resource.
*
* @return \DutchCodingCompany\HetznerDnsClient\Resources\ZoneResource
*/
public function zones(): ZoneResource
{
return new ZoneResource($this);
}

/**
* Collection of methods for the record resource.
*
* @return \DutchCodingCompany\HetznerDnsClient\Resources\RecordResource
*/
public function records(): RecordResource
{
return new RecordResource($this);
}
}
3 changes: 1 addition & 2 deletions src/HetznerDnsClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Illuminate\Contracts\Container\Container;

class HetznerDnsClientServiceProvider extends PackageServiceProvider
{
public function packageRegistered()
public function packageRegistered(): void
{
$this->app->singleton(HetznerDnsClient::class);
$this->app->alias(HetznerDnsClient::class, 'hetnzer-dns-client');
Expand Down
30 changes: 18 additions & 12 deletions src/Objects/BaseRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

namespace DutchCodingCompany\HetznerDnsClient\Objects;

use Carbon\Carbon;
use DutchCodingCompany\HetznerDnsClient\Enums\RecordType;
use Spatie\DataTransferObject\Attributes\DefaultCast;
use Spatie\DataTransferObject\DataTransferObject;

#[
DefaultCast(Carbon::class, Casters\CarbonCaster::class),
DefaultCast(RecordType::class, Casters\RecordTypeCaster::class),
]
class BaseRecord extends DataTransferObject
class BaseRecord
{
public RecordType $type;
public string $name;
public string $value;
public string $zone_id;
public function __construct(
public RecordType $type,
public string $name,
public string $value,
public string $zone_id,
) {
}

public static function fromArray(array $data): self
{
return new self(
type: RecordType::from($data['type']),
name: $data['name'],
value: $data['value'],
zone_id: $data['zone_id'],
);
}
}
Loading

0 comments on commit 2a0991d

Please sign in to comment.