-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
[api] Rest API for PKI app #455
Conversation
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.
Going in the correct direction, one question:
ea2152d
to
61de479
Compare
27348a4
to
7de743b
Compare
a199fe9
to
3b7674b
Compare
@nemesisdesign, I tried to keep it similar to the admin panel, But, Fixed it now. 😊 |
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.
@ManishShah120 I merged the latest master in and some query checks failed can you please double check?
Fixed it 👍 @nemesisdesign |
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.
LGTM! 😄
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.
So here's some important actions that can be performed from the admin but seem missing from the API.
- renew cert
- renew CA
- revoke certificate
To keep it simple, we can introduce these actions for singular objects (leaving the implementation for performing renew/revoke on multiple objects for a future phase if needed at all).
The models have method for each of these actions so the implementation should be pretty easy.
The API urls can be like:
POST /cert/{id}/renew/
POST /ca/{id}/renew/
POST /cert/{id}/revoke/
if data.get('certificate') and data.get('private_key'): | ||
data = get_import_data(instance) | ||
data.update({'ca': instance.ca}) | ||
return data |
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.
this looks mostly the same as the Ca serializer
def validate_validity_end(self, value): | ||
if value is None: | ||
value = default_cert_validity_end() | ||
return value |
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.
these two method also are almost identical
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 you please move these 3 methods above to a BaseListSerializer
which inherits from BaseSerializer
and then use it as a base for CertListSerializer
and CatListSerializer
?
The line which adds data.update({'ca': instance.ca})
can be added with super()
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.
almost there
openwisp_controller/pki/api/views.py
Outdated
instance.renew() | ||
return Response( | ||
{_("CA '{}' renewed successfully".format(instance.name))}, status=302, | ||
) |
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.
return the serialized data with the updated data and 200 as status code, applies to the other endpoints as well
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.
This is done. 👍
@nemesisdesign I have made the requested changes for the revoke and renew endpoints, but there's one minor issue, i.e., I have used the However, this will not be a an issue, in production. Still I will see if I can fix it. |
Sure, better fix this and ensure the serializers are correct, you simply need to create a new serializers inheriting the serializer you're using now and removing the write_only fields. |
Done, Fixed it. 👍 |
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.
Almost there, let's do some more code improvement and then we're done.
return data | ||
|
||
|
||
def CertList_fields(fields=None): |
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.
two doubts here:
- why the default argument is
None
? it looks like there should be no default argument - why this naming? Capital letter is used for classes, I think this should be named
get_cert_list_fields
Eg:
def get_cert_list_fields(fields):
pass
return value | ||
|
||
|
||
def CaDetail_fields(fields=None): |
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 here as for get_cert_list_fields
return value | ||
|
||
|
||
def CertDetail_fields(fields=None): |
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 here
def validate_validity_end(self, value): | ||
if value is None: | ||
value = default_cert_validity_end() | ||
return value |
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 you please move these 3 methods above to a BaseListSerializer
which inherits from BaseSerializer
and then use it as a base for CertListSerializer
and CatListSerializer
?
The line which adds data.update({'ca': instance.ca})
can be added with super()
Hi @nemesisdesign have implemented the |
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 found another weird thing: why does the list endpoint provide the info about extensions but the details endpoint does not?
@nemesisdesign currently I have also removed the |
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 found another weird thing: why does the list endpoint provide the info about extensions but the details endpoint does not?
@nemesisdesign currently I have also removed the
passphrase
field from the detail endpoint, Should I leave it as as it is or should I make it visible too in the detail endpoint.
Passphrase shall be write_only
: a020222.
With this change I think we're done here.
Closes #462