Skip to content
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

Swagger #3

Merged
merged 2 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
detect_v1/**
detect_v2/**

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
36 changes: 36 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:

.gitignore
.openapi-generator
.openapi-generator/**
.travis.yml
README.md
docs/**
git_push.sh
requirements.txt
setup.py
test/**
test
test-requirements.txt
tox.ini
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
language: python

python:
- 3.6
- 3.5
- 2.7

services:
- docker

install: pip install -U tox-travis
script: tox

script:
- make test-all

before_deploy: make swagger
deploy:
provider: pypi
distributions: sdist bdist_wheel
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is a workaround in order to assume the current user.

FROM openapitools/openapi-generator-cli

ARG USERNAME
ARG UID
ARG GID

RUN adduser -D -H -u $UID -g $GID $USERNAME
USER $USERNAME
51 changes: 43 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BROWSER := python -c "$$BROWSER_PYSCRIPT"
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
clean: clean-build clean-pyc clean-test clean-swagger ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
rm -fr build/
Expand All @@ -50,39 +50,74 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/
rm -fr .pytest_cache

clean-swagger:
rm -rf detect_v1
rm -rf detect_v2

lint: ## check style with flake8
flake8 vectra_api_client tests

test: ## run tests quickly with the default Python
py.test
test: swagger ## run tests quickly with the default Python
pytest

test-all: ## run tests on every Python version with tox
test-all: swagger ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source vectra_api_client -m pytest
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/vectra_api_client.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ vectra_api_client
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html

servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .

release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
dist: clean swagger ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

install: clean ## install the package to the active Python's site-packages
install: clean swagger ## install the package to the active Python's site-packages
python setup.py install

USERNAME=$(shell id --user --name)
UID=$(shell id --user $(USERNAME))
GID=$(shell id --group $(USERNAME))

CONFIG_DIR=swagger/config
OUTPUT_DIR=.

.PHONY: swagger
swagger:
docker build \
--build-arg USERNAME=$(USERNAME) \
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
-t vectra-api-client/openapi-generator-cli \
. \
2>&1 >/dev/null
docker run \
-v $(PWD):/local \
vectra-api-client/openapi-generator-cli generate \
--config /local/$(CONFIG_DIR)/detect_v1.json \
--input-spec /local/swagger/detect_v1.yml \
--generator-name python \
--output /local/$(OUTPUT_DIR)
docker run \
-v $(PWD):/local \
vectra-api-client/openapi-generator-cli generate \
--config /local/$(CONFIG_DIR)/detect_v2.json \
--input-spec /local/swagger/detect_v2.yml \
--generator-name python \
--output /local/$(OUTPUT_DIR)
rm -rf $(OUTPUT_DIR)/test
rm -rf $(OUTPUT_DIR)/.openapi-generator
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
certifi >= 14.05.14
python_dateutil >= 2.5.3
requests==2.20.0
setuptools >= 21.0.0
six >= 1.10
urllib3 >= 1.15.1
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ twine==1.12.1

pytest==3.8.2
pytest-runner==4.2
pytest-mock==1.10.0
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ universal = 1

[flake8]
exclude = docs
max_line_length=120

[aliases]
test = pytest
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
include_package_data=True,
keywords='vectra_api_client',
name='vectra_api_client',
packages=find_packages(include=['vectra_api_client']),
packages=find_packages(),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
Expand Down
3 changes: 3 additions & 0 deletions swagger/config/detect_v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageName": "detect_v1"
}
3 changes: 3 additions & 0 deletions swagger/config/detect_v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageName": "detect_v2"
}
Empty file removed swagger/detect_api_v1.yml
Empty file.
Empty file removed swagger/detect_api_v2.yml
Empty file.
88 changes: 88 additions & 0 deletions swagger/detect_v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
openapi: 3.0.0
info:
title: Vectra API
description: Swagger spec for Vectra API v1
version: v1
license:
name: MIT
contact:
name: Vectra Support
url: https://support.vectranetworks.com
email: support@vectra.ai
servers:
- url: 'https://{host}/api'
variables:
host:
description: Hostname or IP of Brain
default: localhost
security:
- BasicAuth: []
paths:
/detections:
get:
summary: Detection objects contain all the information related to security events detected on the network.
operationId: get_detections
tags:
- detections
parameters:
- name: page
in: query
description: Page Number.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Detections'
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
schemas:
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Detections:
type: object
properties:
count:
description: Number of returned objects
type: integer
next:
description: URL for next page
type: string
previous:
description: URL for previous page
type: string
results:
description: The list of detections
type: array
items:
$ref: '#/components/schemas/Detection'
required:
- count
- results
Detection:
type: object
properties:
id:
type: integer
89 changes: 89 additions & 0 deletions swagger/detect_v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
openapi: 3.0.0
info:
title: Vectra API
description: Swagger spec for Vectra API v2
version: v2
license:
name: MIT
contact:
name: Vectra Support
url: https://support.vectranetworks.com
email: support@vectra.ai
servers:
- url: 'https://{host}/api/v2'
variables:
host:
description: Hostname or IP of Brain
default: localhost
security:
- TokenAuth: []
paths:
/detections:
get:
summary: Detection objects contain all the information related to security events detected on the network.
operationId: get_detections
tags:
- detections
parameters:
- name: page
in: query
description: Page Number.
required: false
schema:
type: integer
format: int32
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Detections'
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
securitySchemes:
TokenAuth:
type: apiKey
name: Authorization
in: header
schemas:
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Detections:
type: object
properties:
count:
description: Number of returned objects
type: integer
next:
description: URL for next page
type: string
previous:
description: URL for previous page
type: string
results:
description: The list of detections
type: array
items:
$ref: '#/components/schemas/Detection'
required:
- count
- results
Detection:
type: object
properties:
id:
type: integer
Loading