Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
webomagic-auth
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Pratik Shrivastava
webomagic-auth
Commits
1dd3f4ed
Commit
1dd3f4ed
authored
Jul 14, 2024
by
deepdey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add web-api/update endpoint
parent
6a0c6b3c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
3 deletions
+105
-3
app/routes/web_api/__init__.py
app/routes/web_api/__init__.py
+32
-1
app/routes/web_api/web_api_dao_service.py
app/routes/web_api/web_api_dao_service.py
+31
-0
app/routes/web_api/web_api_payload.py
app/routes/web_api/web_api_payload.py
+19
-0
app/routes/web_api/web_api_response.py
app/routes/web_api/web_api_response.py
+10
-1
app/routes/web_api/web_api_validator.py
app/routes/web_api/web_api_validator.py
+13
-1
No files found.
app/routes/web_api/__init__.py
View file @
1dd3f4ed
...
...
@@ -25,7 +25,7 @@ ns = api.namespace(
@
ns
.
route
(
'/add'
,
methods
=
[
'POST'
])
class
Add
(
Resource
):
class
Add
WebApi
(
Resource
):
@
ns
.
doc
(
security
=
SECURITY
)
@
ns
.
expect
(
*
add_web_api_payload
())
...
...
@@ -50,6 +50,37 @@ class Add(Resource):
error
=
e
.
normalized_messages
()
)
except
Exception
as
e
:
logger
.
error
(
traceback
.
format_exc
())
return
prepare_api_response
(
EXCEPTION_CODE
,
str
(
e
))
@
ns
.
route
(
'/update'
,
methods
=
[
'PATCH'
])
class
UpdateWebApi
(
Resource
):
@
ns
.
doc
(
security
=
SECURITY
)
@
ns
.
expect
(
*
update_web_api_payload
())
@
ns
.
response
(
*
update_web_api_response
())
@
sanitized
()
def
patch
(
self
):
try
:
validator
=
UpdateWebApiValidator
()
payload
:
dict
=
validator
.
load
(
request
.
get_json
())
updated
:
bool
=
update_web_api
(
payload
)
if
not
updated
:
return
prepare_api_response
(
EXCEPTION_CODE
,
UPDATE_ERROR_MESSAGE
)
return
prepare_api_response
(
SUCCESS_CODE
,
UPDATE_SUCCESS_MESSAGE
)
except
ValidationError
as
e
:
return
prepare_api_response
(
VALIDATION_ERROR_CODE
,
VALIDATION_ERROR_MESSAGE
,
error
=
e
.
normalized_messages
(),
)
except
Exception
as
e
:
logger
.
error
(
traceback
.
format_exc
())
return
prepare_api_response
(
EXCEPTION_CODE
,
str
(
e
))
\ No newline at end of file
app/routes/web_api/web_api_dao_service.py
View file @
1dd3f4ed
...
...
@@ -22,8 +22,39 @@ def add_web_api(web_api_info: dict) -> int | None:
db
.
session
.
add
(
web_api_model
)
db
.
session
.
commit
()
# TODO: add new api entry to redis
return
web_api_model
.
id
except
Exception
as
e
:
db
.
session
.
rollback
()
raise
e
def
update_web_api
(
web_api_info
:
dict
)
->
bool
:
try
:
existing_web_api_info
:
ORM
.
Api
|
None
=
\
ORM
.
Api
.
query
.
filter_by
(
id
=
web_api_info
.
get
(
'id'
))
.
first
()
if
existing_web_api_info
is
None
:
return
False
old_endpoint
=
existing_web_api_info
.
get
(
'endpoint'
)
new_endpoint
=
web_api_info
.
get
(
'endpoint'
)
# TODO: delete old one from redis and add new one
if
existing_web_api_info
.
tag
!=
web_api_info
.
get
(
'tag'
):
# TODO: refresh redis api role mapping as a daemon job
pass
existing_web_api_info
.
endpoint
=
new_endpoint
existing_web_api_info
.
method
=
web_api_info
.
get
(
'method'
)
existing_web_api_info
.
tag
=
web_api_info
.
get
(
'tag'
)
db
.
session
.
commit
()
return
True
except
Exception
as
e
:
db
.
session
.
rollback
()
raise
e
\ No newline at end of file
app/routes/web_api/web_api_payload.py
View file @
1dd3f4ed
...
...
@@ -17,4 +17,23 @@ def add_web_api_payload() -> list:
},
)
return
[
payload
]
def
update_web_api_payload
()
->
list
:
payload
=
api
.
model
(
'updateWebApi Payload'
,
{
'id'
:
fields
.
Integer
(
required
=
True
),
'endpoint'
:
fields
.
String
(
required
=
True
),
'method'
:
fields
.
String
(
required
=
True
,
enum
=
ENDPOINT_METHODS
),
'tag'
:
fields
.
String
(
required
=
True
,
enum
=
ENDPOINT_TAGS
,
description
=
'`P` - No need to login | `V` - Need to login but no role check | `SU` Only accessable by *SUPER USERS* | `PA` - Only accesable by *PROJECT ADMIN and above* | `RA` - Only accesable by *PREVILAGED USERS and above*'
),
},
)
return
[
payload
]
\ No newline at end of file
app/routes/web_api/web_api_response.py
View file @
1dd3f4ed
...
...
@@ -8,5 +8,14 @@ def add_web_api_response() -> any:
return
prepare_swagger_response
(
code
=
SUCCESS_CODE
,
message
=
INSERT_SUCCESS_MESSAGE
,
model_name
=
'addUser Response'
model_name
=
'addWebApi Response'
)
def
update_web_api_response
()
->
any
:
return
prepare_swagger_response
(
code
=
SUCCESS_CODE
,
message
=
UPDATE_SUCCESS_MESSAGE
,
model_name
=
'updateWebApi Response'
)
\ No newline at end of file
app/routes/web_api/web_api_validator.py
View file @
1dd3f4ed
from
marshmallow
import
Schema
,
fields
,
validate
from
app.app_config.constant
import
ENDPOINT_METHODS
,
ENDPOINT_TAGS
...
...
@@ -13,3 +12,16 @@ class AddWebApiValidator(Schema):
required
=
True
,
validate
=
validate
.
OneOf
(
ENDPOINT_TAGS
),
)
class
UpdateWebApiValidator
(
Schema
):
id
=
fields
.
Integer
(
required
=
True
)
endpoint
=
fields
.
String
(
required
=
True
)
method
=
fields
.
String
(
required
=
True
,
validate
=
validate
.
OneOf
(
ENDPOINT_METHODS
)
)
tag
=
fields
.
String
(
required
=
True
,
validate
=
validate
.
OneOf
(
ENDPOINT_TAGS
),
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment