Skip to content

Commit

Permalink
feat: add support to CloudSQL certs
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodaher committed Mar 18, 2024
1 parent fd4f8b4 commit cce2a75
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion gcp_pilot/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import time
import uuid
from collections.abc import Generator
from typing import Any

Expand All @@ -22,7 +23,7 @@ class CloudSQL(DiscoveryMixin, GoogleCloudPilotAPI):
def __init__(self, **kwargs):
super().__init__(
serviceName="sqladmin",
version="v1beta4",
version="v1",
cache_discovery=False,
**kwargs,
)
Expand Down Expand Up @@ -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",)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <joao@daher.dev>"]
repository = "https://github.com/flamingo-run/gcp-pilot"
Expand Down

0 comments on commit cce2a75

Please sign in to comment.