-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more endpoints to sample service
- Loading branch information
Showing
9 changed files
with
253 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
ingestors/test_data/producers/ecommerce/edit_admin_config.py
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,44 @@ | ||
from datetime import datetime, timedelta | ||
from typing import List | ||
import json | ||
from random import randint | ||
|
||
from producers.ecommerce.utils import sources, destinations | ||
from producers.utils import get_auth_header, get_meta, JSON_HEADER | ||
from producers.base import BaseProducer | ||
|
||
|
||
class EcommerceEditAdminConfigProducer(BaseProducer): | ||
|
||
avg_emit_delta = timedelta(seconds=60) | ||
|
||
def get_data_points_helper(self) -> dict: | ||
resp = { | ||
"status": 200, | ||
"headers": [JSON_HEADER], | ||
"body": json.dumps({ | ||
"ok": True, | ||
}), | ||
} | ||
req_body = { | ||
"max_products": randint(100, 1000), | ||
"max_carts": randint(10000, 100000), | ||
"foo": "bar", | ||
} | ||
return { | ||
"request": { | ||
"url": { | ||
"host": "test-ecommerce.metlo.com", | ||
"path": "/admin/config", | ||
"parameters": [] | ||
}, | ||
"headers": [get_auth_header()], | ||
"method": "POST", | ||
"body": json.dumps(req_body), | ||
}, | ||
"response": resp, | ||
"meta": get_meta(sources, destinations), | ||
} | ||
|
||
def get_data_points(self, time: datetime) -> List[dict]: | ||
return [self.get_data_points_helper()] |
44 changes: 44 additions & 0 deletions
44
ingestors/test_data/producers/ecommerce/edit_product_price.py
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,44 @@ | ||
from datetime import datetime, timedelta | ||
from typing import List | ||
from uuid import uuid4 | ||
import json | ||
from random import randint | ||
|
||
from producers.ecommerce.utils import sources, destinations | ||
from producers.utils import get_auth_header, get_meta, JSON_HEADER | ||
from producers.base import BaseProducer | ||
|
||
|
||
class EcommerceEditProductPriceProducer(BaseProducer): | ||
|
||
avg_emit_delta = timedelta(seconds=30) | ||
|
||
def get_data_points_helper(self) -> dict: | ||
product_uuid = str(uuid4()) | ||
resp = { | ||
"status": 200, | ||
"headers": [JSON_HEADER], | ||
"body": json.dumps({ | ||
"ok": True, | ||
}), | ||
} | ||
req_body = { | ||
"price": randint(100, 1000), | ||
} | ||
return { | ||
"request": { | ||
"url": { | ||
"host": "test-ecommerce.metlo.com", | ||
"path": f"/product/{product_uuid}/price", | ||
"parameters": [] | ||
}, | ||
"headers": [get_auth_header()], | ||
"method": "POST", | ||
"body": json.dumps(req_body), | ||
}, | ||
"response": resp, | ||
"meta": get_meta(sources, destinations), | ||
} | ||
|
||
def get_data_points(self, time: datetime) -> List[dict]: | ||
return [self.get_data_points_helper()] |
40 changes: 40 additions & 0 deletions
40
ingestors/test_data/producers/ecommerce/get_admin_config.py
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,40 @@ | ||
from datetime import datetime, timedelta | ||
from typing import List | ||
import json | ||
from random import randint | ||
|
||
from producers.ecommerce.utils import sources, destinations | ||
from producers.utils import get_auth_header, get_meta, JSON_HEADER | ||
from producers.base import BaseProducer | ||
|
||
|
||
class EcommerceGetAdminConfigProducer(BaseProducer): | ||
|
||
avg_emit_delta = timedelta(seconds=60) | ||
|
||
def get_data_points_helper(self) -> dict: | ||
resp = { | ||
"status": 200, | ||
"headers": [JSON_HEADER], | ||
"body": json.dumps({ | ||
"max_products": randint(100, 1000), | ||
"max_carts": randint(10000, 100000), | ||
"foo": "bar", | ||
}), | ||
} | ||
return { | ||
"request": { | ||
"url": { | ||
"host": "test-ecommerce.metlo.com", | ||
"path": f"/admin/config", | ||
"parameters": [] | ||
}, | ||
"headers": [get_auth_header()], | ||
"method": "GET", | ||
}, | ||
"response": resp, | ||
"meta": get_meta(sources, destinations), | ||
} | ||
|
||
def get_data_points(self, time: datetime) -> List[dict]: | ||
return [self.get_data_points_helper()] |
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 |
---|---|---|
|
@@ -14,6 +14,28 @@ def main(backend, api_key): | |
print(r.text) | ||
return | ||
|
||
r = requests.post( | ||
f"{backend}/register", | ||
json={ | ||
"firstName": "Test 1", | ||
"lastName": "Admin User 1", | ||
"email": "[email protected]", | ||
"role": "admin", | ||
"address": fake.address(), | ||
"phoneNumber": fake.phone_number(), | ||
"dob": fake.date_of_birth().isoformat(), | ||
"password": fake.sentence(nb_words=5), | ||
}, | ||
headers=headers | ||
) | ||
if r.status_code > 300: | ||
print("Register Admin User 1") | ||
print(r.status_code) | ||
print(r.text) | ||
return | ||
admin_user_1 = r.json()['user'] | ||
admin_user_1_api_key = admin_user_1['apiKey'] | ||
|
||
r = requests.post( | ||
f"{backend}/register", | ||
json={ | ||
|
@@ -105,12 +127,19 @@ def main(backend, api_key): | |
actor User {{ | ||
items = [ | ||
{{ | ||
"uuid": "{admin_user_1['uuid']}", | ||
"role": "admin", | ||
"auth": "{admin_user_1['apiKey']}" | ||
}}, | ||
{{ | ||
"uuid": "{user_1['uuid']}", | ||
"role": "regular", | ||
"auth": "{user_1['apiKey']}" | ||
}}, | ||
{{ | ||
"uuid": "{user_2['uuid']}", | ||
"role": "regular", | ||
"auth": "{user_2['apiKey']}" | ||
}} | ||
] | ||
|
@@ -142,6 +171,23 @@ def main(backend, api_key): | |
] | ||
}} | ||
resource AdminAccess {{ | ||
permissions = ["read", "write"], | ||
endpoints = [ | ||
{{ | ||
"method": "GET", | ||
"path": "/admin/.*", | ||
"permissions": ["read"] | ||
}}, | ||
{{ | ||
"method": "POST", | ||
"path": "/admin/.*", | ||
"permissions": ["write"] | ||
}} | ||
] | ||
}} | ||
has_permission(User(role="admin"), [ "read", "write" ], AdminAccess) | ||
has_permission(User, [ "read" ], Product) | ||
has_permission(User(role="admin"), [ "write" ], Product) | ||
has_permission(User(uuid="{user_1['uuid']}"), [ "write" ], Product(uuid="{user_1_product}")) | ||
|
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,34 @@ | ||
import { FastifyReply, FastifyRequest } from "fastify" | ||
import ApiResponseHandler from "api-response-handler" | ||
import { Error401UnauthorizedRequest } from "errors" | ||
|
||
export const getAdminConfig = async ( | ||
req: FastifyRequest, | ||
res: FastifyReply, | ||
): Promise<void> => { | ||
try { | ||
await ApiResponseHandler.success(res, { | ||
max_products: 200, | ||
max_carts: 15000, | ||
foo: "bar", | ||
}) | ||
} catch (err) { | ||
await ApiResponseHandler.error(res, err) | ||
} | ||
} | ||
|
||
export const editAdminConfig = async ( | ||
req: FastifyRequest, | ||
res: FastifyReply, | ||
): Promise<void> => { | ||
try { | ||
if (req.user.role != "admin") { | ||
throw new Error401UnauthorizedRequest("No access") | ||
} | ||
await ApiResponseHandler.success(res, { | ||
ok: true, | ||
}) | ||
} catch (err) { | ||
await ApiResponseHandler.error(res, err) | ||
} | ||
} |
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
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
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