Skip to content

Commit

Permalink
Merge pull request #3 from tagbase/timezone_fix
Browse files Browse the repository at this point in the history
Fix issue with Timzone and update from Swagger 2.0 to OpenAPI 3.0.0
  • Loading branch information
lewismc authored Jul 9, 2019
2 parents a705d39 + b990a53 commit a1ab120
Show file tree
Hide file tree
Showing 27 changed files with 310 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.travis.yaml
.swagger-codegen-ignore
.openapi-generator-ignore
README.md
tox.ini
git_push.sh
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,3 @@ target/

#Ipython Notebook
.ipynb_checkpoints

tagbase.log*
File renamed without changes.
1 change: 1 addition & 0 deletions .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ EXPOSE 5433

ENTRYPOINT ["python3"]

CMD ["-m", "swagger_server"]
CMD ["-m", "openapi_server"]
7 changes: 6 additions & 1 deletion Dockerfile-tagbase
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/

RUN apk update && \
apk upgrade && \
apk add bash postgresql-libs && \
apk add --update tzdata && \
apk add --virtual .build-deps gcc musl-dev postgresql-dev && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps

RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
#&& \ dpkg-reconfigure -f noninteractive tzdata

RUN pip3 install --no-cache-dir -r requirements.txt

COPY . /usr/src/app
Expand All @@ -19,4 +24,4 @@ EXPOSE 5433

ENTRYPOINT ["python3"]

CMD ["-m", "swagger_server"]
CMD ["-m", "openapi_server"]
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Overview

