Skip to content

Commit 71d7648

Browse files
committed
Merge branch 'task/updated-documentation'
2 parents 2f1710a + 6e206cf commit 71d7648

File tree

6 files changed

+79
-87
lines changed

6 files changed

+79
-87
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ if __name__ == '__main__':
6464

6565
config.yml
6666
```yaml
67-
pyms: # 1.2
68-
requests:
69-
data: {}
70-
ms: # 1.3
71-
DEBUG: true
72-
APP_NAME: business-glossary
73-
APPLICATION_ROOT : ""
74-
SECRET_KEY: "gjr39dkjn344_!67#"
67+
pyms:
68+
services: # 1.2
69+
requests:
70+
data: {}
71+
config: # 1.3
72+
DEBUG: true
73+
APP_NAME: business-glossary
74+
APPLICATION_ROOT : ""
75+
SECRET_KEY: "gjr39dkjn344_!67#"
7576
```
7677

7778
### So what did that code do?

docs/configuration.md

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,91 +18,74 @@ a simple configuration file could be a config.yaml:
1818

1919
```yaml
2020
pyms:
21-
requests: true
22-
swagger:
23-
path: ""
24-
file: "swagger.yaml"
25-
my-ms:
26-
DEBUG: true
27-
TESTING: false
28-
APP_NAME: "Python Microservice"
29-
APPLICATION_ROOT: ""
21+
services:
22+
requests: true
23+
swagger:
24+
path: ""
25+
file: "swagger.yaml"
26+
config:
27+
debug: true
28+
testing: false
29+
app_name: "Python Microservice"
30+
APPLICATION_ROOT: ""
3031
```
3132

3233
or in a config.json:
3334

3435
```json
3536
{
36-
"pyms":{
37-
"requests": true,
38-
"swagger": {
39-
"path": "",
40-
"file": "swagger.yaml"
37+
"pyms": {
38+
"services":{
39+
"requests": true,
40+
"swagger": {
41+
"path": "",
42+
"file": "swagger.yaml"
43+
}
44+
},
45+
"config": {
46+
"DEBUG": true,
47+
"TESTING": true,
48+
"APP_NAME": "Python Microservice",
49+
"APPLICATION_ROOT": "/",
50+
"test_var": "general",
51+
"subservice1": {
52+
"test": "input"
53+
},
54+
"subservice2": {
55+
"test": "output"
56+
}
4157
}
42-
},
43-
"my-ms": {
44-
"DEBUG": true,
45-
"TESTIN": false,
46-
"APP_NAME": "Python Microservice",
47-
"APPLICATION_ROOT": ""
4858
}
4959
}
5060
```
5161

5262
This file could contains this keywords:
5363

54-
## pyms block
64+
## pyms - services block
5565

5666
```pyms```: all subsets inside this keyword are the settings of this library. Each keyword will be a service of our
5767
[Microservice class](ms_class.md). For example, we declare our microservice class as:
5868

5969
```python
6070
from pyms.flask.app import Microservice
61-
ms = Microservice(service="my-ms", path=__file__)
71+
ms = Microservice(path=__file__)
6272
```
6373
and a `config.yaml` file:
6474

6575
```yaml
6676
pyms:
67-
requests: true
77+
services:
78+
requests: true
6879
```
6980

7081
our object `ms` has an attribute `requests` that is a instance of our service [requests](services.md).
7182

72-
## Our microservice block
83+
## pyms - config block
7384
This part contains all keywords of a [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/) and our
7485
constants of the enviroments (local configuration, staging configuration...). Keep in mind that a Flask configuration needs
75-
the keywords to be declared as uppercase.
86+
the keywords to be declared as uppercase. If you defined a variable like `app_name`, you will get this with
87+
`current_app.config["APP_NAME"]`
7688

77-
The name of this block is defined when you create the object of [Microservice class](ms_class.md):
78-
79-
### Example 1
80-
```python
81-
from pyms.flask.app import Microservice
82-
ms = Microservice(service="my-personal-microservice", path=__file__)
83-
```
84-
and a `config.yaml` file:
85-
86-
```yaml
87-
my-personal-microservice:
88-
DEBUG: true
89-
TESTING: false
90-
```
91-
92-
### Example 2
93-
```python
94-
from pyms.flask.app import Microservice
95-
ms = Microservice(service="ms1-api", path=__file__)
96-
```
97-
and a `config.yaml` file:
98-
99-
```yaml
100-
ms1-api:
101-
DEBUG: true
102-
TESTING: false
103-
```
104-
105-
You can set this keyword with the environment var **CONFIGMAP_SERVICE**.
10689

