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
e556a6e6
Commit
e556a6e6
authored
Jul 14, 2024
by
deepdey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add `web-api/add` endpoint
parent
c491f760
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
134 additions
and
1 deletion
+134
-1
app/app_config/constant.py
app/app_config/constant.py
+3
-1
app/routes/web_api/__init__.py
app/routes/web_api/__init__.py
+55
-0
app/routes/web_api/web_api_dao_service.py
app/routes/web_api/web_api_dao_service.py
+29
-0
app/routes/web_api/web_api_payload.py
app/routes/web_api/web_api_payload.py
+20
-0
app/routes/web_api/web_api_response.py
app/routes/web_api/web_api_response.py
+12
-0
app/routes/web_api/web_api_validator.py
app/routes/web_api/web_api_validator.py
+15
-0
No files found.
app/app_config/constant.py
View file @
e556a6e6
ALPHANUMARIC_STRING
:
str
=
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
ALPHANUMARIC_STRING
:
str
=
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
ENDPOINT_TAGS
:
list
=
[
'P'
,
'V'
,
'SU'
,
'PV'
,
'RA'
]
ENDPOINT_METHODS
:
list
=
[
'GET'
,
'POST'
,
'PATCH'
,
'PUT'
,
'DELETE'
]
\ No newline at end of file
app/routes/web_api/__init__.py
0 → 100644
View file @
e556a6e6
import
os
import
traceback
from
flask
import
request
from
flask_restx
import
Resource
from
marshmallow
import
ValidationError
from
app.app_config.config
import
get_logger
from
app.app_config.response_code
import
*
from
app.app_config.response_message
import
*
from
app.app_config.swagger_config
import
SECURITY
from
app.decorators.sanitizer
import
sanitized
from
app.routes
import
api
from
app.routes.web_api.web_api_validator
import
*
from
app.routes.web_api.web_api_payload
import
*
from
app.routes.web_api.web_api_response
import
*
from
app.routes.web_api.web_api_dao_service
import
*
from
app.utils.api_response
import
prepare_api_response
logger
=
get_logger
(
__name__
)
ns
=
api
.
namespace
(
name
=
os
.
path
.
dirname
(
__file__
)
.
split
(
os
.
sep
)[
-
1
]
.
replace
(
'_'
,
'-'
),
description
=
'API connected to web-api module'
,
ordered
=
False
)
@
ns
.
route
(
'/add'
,
methods
=
[
'POST'
])
class
Add
(
Resource
):
@
ns
.
doc
(
security
=
SECURITY
)
@
ns
.
expect
(
*
add_web_api_payload
())
@
ns
.
response
(
*
add_web_api_response
())
@
sanitized
()
def
post
(
self
):
try
:
validator
=
AddWebApiValidator
()
payload
:
dict
=
validator
.
load
(
request
.
get_json
())
web_api_id
:
int
=
add_web_api
(
payload
)
return
prepare_api_response
(
SUCCESS_CODE
,
INSERT_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
0 → 100644
View file @
e556a6e6
from
app
import
orm
as
ORM
from
app
import
db
def
get_web_api_by_endpoint
(
endpoint
:
str
)
->
ORM
.
Api
|
None
:
return
ORM
.
Api
.
query
.
filter_by
(
endpoint
=
endpoint
)
.
first
()
def
add_web_api
(
web_api_info
:
dict
)
->
int
|
None
:
try
:
existing_web_api
:
ORM
.
Api
|
None
=
\
get_web_api_by_endpoint
(
web_api_info
.
get
(
'endpoint'
))
if
existing_web_api
:
raise
Exception
(
'endpoint already exists'
)
web_api_model
=
ORM
.
Api
(
endpoint
=
web_api_info
.
get
(
'endpoint'
),
method
=
web_api_info
.
get
(
'method'
),
tag
=
web_api_info
.
get
(
'tag'
)
)
db
.
session
.
add
(
web_api_model
)
db
.
session
.
commit
()
return
web_api_model
.
id
except
Exception
as
e
:
db
.
session
.
rollback
()
raise
e
\ No newline at end of file
app/routes/web_api/web_api_payload.py
0 → 100644
View file @
e556a6e6
from
flask_restx
import
fields
from
app.app_config.constant
import
ENDPOINT_METHODS
,
ENDPOINT_TAGS
from
app.routes
import
api
def
add_web_api_payload
()
->
list
:
payload
=
api
.
model
(
'addWebApi Payload'
,
{
'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
0 → 100644
View file @
e556a6e6
from
app.app_config.response_code
import
*
from
app.app_config.response_message
import
*
from
app.utils.api_response
import
prepare_swagger_response
def
add_web_api_response
()
->
any
:
return
prepare_swagger_response
(
code
=
SUCCESS_CODE
,
message
=
INSERT_SUCCESS_MESSAGE
,
model_name
=
'addUser Response'
)
\ No newline at end of file
app/routes/web_api/web_api_validator.py
0 → 100644
View file @
e556a6e6
from
marshmallow
import
Schema
,
fields
,
validate
from
app.app_config.constant
import
ENDPOINT_METHODS
,
ENDPOINT_TAGS
class
AddWebApiValidator
(
Schema
):
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