This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update project with initial application logic
- Loading branch information
Showing
29 changed files
with
1,086 additions
and
298 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--requirement requirements-test.txt | ||
flask_testing | ||
ipython | ||
mypy | ||
semver |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--editable .[test] | ||
--requirement requirements.txt | ||
flask_testing |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Note: Add any additional requirements to setup.py's install_requires field | ||
--editable . | ||
connexion == 2.6.0 | ||
flask_testing | ||
python_dateutil == 2.6.0 | ||
setuptools >= 21.0.0 | ||
wheel |
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
Binary file not shown.
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,24 @@ | ||
"""The example library.""" | ||
# We disable a Flake8 check for "Module imported but unused (F401)" because | ||
# although this import is not directly used, it populates the value | ||
# package_name.__version__, which is used to get version information about this | ||
# Python package. | ||
# cisagov Libraries | ||
from api.controllers import customers_controller | ||
|
||
from ._version import __version__ # noqa: F401 | ||
|
||
__all__ = [ | ||
"customers_controller", | ||
# "api_response", | ||
# "assessment", | ||
# "base_model", | ||
# "campaign", | ||
# "customer", | ||
# "document", | ||
# "template", | ||
# "user", | ||
# "encoder", | ||
# "type_util", | ||
# "util" | ||
] |
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,20 @@ | ||
#!/usr/bin/env python3 | ||
"""Code to run if this package is used as a Python module.""" | ||
|
||
# Third-Party Libraries | ||
import connexion | ||
|
||
# cisagov Libraries | ||
from api import encoder | ||
|
||
|
||
def main(): | ||
"""Run Main Application..""" | ||
app = connexion.App(__name__, specification_dir="./openapi/") | ||
app.app.json_encoder = encoder.JSONEncoder | ||
app.add_api("openapi.yaml", arguments={"title": "Li-PCA API"}, pythonic_params=True) | ||
app.run(port=8080) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
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 @@ | ||
"""Controllers Init.""" |
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,88 @@ | ||
#!/usr/bin/env python | ||
"""Customers Controller Logic.""" | ||
|
||
# Standard Python Libraries | ||
import logging | ||
|
||
# Third-Party Libraries | ||
import connexion | ||
|
||
# cisagov Libraries | ||
# from api import util | ||
from api.models.customer import Customer # noqa: E501 | ||
|
||
|
||
def create_customer(body=None): # noqa: E501 | ||
"""Add a new customer to the data store. | ||
# noqa: E501 | ||
:param body: Customer object to be added to data store | ||
:type body: dict | bytes | ||
:rtype: None | ||
""" | ||
if connexion.request.is_json: | ||
body = Customer.from_dict(connexion.request.get_json()) # noqa: E501 | ||
logging.debug("Body: %s", body) | ||
return "do some magic!" | ||
|
||
|
||
def delete_customer_by_uuid(uuid): # noqa: E501 | ||
"""Delete a customer. | ||
# noqa: E501 | ||
:param uuid: uuid to delete | ||
:type uuid: str | ||
:rtype: None | ||
""" | ||
logging.debug("Uuid: %s", uuid) | ||
return "do some magic!" | ||
|
||
|
||
def get_all_customers(name=None): # noqa: E501 | ||
"""Find all customers. | ||
Multiple status values can be provided with comma separated strings # noqa: E501 | ||
:param name: Customer name filter | ||
:type name: List[str] | ||
:rtype: List[Customer] | ||
""" | ||
logging.debug("name: %s", name) | ||
return "do some magic!" | ||
|
||
|
||
def get_customer_by_uuid(uuid): # noqa: E501 | ||
"""Find customer by uuid. | ||
Returns a single customer # noqa: E501 | ||
:param uuid: uuid of customer to return | ||
:type uuid: str | ||
:rtype: Customer | ||
""" | ||
logging.debug("Uuid: %s", uuid) | ||
return "do some magic!" | ||
|
||
|
||
def update_customer_by_uuid(uuid, body=None): # noqa: E501 | ||
"""Update an existing customer. | ||
# noqa: E501 | ||
:param uuid: uuid of customer to update | ||
:type uuid: str | ||
:param body: Customer object to be added to data store | ||
:type body: dict | bytes | ||
:rtype: None | ||
""" | ||
if connexion.request.is_json: | ||
body = Customer.from_dict(connexion.request.get_json()) # noqa: E501 | ||
logging.debug("Body: %s", body) | ||
return "do some magic!" |
File renamed without changes.
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,37 @@ | ||
"""Encoding Utility Logic.""" | ||
|
||
# Third-Party Libraries | ||
from connexion.apps.flask_app import FlaskJSONEncoder # type: ignore | ||
import six # type: ignore | ||
|
||
# cisagov Libraries | ||
from api.models.base_model_ import Model | ||
|
||
|
||
class JSONEncoder(FlaskJSONEncoder): | ||
"""Encoding Class.""" | ||
|
||
include_nulls = False | ||
encoding_type = "UTF-8" | ||
|
||
def default(self, encode_target): | ||
"""Use default encooding logic.""" | ||
if isinstance(encode_target, Model): | ||
dikt = {} | ||
for attr, _ in six.iteritems(encode_target.swagger_types): | ||
value = getattr(encode_target, attr) | ||
if value is None and not self.include_nulls: | ||
continue | ||
attr = encode_target.attribute_map[attr] | ||
dikt[attr] = value | ||
return dikt | ||
return FlaskJSONEncoder.default(self, encode_target) | ||
|
||
def set_decoding(self, encoding_type): | ||
"""Set encooding type.""" | ||
# Raise assertion error if input type is invalid | ||
# TODO: Check B101 allowance in bandit config | ||
# assert isinstance(encoding_type, str) | ||
|
||
self.encoding_type = encoding_type | ||
return self.encoding_type |
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,9 @@ | ||
# coding: utf-8 | ||
|
||
# flake8: noqa | ||
from __future__ import absolute_import | ||
|
||
# cisagov Libraries | ||
# import models into model package | ||
from api.models.api_response import ApiResponse | ||
from api.models.customer import Customer |
Oops, something went wrong.