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

Add Certificate Manager, RDS for MariaDB, RDS for MySQL resources #26

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ local-conf.yml
.venv/
.venv.nosync/
.DS_Store
/test/
15 changes: 15 additions & 0 deletions managed_resource/schema/nhncloud_app_key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ schema:
- app_key
- email_secret_key
- push_secret_key
- certificate_app_key
- user_access_key_id
- secret_access_key
properties:
app_key:
format: password
Expand All @@ -20,6 +23,18 @@ schema:
format: password
title: Push Secret Key
type: string
certificate_app_key:
format: password
title: Certificate App Key
type: string
user_access_key_id:
format: password
title: User Access Key ID
type: string
secret_access_key:
format: password
title: Secret Access Key
type: string
required:
- app_key
type: object
Expand Down
Empty file.
44 changes: 44 additions & 0 deletions src/plugin/connector/certificate_manager/certificate_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
import requests

from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class CertificateConnector(NHNCloudBaseConnector):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_certificates(app_key, user_access_key_id, secret_access_key) -> list:
certificates = []
current_page = 1

while True:
response = requests.get(
f"https://certmanager.api.nhncloudservice.com/certmanager/v1.1/appkeys/{app_key}/certificates",
headers={
"Content-Type": "application/json",
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
},
params={
"pageNum": current_page,
"pageSize": 10 # defalut
})

response_data = response.json()
data = response_data['body']['data']

if not data:
break

certificates.extend(data)
current_page += 1
total_pages = response_data['body']['totalPage']

if current_page > total_pages:
break

return certificates
Empty file.
40 changes: 40 additions & 0 deletions src/plugin/connector/rds_for_mariadb/backup_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class BackupConnector(NHNCloudBaseConnector):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_backups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
backups = []
idx = 1
while True:
response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/backups?page={idx}&size=10",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get Backups. {response.json()}")
raise Exception(f"Failed to get Backups. {response.json()}")


if not response.json()['backups']:
break

backups.extend(response.json()['backups'])
idx += 1

return backups
33 changes: 33 additions & 0 deletions src/plugin/connector/rds_for_mariadb/db_instance_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class DBInstanceConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_db_instances(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
db_instances = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/db-instances",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get db instances. {response.json()}")
raise Exception(f"Failed to get db instances. {response.json()}")

db_instances.extend(response.json()['dbInstances'])

return db_instances
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class DBInstanceGroupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_db_instance_groups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
db_instance_groups = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/db-instance-groups",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get db instance groups. {response.json()}")
raise Exception(f"Failed to get db instance groups. {response.json()}")

db_instance_groups.extend(response.json()['dbInstanceGroups'])

return db_instance_groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class DBSecurityGroupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_db_security_groups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
db_security_groups = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/db-security-groups",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get db security groups. {response.json()}")
raise Exception(f"Failed to get db security groups. {response.json()}")

db_security_groups.extend(response.json()['dbSecurityGroups'])

return db_security_groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class NotificationGroupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_notification_groups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
notification_groups = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/notification-groups",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get notification groups. {response.json()}")
raise Exception(f"Failed to get notification groups. {response.json()}")

notification_groups.extend(response.json()['notificationGroups'])

return notification_groups
33 changes: 33 additions & 0 deletions src/plugin/connector/rds_for_mariadb/parameter_group_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class ParameterGroupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_parameter_groups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
parameter_groups = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/parameter-groups",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get parameter groups. {response.json()}")
raise Exception(f"Failed to get parameter groups. {response.json()}")

parameter_groups.extend(response.json()['parameterGroups'])

return parameter_groups
33 changes: 33 additions & 0 deletions src/plugin/connector/rds_for_mariadb/user_group_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class UserGroupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_user_groups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
user_groups = []

response = requests.get(
f"https://{region.name.lower()}-rds-mariadb.api.nhncloudservice.com/v3.0/user-groups",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get user groups. {response.json()}")
raise Exception(f"Failed to get user groups. {response.json()}")

user_groups.extend(response.json()['userGroups'])

return user_groups
Empty file.
39 changes: 39 additions & 0 deletions src/plugin/connector/rds_for_mysql/backup_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging

import requests

from plugin.conf.cloud_service_conf import REGION
from plugin.connector.base import NHNCloudBaseConnector

_LOGGER = logging.getLogger("cloudforet")

class BackupConnector(NHNCloudBaseConnector):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def list_backups(app_key, user_access_key_id, secret_access_key, region:REGION) -> list:
backups = []
idx = 1
while True:
response = requests.get(
f"https://{region.name.lower()}-rds-mysql.api.nhncloudservice.com/v3.0/backups?page={idx}&size=10",
headers={
"Content-Type": "application/json",
"X-TC-APP-KEY": app_key,
"X-TC-AUTHENTICATION-ID": user_access_key_id,
"X-TC-AUTHENTICATION-SECRET": secret_access_key
})

if response.status_code != 200 or response.json().get('header').get('isSuccessful') is False:
_LOGGER.error(f"Failed to get Backups. {response.json()}")
raise Exception(f"Failed to get Backups. {response.json()}")


if not response.json()['backups']:
break

backups.extend(response.json()['backups'])
idx += 1

return backups
Loading
Loading