diff --git a/gcp_pilot/sql.py b/gcp_pilot/sql.py index b42860d..ee82ae1 100644 --- a/gcp_pilot/sql.py +++ b/gcp_pilot/sql.py @@ -2,6 +2,7 @@ import json import logging import time +import uuid from collections.abc import Generator from typing import Any @@ -22,7 +23,7 @@ class CloudSQL(DiscoveryMixin, GoogleCloudPilotAPI): def __init__(self, **kwargs): super().__init__( serviceName="sqladmin", - version="v1beta4", + version="v1", cache_discovery=False, **kwargs, ) @@ -153,5 +154,41 @@ def create_user(self, name: str, password: str, instance: str, project_id: str | body=body, ) + def create_ssl_cert(self, instance: str, project_id: str | None = None, ssl_name: str | None = None,) -> UserType: + body = dict( + commonName=ssl_name or uuid.uuid4().hex, + ) + return self._execute( + method=self.client.sslCerts().insert, + instance=instance, + project=project_id or self.project_id, + body=body, + ) + + def list_ssl_certs(self, instance: str, project_id: str | None = None) -> Generator[dict, None, None]: + params = dict( + instance=instance, + project=project_id or self.project_id, + ) + certs = self._paginate( + method=self.client.sslCerts().list, + params=params, + ) + yield from certs + + def delete_ssl_cert(self, instance: str, ssl_name: str, project_id: str | None = None, not_found_ok: bool = True) -> dict: + for cert in self.list_ssl_certs(instance=instance, project_id=project_id): + if cert["commonName"] != ssl_name: + continue + sha1_fingerprint = cert["sha1Fingerprint"] + return self._execute( + method=self.client.sslCerts().delete, + instance=instance, + sha1Fingerprint=sha1_fingerprint, + project=project_id or self.project_id, + ) + if not not_found_ok: + raise exceptions.NotFound() + __all__ = ("CloudSQL",) diff --git a/pyproject.toml b/pyproject.toml index ee6dfac..917ae93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "gcp-pilot" -version = "1.23.0" +version = "1.24.0" description = "Google Cloud Platform Friendly Pilot" authors = ["Joao Daher "] repository = "https://github.com/flamingo-run/gcp-pilot"