Tagbase is a [Flask](http://flask.pocoo.org/) application which provides HTTP endpoints for ingestion of
various files into the Tagbase SQL database.
various files into the Tagbase SQL database. This project was autogenerated from the OpenAPI v3 specification
which can be found at **openapi_server/openapi/openapi.yaml**


## Running with Docker
Expand Down Expand Up @@ -68,23 +69,23 @@ You will see the services graciously shutdown.

**N.B.** The URI's below may alternate between ***localhost*** and ***0.0.0.0*** depending on whether your workstation is Windows (localhost) or Linux/Mac (0.0.0.0)

Navigate to [http://localhost:5433/v1/tagbase/ui/](http://0.0.0.0:5433/v1/tagbase/ui/)
Navigate to [http://localhost:5433/v2/tagbase/ui/](http://0.0.0.0:5433/v2/tagbase/ui/)
to see the tagbase-server UI running.
**It will really help for you to read the API documentation provided in the Web Application.**
Using the [eTUFF API](http://0.0.0.0:5433/v1/tagbase/ui/#!/Products/ingest_etuff_get),
Using the [eTUFF API](http://0.0.0.0:5433/v2/tagbase/ui/#!/Products/ingest_etuff_get),
you can execute the following commands to initiate a primitive test
ingestion of some sample eTUFF-sailfish-117259.txt data present on the server.

using curl...

```bash
curl -X GET --header 'Accept: application/json' 'http://0.0.0.0:5433/v1/tagbase/ingest/etuff?granule_id=1234&file=file%3A%2F%2F%2Fusr%2Fsrc%2Fapp%2Fdata%2FeTUFF-sailfish-117259.txt'
curl -X GET --header 'Accept: application/json' 'http://0.0.0.0:5433/v2/tagbase/ingest/etuff?granule_id=1234&file=file%3A%2F%2F%2Fusr%2Fsrc%2Fapp%2Fdata%2FeTUFF-sailfish-117259.txt'
```

...or using a Request URL

```bash
http://0.0.0.0:5433/v1/tagbase/ingest/etuff?granule_id=1234&file=file%3A%2F%2F%2Fusr%2Fsrc%2Fapp%2Fdata%2FeTUFF-sailfish-117259.txt
http://0.0.0.0:5433/v2/tagbase/ingest/etuff?granule_id=1234&file=file%3A%2F%2F%2Fusr%2Fsrc%2Fapp%2Fdata%2FeTUFF-sailfish-117259.txt
```

**N.B.** The REST server is capable of ingesting data from many sources e.g. file, ftp, http and https.
Expand Down
52 changes: 52 additions & 0 deletions git_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"

git_user_id=$1
git_repo_id=$2
release_note=$3

if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi

if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi

if [ "$release_note" = "" ]; then
release_note="Minor update"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi

# Initialize the local directory as a Git repository
git init

# Adds the files in the local repository and stages them for commit.
git add .

# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"

# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined

if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi

fi

git pull origin master

# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

File renamed without changes.
6 changes: 3 additions & 3 deletions swagger_server/__main__.py → openapi_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#from flask_swagger_ui import get_swaggerui_blueprint
from logging.handlers import RotatingFileHandler
from logging import Formatter
from swagger_server import encoder
from openapi_server import encoder

def main():
handler = RotatingFileHandler('tagbase.log', maxBytes=10000, backupCount=10)
Expand All @@ -18,9 +18,9 @@ def main():

logger = logging.getLogger('werkzeug')
logger.addHandler(handler)
app = connexion.FlaskApp(__name__, specification_dir='./swagger/')
app = connexion.FlaskApp(__name__, specification_dir='./openapi/')
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Tagbase API'})
app.add_api('openapi.yaml', arguments={'title': 'Tagbase API'})

## Uncomment the following code if you wish the swagger ui to be available at
## http://localhost:5433/api/docs/
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from time import time
from tzlocal import get_localzone

from swagger_server.models.error import Error
from swagger_server.models.success import Success
from swagger_server import util
from openapi_server.models.error import Error # noqa: E501
from openapi_server.models.success import Success # noqa: E501
from openapi_server import util

# Needed Python 2/3 urllib compatability
try:
Expand All @@ -22,7 +22,6 @@

from werkzeug.exceptions import InternalServerError


def ingest_etuff_get(granule_id, file):
"""Get eTUFF file and execute ingestion.
Expand Down
3 changes: 3 additions & 0 deletions openapi_server/controllers/security_controller_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import List


4 changes: 2 additions & 2 deletions swagger_server/encoder.py → openapi_server/encoder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from swagger_server.models.base_model_ import Model
from openapi_server.models.base_model_ import Model


class JSONEncoder(FlaskJSONEncoder):
Expand All @@ -10,7 +10,7 @@ class JSONEncoder(FlaskJSONEncoder):
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
for attr, _ in six.iteritems(o.openapi_types):
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from swagger_server.models.error import Error
from swagger_server.models.success import Success
from openapi_server.models.error import Error
from openapi_server.models.success import Success
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import six
import typing

from swagger_server import util
from openapi_server import util

T = typing.TypeVar('T')


class Model(object):
# swaggerTypes: The key is attribute name and the
# openapiTypes: The key is attribute name and the
# value is attribute type.
swagger_types = {}
openapi_types = {}

# attributeMap: The key is attribute name and the
# value is json key in definition.
Expand All @@ -29,7 +29,7 @@ def to_dict(self):
"""
result = {}

for attr, _ in six.iteritems(self.swagger_types):
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
Expand Down
24 changes: 12 additions & 12 deletions swagger_server/models/error.py → openapi_server/models/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

from typing import List, Dict # noqa: F401

from swagger_server.models.base_model_ import Model
from swagger_server import util
from openapi_server.models.base_model_ import Model
from openapi_server import util


class Error(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, code: int=None, message: str=None, fields: str=None): # noqa: E501
"""Error - a model defined in Swagger
def __init__(self, code=None, message=None, fields=None): # noqa: E501
"""Error - a model defined in OpenAPI
:param code: The code of this Error. # noqa: E501
:type code: int
Expand All @@ -25,7 +25,7 @@ def __init__(self, code: int=None, message: str=None, fields: str=None): # noqa
:param fields: The fields of this Error. # noqa: E501
:type fields: str
"""
self.swagger_types = {
self.openapi_types = {
'code': int,
'message': str,
'fields': str
Expand Down Expand Up @@ -53,7 +53,7 @@ def from_dict(cls, dikt) -> 'Error':
return util.deserialize_model(dikt, cls)

@property
def code(self) -> int:
def code(self):
"""Gets the code of this Error.
Expand All @@ -63,7 +63,7 @@ def code(self) -> int:
return self._code

@code.setter
def code(self, code: int):
def code(self, code):
"""Sets the code of this Error.
Expand All @@ -74,7 +74,7 @@ def code(self, code: int):
self._code = code

@property
def message(self) -> str:
def message(self):
"""Gets the message of this Error.
Expand All @@ -84,7 +84,7 @@ def message(self) -> str:
return self._message

@message.setter
def message(self, message: str):
def message(self, message):
"""Sets the message of this Error.
Expand All @@ -95,7 +95,7 @@ def message(self, message: str):
self._message = message

@property
def fields(self) -> str:
def fields(self):
"""Gets the fields of this Error.
Expand All @@ -105,7 +105,7 @@ def fields(self) -> str:
return self._fields

@fields.setter
def fields(self, fields: str):
def fields(self, fields):
"""Sets the fields of this Error.
Expand Down
Loading

0 comments on commit a1ab120

Please sign in to comment.