Skip to content

Commit c091785

Browse files
authored
feat: add digitalocean ACME Authenticator (#15315)
Closes: https://forums.truenas.com/t/add-digitalocean-as-acme-dns-authenicator/29879 Signed-off-by: Thomas Bettler <thomas.bettler@gmail.com>
1 parent 1c04c86 commit c091785

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎src/middlewared/middlewared/api/v25_04_0/acme_dns_authenticator.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'ACMEDNSAuthenticatorUpdateArgs', 'ACMEDNSAuthenticatorUpdateResult', 'ACMEDNSAuthenticatorDeleteArgs',
1515
'ACMEDNSAuthenticatorDeleteResult', 'ACMEDNSAuthenticatorSchemasArgs', 'ACMEDNSAuthenticatorSchemasResult',
1616
'ACMEDNSAuthenticatorPerformChallengeArgs', 'ACMEDNSAuthenticatorPerformChallengeResult', 'Route53SchemaArgs',
17-
'ACMECustomDNSAuthenticatorReturns', 'CloudFlareSchemaArgs', 'OVHSchemaArgs', 'ShellSchemaArgs',
17+
'ACMECustomDNSAuthenticatorReturns', 'CloudFlareSchemaArgs', 'DigitalOceanSchemaArgs', 'OVHSchemaArgs', 'ShellSchemaArgs',
1818
'TrueNASConnectSchemaArgs',
1919
]
2020

@@ -54,6 +54,16 @@ class CloudFlareSchemaArgs(CloudFlareSchema):
5454
pass
5555

5656

57+
class DigitalOceanSchema(BaseModel):
58+
authenticator: Literal['digitalocean']
59+
digitalocean_token: Secret[NonEmptyString] = Field(description='DigitalOcean Token')
60+
61+
62+
@single_argument_args('attributes')
63+
class DigitalOceanSchemaArgs(DigitalOceanSchema):
64+
pass
65+
66+
5767
class OVHSchema(BaseModel):
5868
authenticator: Literal['OVH']
5969
application_key: NonEmptyString = Field(description='OVH Application Key')
@@ -92,7 +102,7 @@ class ShellSchemaArgs(ShellSchema):
92102

93103

94104
AuthType: TypeAlias = Annotated[
95-
CloudFlareSchema | OVHSchema | Route53Schema | ShellSchema,
105+
CloudFlareSchema | DigitalOceanSchema | OVHSchema | Route53Schema | ShellSchema,
96106
Field(discriminator='authenticator')
97107
]
98108

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import logging
2+
3+
from certbot_dns_digitalocean._internal.dns_digitalocean import _DigitalOceanClient
4+
5+
from middlewared.api.current import DigitalOceanSchemaArgs
6+
7+
from .base import Authenticator
8+
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class DigitalOceanAuthenticator(Authenticator):
14+
15+
NAME = 'digitalocean'
16+
PROPAGATION_DELAY = 60
17+
SCHEMA_MODEL = DigitalOceanSchemaArgs
18+
19+
def initialize_credentials(self):
20+
self.digitalocean_token = self.attributes.get('digitalocean_token')
21+
22+
@staticmethod
23+
async def validate_credentials(middleware, data):
24+
return data
25+
26+
def _perform(self, domain, validation_name, validation_content):
27+
self.get_client().add_txt_record(domain, validation_name, validation_content, 600)
28+
29+
def get_client(self):
30+
return _DigitalOceanClient(self.digitalocean_token)
31+
32+
def _cleanup(self, domain, validation_name, validation_content):
33+
self.get_client().del_txt_record(domain, validation_name, validation_content)

‎src/middlewared/middlewared/plugins/acme_protocol_/authenticators/factory.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from middlewared.service_exception import CallError
44

55
from .cloudflare import CloudFlareAuthenticator
6+
from .digitalocean import DigitalOceanAuthenticator
67
from .ovh import OVHAuthenticator
78
from .route53 import Route53Authenticator
89
from .shell import ShellAuthenticator
@@ -29,6 +30,7 @@ def get_authenticators(self, include_internal=False):
2930
auth_factory = AuthenticatorFactory()
3031
for authenticator in [
3132
CloudFlareAuthenticator,
33+
DigitalOceanAuthenticator,
3234
Route53Authenticator,
3335
OVHAuthenticator,
3436
ShellAuthenticator,

0 commit comments

Comments
 (0)