-
Notifications
You must be signed in to change notification settings - Fork 52
WIP - feature/basic api for app #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
WIP - feature/basic api for app #99
Conversation
|
||
api_routes = [{'name': '/new_event',}, {'name': '/{date}'}] | ||
api_key = session.query(Token).filter_by(owner_id=user.id).first() | ||
session.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary? The session is being closed at the end of the get_db
type="text/javascript" | ||
src="{{ url_for('static', path='/apiKeyGenerator.js') }}" | ||
></script> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work!
remember, tests and documentation are essential
@@ -8,11 +8,13 @@ | |||
|
|||
|
|||
SQLALCHEMY_DATABASE_URL = os.getenv( | |||
"DATABASE_CONNECTION_STRING", config.DEVELOPMENT_DATABASE_STRING) | |||
"DATABASE_CONNECTION_STRING2", config.DEVELOPMENT_DATABASE_STRING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mistake?
|
||
#pool_pre_ping=True for POSTGRES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
@@ -32,3 +33,11 @@ class Event(Base): | |||
owner_id = Column(Integer, ForeignKey("users.id")) | |||
|
|||
owner = relationship("User", back_populates="events") | |||
|
|||
|
|||
class Token(Base): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be nice to add a short documentation for this table.
callAPIKeyRoute("/api/generate_key", { user: user_id, refresh: state }).then( | ||
(data) => { | ||
let keyText = document.getElementById("apiKeyHolder"); | ||
keyText.textContent = "API Key: " + data.key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you use f"string {param}" ?
@@ -1,9 +1,9 @@ | |||
// Enable bootstrap popovers | |||
// // Enable bootstrap popovers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revisit this file and remove unneeded code.
@@ -8,11 +8,13 @@ | |||
|
|||
|
|||
SQLALCHEMY_DATABASE_URL = os.getenv( | |||
"DATABASE_CONNECTION_STRING", config.DEVELOPMENT_DATABASE_STRING) | |||
"DATABASE_CONNECTION_STRING2", config.DEVELOPMENT_DATABASE_STRING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure you don't commit this change :)
|
||
id = Column(String, primary_key=True, index=True) | ||
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False, unique=True) | ||
owner = relationship("User", back_populates="token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a good practice, we can add expiry_date
. If you really into it, read about security in APIs: https://owasp.org/www-project-api-security/
return JSONResponse(jsonable_encoder({'key': token})) | ||
|
||
|
||
@key_gen_router.post('/delete_key') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use @key_gen_route.delete
?
api_routes = [{'name': '/new_event',}, {'name': '/{date}'}] | ||
api_key = session.query(Token).filter_by(owner_id=user.id).first() | ||
session.close() | ||
no_api_key = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change these lines to key = getattr(api_key, 'id', None)
and remove the no_api_key
variable?
from typing import Optional | ||
|
||
|
||
def check_api_key(key: str, session=Depends(get_db)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should implement rate limit to this check
data = await request.json() | ||
if data.get('refresh', False): | ||
session.query(Token).filter_by(owner_id=data['user']).delete() | ||
token = secrets.token_urlsafe(32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job for using secrets
!
@@ -0,0 +1,8 @@ | |||
#apiKeyDelete { | |||
font-size: 0.6rem; | |||
margin-left: 20px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer working with em/%
session.commit() | ||
session.close() | ||
return JSONResponse(jsonable_encoder({'success': True})) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many blank lines :)
session.add(event) | ||
session.commit() | ||
d['id'] = event.id | ||
session.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as @IdanPelled comment
basic implementation, no docs on front, no tests, no documentation yet
Hey, want some CRs for code