Skip to content

Commit 60ab0a8

Browse files
authored
Merge pull request #2 from NehaDC-IMC/processor-template-with-openapi-cookiecutter
Processor template with openapi cookiecutter
2 parents 319b444 + 3f8d5ed commit 60ab0a8

24 files changed

+1126
-0
lines changed

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Cookiecutter for CloudBlue Connect Reports
2+
3+
Powered by [Cookiecutter](https://github.com/cookiecutter/cookiecutter), Cookiecutter for CloudBlue Connect Reports provides a framework for boostraping your custom reports for Connect.
4+
5+
With this project you can write your own reports to execute either locally or using the reports module of Connect.
6+
7+
In order to create your own custom report you will need to get familiar with the [Connect Rest API](https://connect.cloudblue.com/community/api/) and it's OpenAPI implementation using the [connect-openapi-client](https://github.com/cloudblue/connect-python-openapi-client).
8+
9+
## Features
10+
11+
* Works fit python 3.8 and 3.9
12+
* Bootstraps a custom report project within seconds
13+
* Provides all needed dependencies
14+
* Provides basic testing functionality including right mockers
15+
* Compatible with github Actions
16+
* Configures project licensing
17+
18+
## Usage
19+
20+
Creating a project that provides a report package that could be run either using the [Connect CLI](https://github.com/cloudblue/connect-cli) or directly in [Connect](https://connect.cloudblue.com) is simple.
21+
22+
First of all, install in your local machine Cookiecutter, for example you can do it using pip:
23+
24+
$ pip install cookiecutter
25+
26+
Once cookiecutter is installed you can instantiate it against this repository:
27+
28+
$ cookiecutter https://github.com/cloudblue/connect-report-python-boilerplate
29+
30+
You'll be prompted for some values. Provide them and a Connect project will be created for you.
31+
32+
**Warning**: Please change sample data with your own desired information
33+
34+
project_name [My Awesome Project]: My Awesome Project
35+
project_slug [my_awesome_project]:
36+
description [My reports are really usefull!]:
37+
package_name [reports]:
38+
initial_report_name [My Awesome Report]: My Awesome Report
39+
initial_report_slug [my_awesome_report]:
40+
initial_report_description [This report provides all data i need]:
41+
author [Globex Corporation]: ISV Inc
42+
version [0.1.0]: 1.0.0
43+
Select license:
44+
1 - Apache Software License 2.0
45+
2 - MIT
46+
3 - BSD
47+
Choose from 1, 2, 3 [1]: 1
48+
use_github_actions [y]: y
49+
Done! Your report project is ready to go!
50+
51+
Now you can access your recently created project folder and take a look arround it:
52+
53+
$ cd my_awesome_report
54+
$ ls
55+
56+
Starting here, if you want you can put your project on a git repository, for example at github:
57+
58+
$ git init
59+
$ git add .
60+
$ git commit -m "first commit"
61+
$ git remote add origin https://github.com/cloudblue/my_custom_report.git
62+
$ git push -u origin master
63+
64+
In the use case that you decided to use github actions, you will notice that a first CI task will run, this one will run the sample test
65+
66+
## Creating your own report
67+
68+
The creation of a requires some knowladge of [Connect Rest API](https://connect.cloudblue.com/community/api/) and the [connect-openapi-client](https://github.com/cloudblue/connect-python-openapi-client).
69+
70+
First, edit the reports.json file, this file is a descriptor that can be read by Connect as well as Connect CLI to understand your package. Please ensure that all properties are defined. On the parameters list, you can define the parameters that will be asked to be populated by who runs the report, just select the ones you need as described in our community portal.
71+
72+
The code of your report must be defined at your entrypoint, here is where system will find your function that will receive an instantiated client, this client is the openapi one and can work with our API, additionally you will get a function that you must invoke in order to update the progress
73+
74+
Job done? Try to run it locally!
75+
76+
$ ccli report list -d ./my_awesome_project
77+
78+
************************************************************
79+
80+
My Awesome Project version 1.0.0
81+
82+
************************************************************
83+
84+
Welcome to My Awesome Project !
85+
86+
My reports are really usefull!
87+
88+
License
89+
90+
My Awesome Project is licensed under the Apache Software License 2.0 license.
91+
92+
93+
************************************************************
94+
95+
List of available reports:
96+
97+
Report ID: my_awesome_report - Report name: My Awesome Project
98+
99+
Now if you want you can execute it also using ccli
100+
101+
$ ccli report execute my_awesome_report_1 -d ./my_awesome_report
102+
103+
## Examples
104+
105+
All our reports that you can run from Connect platform are available to you, if you want to take a look at them and it's code visit our github repository available [here](https://github.com/cloudblue/connect-reports)
106+
107+
Please take a look to our oficial [documentation site](https://connect.cloudblue.com) for more information on how to work with reports

cookiecutter.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"project_name": "My Connect Processor",
3+
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
4+
"description": "My processor will auto-process subscription requests in CloudBlue Connect",
5+
"author": "CloudBlue Vendor",
6+
"version": "0.1.0",
7+
"license": [
8+
"Apache Software License 2.0",
9+
"MIT",
10+
"BSD"
11+
],
12+
"Require_subscription_change_usecase": "y/n",
13+
"Require_subscription_cancel_usecase": "y/n",
14+
"Require_subscription_suspend_and_resume_usecases": "y/n"
15+
}

hooks/post_gen_project.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This file is part of the Ingram Micro Cloud Blue Connect Report Python Boilerplate.
4+
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.
5+
6+
import os
7+
import shutil
8+
import string
9+
import sys
10+
import pathlib
11+
12+
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
13+
14+
15+
def remove_license():
16+
os.remove('LICENSE')
17+
18+
def remove_file(filepath):
19+
os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
20+
21+
def main():
22+
if '{{ cookiecutter.license }}' == 'Other, not Open-source':
23+
remove_license()
24+
25+
if '{{ cookiecutter.Require_subscription_change_usecase }}'.lower() == 'n':
26+
c_file = os.path.join('connect_processor','app','change.py')
27+
remove_file(c_file)
28+
29+
if '{{ cookiecutter.Require_subscription_cancel_usecase }}'.lower() == 'n':
30+
c_file = os.path.join('connect_processor', 'app', 'cancel.py')
31+
remove_file(c_file)
32+
33+
if '{{ cookiecutter.Require_subscription_suspend_and_resume_usecases }}'.lower() == 'n':
34+
c_file = os.path.join('connect_processor', 'app', 'suspend.py')
35+
remove_file(c_file)
36+
c_file = os.path.join('connect_processor', 'app', 'resume.py')
37+
remove_file(c_file)
38+
39+
40+
print('Done! Your report project is ready to go!')
41+
42+
if __name__ == '__main__':
43+
main()

hooks/pre_gen_project.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This file is part of the Ingram Micro Cloud Blue Connect Processor Template Python Boilerplate.
4+
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.
5+
6+
7+
project_slug = '{{ cookiecutter.project_slug }}'
8+
if hasattr(project_slug, 'isidentifier'):
9+
assert (
10+
project_slug.isidentifier()
11+
), '`{}` project slug is not a valid Python identifier.'.format(project_slug)
12+
13+
assert (
14+
project_slug == project_slug.lower()
15+
), '`{}` project slug should be all lowercase'.format(project_slug)

{{cookiecutter.project_slug}}/.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
exclude = .idea,.vscode,.git,pg_data,venv,env,msmiddleware/settings/*.py,*/migrations/*.py,
3+
show-source = True
4+
max-line-length = 100
5+
application-import-names = smarkets
6+
max-cognitive-complexity = 15
7+
ignore = FI1,I100,W503
8+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
htmlcov
3+
.coverage
4+
coverage.xml

0 commit comments

Comments
 (0)