Skip to content

Commit 7169ad6

Browse files
committed
LITE-27243 Limited allowed number of DBs per Account
1 parent 580bd13 commit 7169ad6

16 files changed

+92
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@
2323
* Added workload description and external link to docs
2424
* 0.3.2: Backend dependencies are bumped
2525
* 0.3.3: Removed limit of returned DB objects in DB List API
26+
* 0.4.0: Enhancements
27+
* DB Owner is shown in Databases API and Administrative UI
28+
* Max number of allowed DB per account can now be set via `DB_MAX_ALLOWED_NUMBER_PER_ACCOUNT` env variable
29+
* Frontend changes:
30+
* 400 and 422 server errors are better handled

dbaas/extension.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "DBaaS",
33
"description": "On-demand provisioning of cloud-based database storages as a service.",
4-
"version": "0.3.3",
4+
"version": "0.4.0",
55
"audience": ["reseller", "distributor", "vendor"],
6-
"readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/README.md",
7-
"changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/CHANGELOG.md",
6+
"readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.4.0/README.md",
7+
"changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.4.0/CHANGELOG.md",
88
"icon": "googleExtensionBaseline"
99
}

dbaas/services.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ async def create(
8888
if tech_contact['id'] != context.user_id:
8989
actor = await cls._get_actor(context, client)
9090

91+
await cls._validate_allowed_db_number_per_account(db, context, config)
92+
9193
prepared_db_doc = cls._prepare_db_document(data, context, region_doc, tech_contact, actor)
9294
inserted_db_doc = await cls._create_db_document(
9395
prepared_db_doc, db, context, client, config,
@@ -355,6 +357,25 @@ async def _get_validated_tech_contact(
355357

356358
return tech_contact
357359

360+
@classmethod
361+
async def _validate_allowed_db_number_per_account(
362+
cls,
363+
db: AsyncIOMotorDatabase,
364+
context: Context,
365+
config: dict,
366+
):
367+
if is_admin_context(context):
368+
return
369+
370+
max_allowed_number_of_db = int(config.get('DB_MAX_ALLOWED_NUMBER_PER_ACCOUNT', 50))
371+
372+
db_coll = db[cls.COLLECTION]
373+
current_number_of_db = await db_coll.count_documents(cls._default_query(context))
374+
if current_number_of_db + 1 > max_allowed_number_of_db:
375+
raise ValueError(
376+
f'Max allowed number of databases is reached: {max_allowed_number_of_db}.',
377+
)
378+
358379
@classmethod
359380
async def _get_actor(cls, context: Context, client: AsyncConnectClient) -> dict:
360381
actor = await ConnectAccountUser.retrieve(context.account_id, context.user_id, client)
@@ -461,7 +482,7 @@ def _db_collection_from_db_session(cls, db_session, config):
461482

462483
@staticmethod
463484
def _generate_id(config: dict) -> str:
464-
id_random_length = config.get('DB_ID_RANDOM_LENGTH', 5)
485+
id_random_length = int(config.get('DB_ID_RANDOM_LENGTH', 5))
465486
id_prefix = config.get('DB_ID_PREFIX', 'DBPG')
466487

467488
random_part = ''.join(random.choice(string.digits) for _ in range(id_random_length))

dbaas/static/7cace99224d3d55c5b00.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dbaas/static/9606f1a55fe0a2d35893.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dbaas/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<html><head><title>Lorem ipsum</title><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Mono:400,500|Material+Icons" rel="stylesheet"><link id="mock-favicon" rel="shortcut icon" href="#"><script defer="defer" src="9606f1a55fe0a2d35893.js"></script><link href="main.css" rel="stylesheet"></head><body><div id="app"></div></body></html>
1+
<html><head><title>Lorem ipsum</title><link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Mono:400,500|Material+Icons" rel="stylesheet"><link id="mock-favicon" rel="shortcut icon" href="#"><script defer="defer" src="7cace99224d3d55c5b00.js"></script><link href="main.css" rel="stylesheet"></head><body><div id="app"></div></body></html>

dbaas/static/main.css

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudblueconnect/eaas-database-extension",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"description": "On-demand provisioning of cloud-based database storages as a service.",
55
"author": "Ingram Micro",
66
"license": "Apache Software License 2.0",

0 commit comments

Comments
 (0)