Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from loyal812/feat/api-key-feat
Browse files Browse the repository at this point in the history
Feat/api key feat
  • Loading branch information
loyal812 authored Mar 27, 2024
2 parents 04555f8 + 6dab2fe commit 5d10d7b
Show file tree
Hide file tree
Showing 18 changed files with 397 additions and 120 deletions.
55 changes: 55 additions & 0 deletions check_api_key.py
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)
72 changes: 72 additions & 0 deletions create_api_key.py
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)
14 changes: 10 additions & 4 deletions mongodb.py → delete_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from src.utils.read_json import read_json
from src.mongodb.MongoDBClass import MongoDBClass
from pathlib import Path

def mongodb(args):
def delete_api_key(args):
"""
main entry point
"""
Expand All @@ -20,8 +21,8 @@ def mongodb(args):
db_name=payload_data["db_name"],
collection_name=payload_data["collection_name"],
mongo_uri=payload_data["mongo_uri"])
mongodb.mongo_connect()

mongodb.delete_api(api_key=str(Path(args.api_key)), user=str(Path(args.user)))

gc.collect()

Expand All @@ -40,10 +41,15 @@ def mongodb(args):
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()

mongodb(args)
delete_api_key(args)
Loading

0 comments on commit 5d10d7b

Please sign in to comment.