Skip to content

Commit

Permalink
feat: add digitalocean ACME Authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
t0b3 committed Jan 5, 2025
1 parent 6c1de36 commit 44fd7bc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/middlewared/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Build-Depends: alembic,
python3-croniter,
python3-cryptit,
python3-dbus,
python3-digitalocean,
python3-dnspython,
python3-docker,
python3-email-validator,
Expand Down Expand Up @@ -114,6 +115,7 @@ Depends: alembic,
python3-croniter,
python3-cryptit,
python3-dbus,
python3-digitalocean,
python3-dnspython,
python3-docker,
python3-email-validator,
Expand Down
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',
]


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


class DigitalOceanSchema(BaseModel):
authenticator: Literal['digitalocean']
api_token: Secret[NonEmptyString | None] = Field(default=None, description='API 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 @@ -82,7 +92,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.api_token = self.attributes.get('api_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.api_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 @@ -28,6 +29,7 @@ def get_authenticators(self):
auth_factory = AuthenticatorFactory()
for authenticator in [
CloudFlareAuthenticator,
DigitalOceanAuthenticator,
Route53Authenticator,
OVHAuthenticator,
ShellAuthenticator,
Expand Down

0 comments on commit 44fd7bc

Please sign in to comment.