This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from loyal812/feat/api-key-feat
Feat/api key feat
- Loading branch information
Showing
18 changed files
with
397 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
import os | ||
import gc | ||
import argparse | ||
from pathlib import Path | ||
|
||
from src.utils.read_json import read_json | ||
from src.mongodb.MongoDBClass import MongoDBClass | ||
from pathlib import Path | ||
|
||
def delete_api_key(args): | ||
""" | ||
main entry point | ||
""" | ||
|
||
# Payload | ||
payload_data = read_json(args.payload_dir) | ||
|
||
# Call class instance | ||
mongodb = MongoDBClass( | ||
db_name=payload_data["db_name"], | ||
collection_name=payload_data["collection_name"], | ||
mongo_uri=payload_data["mongo_uri"]) | ||
|
||
mongodb.check_validation_api(api_key=str(Path(args.api_key)), user=str(Path(args.user))) | ||
|
||
gc.collect() | ||
|
||
if __name__ == "__main__": | ||
""" | ||
Form command lines | ||
""" | ||
# Clean up buffer memory | ||
gc.collect() | ||
|
||
# Current directory | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Payload directory | ||
test_name = "regression_test013" | ||
payload_name = "mongodb_payload.json" | ||
payload_dir = os.path.join(current_dir, "test", "regression", test_name, "payload", payload_name) | ||
|
||
user = "user@gmail.com" | ||
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA" | ||
|
||
# Add options | ||
p = argparse.ArgumentParser() | ||
p = argparse.ArgumentParser(description="Translate text within an image.") | ||
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example") | ||
p.add_argument("--user", type=Path, default=user, help="user") | ||
p.add_argument("--api_key", type=Path, default=api_key, help="title") | ||
args = p.parse_args() | ||
|
||
delete_api_key(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
import os | ||
import gc | ||
import argparse | ||
from pathlib import Path | ||
from datetime import datetime | ||
|
||
from src.utils.read_json import read_json | ||
from src.mongodb.MongoDBClass import MongoDBClass | ||
from src.utils.utils import generate_api_key | ||
from src.models.api_model import APIModel | ||
from pathlib import Path | ||
|
||
def create_api_key(args): | ||
""" | ||
main entry point | ||
""" | ||
|
||
# Payload | ||
payload_data = read_json(args.payload_dir) | ||
|
||
# Call class instance | ||
mongodb = MongoDBClass( | ||
db_name=payload_data["db_name"], | ||
collection_name=payload_data["collection_name"], | ||
mongo_uri=payload_data["mongo_uri"]) | ||
|
||
api_key = generate_api_key() | ||
|
||
data:APIModel = { | ||
"user": str(Path(args.user)), | ||
"api": api_key, | ||
"title": str(Path(args.title)), | ||
"description": str(Path(args.description)), | ||
"is_removed": False, | ||
"created_at": datetime.now(), | ||
"updated_at": datetime.now(), | ||
} | ||
|
||
mongodb.create_api(data) | ||
|
||
gc.collect() | ||
|
||
if __name__ == "__main__": | ||
""" | ||
Form command lines | ||
""" | ||
# Clean up buffer memory | ||
gc.collect() | ||
|
||
# Current directory | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Payload directory | ||
test_name = "regression_test013" | ||
payload_name = "mongodb_payload.json" | ||
payload_dir = os.path.join(current_dir, "test", "regression", test_name, "payload", payload_name) | ||
|
||
user = "user@gmail.com" | ||
title = "title" | ||
description = "description" | ||
|
||
# Add options | ||
p = argparse.ArgumentParser() | ||
p = argparse.ArgumentParser(description="Translate text within an image.") | ||
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example") | ||
p.add_argument("--user", type=Path, default=user, help="user") | ||
p.add_argument("--title", type=Path, default=title, help="title") | ||
p.add_argument("--description", type=Path, default=description, help="title") | ||
args = p.parse_args() | ||
|
||
create_api_key(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.