Skip to content

Commit

Permalink
Boostrap cloudpub with boilerplate code
Browse files Browse the repository at this point in the history
This commit bootstraps the `cloudpub` library with the project skeleton
as well as some boilerplate code.

Next MRs will need to be open in order to implement this library.
  • Loading branch information
JAVGan committed Jan 5, 2023
1 parent 84142b8 commit 3a834be
Show file tree
Hide file tree
Showing 14 changed files with 888 additions and 60 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include MANIFEST.in
include README.md
include LICENSE
include requirements.txt
recursive-include tests *
global-exclude *.py[cod]
115 changes: 55 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,87 @@
# cloudpub
# CloudPub

A library for publishing product listings on various clouds

## Overview

## Getting started
The `CloudPub` is a library to allow associating and publishing VM images into product listings on
different cloud marketplaces.

To make it easy for you to get started with GitLab, here's a list of recommended next steps.
It's based on several Stratosphere Tooling such as:

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
- [AMREAT](https://gitlab.cee.redhat.com/stratosphere/amreat)
- [Hyperscaler-Automation-Azure](https://gitlab.cee.redhat.com/stratosphere/hyperscaler-automation-azure)
- [Azure Private Offers](https://gitlab.cee.redhat.com/stratosphere/azure-private-offers)

## Add your files
### Objective

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
This library implements a small subset of Stratosphere Tooling actions which concerns only for
associating a VM Image with a product listing and publishing it.

```
cd existing_repo
git remote add origin https://gitlab.cee.redhat.com/stratosphere/cloudpub.git
git branch -M main
git push -uf origin main
```

## Integrate with your tools
It's not inteneded to replace the already existing Stratosphere Tooling but rather complement them
by:

- [ ] [Set up project integrations](https://gitlab.cee.redhat.com/stratosphere/cloudpub/-/settings/integrations)
1. Providing a very small and cohesive implementation of the required actions
2. Using the minimal external dependencies as possible for better integration with Pub
3. Following the same patterns from already existing Pub libraries
4. Not implementing a CLI of any type as its intended to be used as a library only

## Collaborate with your team
It also refactor the exising implementations to use [attrs](https://www.attrs.org/en/stable/) instead
of [pydantic](https://docs.pydantic.dev/) for its models in order to have a better compatibility with
Pub (which uses [attrs](https://www.attrs.org/en/stable/)) as well as
[several other reasons](https://threeofwands.com/why-i-use-attrs-instead-of-pydantic/).

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Installation

## Test and Deploy
To install this library go to the project's root directory and execute:

Use the built-in continuous integration in GitLab.
```{bash}
pip install -r requirements.txt
pip install .
```

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
## Development

***
### Prerequisites

# Editing this README
The versions listed below are the one which were tested and work. Other versions can work as well.

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
- Install or create a `virtualenv` for `python` >= 3.7
- Install `tox` >= 3.25

## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
### Dependency Management

## Name
Choose a self-explaining name for your project.
To manage dependencies, this project uses [pip-tools](https://github.com/jazzband/pip-tools) so that
the dependencies are pinned and their hashes are verified during installation.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
The unpinned dependencies are recorded in **setup.py** and the **requirements.txt** are regenerated
each time `tox` runs. Alternatively you can run `tox -e pip-compile` manually
to achieve the same result. To upgrade a package, use the `-P` argument of the `pip-compile` command.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
When installing the dependencies use the command `pip install --no-deps --require-hashes -r requirements.txt`.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
To ensure the pinned dependencies are not vulnerable, this project uses [safety](https://github.com/pyupio/safety),
which runs on every pull-request or can be run manually by `tox -e security`.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
### Coding Standards

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
The codebase conforms to the style enforced by `flake8` with the following exceptions:

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
- The maximum line length allowed is 100 characters instead of 80 characters

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
In addition to `flake8`, docstrings are also enforced by the plugin `flake8-docstrings` with
the following exemptions:

## Contributing
State if you are open to contributions and what your requirements are for accepting them.
- D100: Missing docstring in public module
- D104: Missing docstring in public package
- D105: Missing docstring in magic method

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
Additionally, `black` is used to enforce other coding standards.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
To verify that your code meets these standards, you may run `tox -e lint`.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
To automatically format your code you man run `tox -e autoformat`.

## License
For open source projects, say how it is licensed.
### Unit tests

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
To run unit tests use `tox -e py37,py38,py39,py310`.
1 change: 1 addition & 0 deletions cloudpub/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
1 change: 1 addition & 0 deletions cloudpub/aws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
41 changes: 41 additions & 0 deletions cloudpub/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
from abc import ABCMeta, abstractmethod

log = logging.getLogger(__name__)


class PublishingMetadata:
"""
A collection of metadata necessary for associating an existing VM Image into a product listing
and publishing it.
Args:
image_path (str)
The image URL or ID to be associated with a product listing
destination (str)
The product listing to update with the given ``image_path``
overwrite (bool)
Whether to overwrite the product listing with the given image or not (append only).
"""

def __init__(self, image_path: str, destination: str, overwrite: bool) -> None:
self.image_path = image_path
self.destination = destination
self.overwrite = overwrite


class BaseService(ABCMeta):
"""
Base class for all cloud provider services.
"""

@abstractmethod
def publish(self, metadata: PublishingMetadata):
"""
Associate a VM image with a given product listing (destination) and publish it.
Args:
metadata (PublishingMetadata): metadata for the VM image publishing.
"""
raise NotImplementedError
17 changes: 17 additions & 0 deletions cloudpub/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: GPL-3.0-or-later


class LoginFailed(RuntimeError):
"""Report login failure to some marketplace."""


class InvalidAuthData(RuntimeError):
"""Report invalid input data for authentication."""


class UnexpectedRuntimeType(RuntimeError):
"""Report invalid type when parsing data from JSON."""


class InvalidStateError(RuntimeError):
"""Report invalid state which should not happen in code"""
1 change: 1 addition & 0 deletions cloudpub/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
1 change: 1 addition & 0 deletions cloudpub/models/aws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
1 change: 1 addition & 0 deletions cloudpub/models/ms_azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
1 change: 1 addition & 0 deletions cloudpub/ms_azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
26 changes: 26 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from setuptools import setup, find_packages

setup(
name='cloudpub',
description='Services for publishing products in cloud environments',
version='0.1.0',
keywords='stratosphere cloudpub cloudpublish',
author='Jonathan Gangi',
author_email='[email protected]',
url='https://gitlab.cee.redhat.com/stratosphere/cloudpub',
license='GPLv3+',
packages=find_packages(exclude=['tests', 'tests.*']),
classifiers=[
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
install_requires=[
'attrs',
'cattrs',
'requests',
],
zip_safe=False,
)
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: GPL-3.0-or-later
62 changes: 62 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[tox]
envlist = pip-compile, docs, lint, mypy, security, py37, py38, py39, py310

[testenv]
envdir = {toxworkdir}/shared-environment
deps=
-r requirements-test.txt
usedevelop=true
commands=
pytest -vv \
--cov-config .coveragerc --cov=cloudpub --cov-report term \
--cov-report xml --cov-report html {posargs}

[testenv:pip-compile]
basepython = python3.7
skip_install = true
deps = pip-tools
commands =
pip-compile --generate-hashes --reuse-hashes --output-file=requirements.txt
pip-compile --generate-hashes --reuse-hashes --output-file=requirements-test.txt setup.py requirements-test.in

[testenv:docs]
use_develop=true
commands=
sphinx-build -M html docs docs/_build

[testenv:lint]
skip_install = true
deps =
black
flake8
flake8-docstrings
isort
mypy
commands =
flake8 --max-line-length=100 --ignore=D100,D104,D105 --per-file-ignores=tests/*:D101,D102,D103 cloudpub tests
black -S -t py39 -l 100 --check --diff cloudpub tests
isort -l 100 --profile black --check --diff cloudpub tests

[testenv:mypy]
basepython = python3.9
deps = -r requirements-test.txt
commands = mypy --ignore-missing-imports --exclude '^venv.*' .

[testenv:security]
skip_install = true
deps =
bandit
safety
commands =
bandit -s B303 -r cloudpub
safety check -r requirements.txt

[testenv:autoformat]
skip_install = true
deps =
black
isort
commands =
black -S -t py39 -l 100 cloudpub tests
isort -l 100 --profile black cloudpub tests

0 comments on commit 3a834be

Please sign in to comment.