Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133594 / 25.04 / feat: add digitalocean ACME Authenticator #15315

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/middlewared/middlewared/api/v25_04_0/acme_dns_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'ACMEDNSAuthenticatorUpdateArgs', 'ACMEDNSAuthenticatorUpdateResult', 'ACMEDNSAuthenticatorDeleteArgs',
'ACMEDNSAuthenticatorDeleteResult', 'ACMEDNSAuthenticatorSchemasArgs', 'ACMEDNSAuthenticatorSchemasResult',
'ACMEDNSAuthenticatorPerformChallengeArgs', 'ACMEDNSAuthenticatorPerformChallengeResult', 'Route53SchemaArgs',
'ACMECustomDNSAuthenticatorReturns', 'CloudFlareSchemaArgs', 'OVHSchemaArgs', 'ShellSchemaArgs',
'ACMECustomDNSAuthenticatorReturns', 'CloudFlareSchemaArgs', 'DigitalOceanSchemaArgs', 'OVHSchemaArgs', 'ShellSchemaArgs',
'TrueNASConnectSchemaArgs',
]

Expand Down Expand Up @@ -54,6 +54,16 @@ class CloudFlareSchemaArgs(CloudFlareSchema):
pass


class DigitalOceanSchema(BaseModel):
authenticator: Literal['digitalocean']
digitalocean_token: Secret[NonEmptyString] = Field(description='DigitalOcean Token')


@single_argument_args('attributes')
class DigitalOceanSchemaArgs(DigitalOceanSchema):
pass


class OVHSchema(BaseModel):
authenticator: Literal['OVH']
application_key: NonEmptyString = Field(description='OVH Application Key')
Expand Down Expand Up @@ -92,7 +102,7 @@ class ShellSchemaArgs(ShellSchema):


AuthType: TypeAlias = Annotated[
CloudFlareSchema | OVHSchema | Route53Schema | ShellSchema,
CloudFlareSchema | DigitalOceanSchema | OVHSchema | Route53Schema | ShellSchema,
Field(discriminator='authenticator')
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

from certbot_dns_digitalocean._internal.dns_digitalocean import _DigitalOceanClient

from middlewared.api.current import DigitalOceanSchemaArgs

from .base import Authenticator


logger = logging.getLogger(__name__)


class DigitalOceanAuthenticator(Authenticator):

NAME = 'digitalocean'
PROPAGATION_DELAY = 60
SCHEMA_MODEL = DigitalOceanSchemaArgs

def initialize_credentials(self):
self.digitalocean_token = self.attributes.get('digitalocean_token')

@staticmethod
async def validate_credentials(middleware, data):
return data

def _perform(self, domain, validation_name, validation_content):
self.get_client().add_txt_record(domain, validation_name, validation_content, 600)

def get_client(self):
return _DigitalOceanClient(self.digitalocean_token)

def _cleanup(self, domain, validation_name, validation_content):
self.get_client().del_txt_record(domain, validation_name, validation_content)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from middlewared.service_exception import CallError

from .cloudflare import CloudFlareAuthenticator
from .digitalocean import DigitalOceanAuthenticator
from .ovh import OVHAuthenticator
from .route53 import Route53Authenticator
from .shell import ShellAuthenticator
Expand All @@ -29,6 +30,7 @@ def get_authenticators(self, include_internal=False):
auth_factory = AuthenticatorFactory()
for authenticator in [
CloudFlareAuthenticator,
DigitalOceanAuthenticator,
Route53Authenticator,
OVHAuthenticator,
ShellAuthenticator,
Expand Down