10790
## Import Configuration
10891
With pyms, all configuration is stored as flask configuration and it can be acceded from:

docs/examples.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@ pip install py-ms
77
config.yml:
88

99
```yaml
10-
my-minimal-microservice:
11-
APP_NAME: "Python Microservice"
10+
pyms:
11+
config:
12+
app_name: "Python Microservice"
1213
```
1314
1415
main.py
1516
1617
```python
17-
from flask import jsonify
18+
from flask import jsonify, current_app
1819

1920
from pyms.flask.app import Microservice
2021

21-
ms = Microservice(service="my-minimal-microservice", path=__file__)
22+
ms = Microservice(path=__file__)
2223
app = ms.create_app()
2324

2425

2526
@app.route("/")
2627
def example():
27-
return jsonify({"main": "hello world"})
28+
return jsonify({"main": "hello world {}".format(current_app.config["APP_NAME"])})
2829

2930

3031
if __name__ == '__main__':

docs/ms_class.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from flask import jsonify
1010

1111
from pyms.flask.app import Microservice
1212

13-
ms = Microservice(service="my-minimal-microservice", path=__file__)
13+
ms = Microservice(path=__file__)
1414
app = ms.create_app()
1515

1616

@@ -26,21 +26,23 @@ if __name__ == '__main__':
2626
And a config file like this config.yml
2727

2828
```yaml
29-
my-minimal-microservice:
30-
APP_NAME: "Python Microservice"
29+
pyms:
30+
config:
31+
APP_NAME: "Python Microservice"
3132
```
3233
Check [Configuration](configuration.md) section to know how to create a configuration file.
3334
3435
Each keyword in our configuration block, can be accessed in our Microservice object through the attribute `config`.
3536

3637
```yaml
3738
# Config.yml
38-
example-config:
39-
APP_NAME: "Python Microservice"
40-
foo: "var"
41-
multiplevars:
42-
config1: "test1"
43-
config2: "test2"
39+
pyms:
40+
config:
41+
app_name: "Python Microservice"
42+
foo: "var"
43+
multiplevars:
44+
config1: "test1"
45+
config2: "test2"
4446
4547
```
4648
```python
@@ -50,6 +52,8 @@ from pyms.flask.app import Microservice
5052
ms = Microservice(service="example-config", path=__file__)
5153
print(ms.config.APP_NAME)
5254
# >> "Python Microservice"
55+
print(ms.config.app_name)
56+
# >> "Python Microservice"
5357
print(ms.config.foo)
5458
# >> "bar"
5559
print(ms.config.multiplevars.config1)

docs/quickstart.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ if __name__ == '__main__':
2525

2626
config.yml
2727
```yaml
28-
pyms: # 1.2
29-
requests:
30-
data: {}
31-
ms: # 1.3
32-
DEBUG: true
33-
APP_NAME: business-glossary
34-
APPLICATION_ROOT : ""
35-
SECRET_KEY: "gjr39dkjn344_!67#"
28+
pyms:
29+
services: # 1.2
30+
requests:
31+
data: {}
32+
config: # 1.3
33+
DEBUG: true
34+
APP_NAME: business-glossary
35+
APPLICATION_ROOT : ""
36+
SECRET_KEY: "gjr39dkjn344_!67#"
3637
```
3738

3839
## So what did that code do?

docs/services.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ To use this service, you may add the next to you configuration file:
4848

4949
```yaml
5050
pyms:
51-
metrics: true
51+
services:
52+
metrics: true
5253
```
5354

5455
This will add the endpoint `/metrics` to your microservice, which will expose
@@ -75,8 +76,9 @@ class Service(DriverService):
7576
* Now, you can configure your service from `config.yml`
7677
```yaml
7778
pyms:
78-
myawesomesrv:
79-
myvalue: 5
79+
config:
80+
myawesomesrv:
81+
myvalue: 5
8082
```
8183

8284
* Your service will be setted inside `ms` object in `flask.current_app` objetct. for example, with the last config,

0 commit comments

Comments
 (0)