python-service-builder 2.0.0__tar.gz → 2.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_service_builder-2.0.0/python_service_builder.egg-info → python_service_builder-2.1.1}/PKG-INFO +36 -18
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/README.md +35 -17
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/pyproject.toml +1 -1
- {python_service_builder-2.0.0 → python_service_builder-2.1.1/python_service_builder.egg-info}/PKG-INFO +36 -18
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/python_service_builder.egg-info/SOURCES.txt +3 -2
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/service_framework/__init__.py +4 -20
- python_service_builder-2.0.0/service_framework/list_services.py → python_service_builder-2.1.1/service_framework/service_finder.py +31 -38
- python_service_builder-2.1.1/service_framework/services.py +406 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/service_framework/services_test.py +1 -1
- python_service_builder-2.1.1/service_framework/update_services.py +47 -0
- python_service_builder-2.0.0/service_framework/services.py +0 -666
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/LICENSE +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/python_service_builder.egg-info/dependency_links.txt +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/python_service_builder.egg-info/requires.txt +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/python_service_builder.egg-info/top_level.txt +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/service_framework/__init_test.py +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/service_framework/service_builder.py +0 -0
- {python_service_builder-2.0.0 → python_service_builder-2.1.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-service-builder
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: Helper library for easier creation of Google services.
|
|
5
5
|
Author-email: David Harcombe <david.harcombe@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -49,10 +49,12 @@ ready for use.
|
|
|
49
49
|
|
|
50
50
|
`service_builder.build_service()` needs two mandatory pieces of information:
|
|
51
51
|
|
|
52
|
-
| Parameter | Description |
|
|
53
|
-
| :-: | - |
|
|
54
|
-
| key | The credentials to use to authenticate the user to the service it has to create |
|
|
55
|
-
| service | The Google API endpoint it is trying to connect to. |
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
| :-: | - | - |
|
|
54
|
+
| key | str | The credentials to use to authenticate the user to the service it has to create. |
|
|
55
|
+
| service | Service | The Google API endpoint it is trying to connect to. |
|
|
56
|
+
| api_key | _See below_ | _Optional_ An API key for those services which require an API key in addition to credentials. |
|
|
57
|
+
| extra_scopes | List[str] | _Optional_ Extra OAuth scopes needed. |
|
|
56
58
|
|
|
57
59
|
### `key`
|
|
58
60
|
|
|
@@ -60,7 +62,7 @@ These can be supplied in one of 4 ways.
|
|
|
60
62
|
|
|
61
63
|
1. A valid `google.oauth2.Credentials` object, created and passed to the
|
|
62
64
|
service builder.
|
|
63
|
-
1.
|
|
65
|
+
1. A `str` which is the name of a local file containing the `json`
|
|
64
66
|
representation of an OAuth credentials object.
|
|
65
67
|
1. A `Mapping` object which is a `json` keyfile `dict`
|
|
66
68
|
2. An `OAuthKey` object from this package, which is a `dataclass` object
|
|
@@ -69,11 +71,36 @@ These can be supplied in one of 4 ways.
|
|
|
69
71
|
### `service`
|
|
70
72
|
|
|
71
73
|
This is an Enum in the `service_framework.service` module, which defines
|
|
72
|
-
the Google service you're planning to connect to. All
|
|
73
|
-
|
|
74
|
+
the Google service you're planning to connect to. All the standard Google
|
|
75
|
+
services are included (as of the date listed in the `Services.py` file).
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
If a
|
|
78
|
+
new service has been added but this library has yet to be updated, you can
|
|
79
|
+
request it by using either `Service('<UNLISTED SERVICE>')` or
|
|
80
|
+
`Service.from_value('<UNLISTED SERVICE>')`. This will cause the library to
|
|
81
|
+
attempt to fetch the service's definition from Google and will create an
|
|
82
|
+
entry in the enum for this new service.
|
|
76
83
|
|
|
84
|
+
### Examples
|
|
85
|
+
|
|
86
|
+
#### 1. Using `Credentials`
|
|
87
|
+
```
|
|
88
|
+
from service_framework.services import Service
|
|
89
|
+
from service_framework import service_builder
|
|
90
|
+
from google.oauth2 import credentials as oauth
|
|
91
|
+
|
|
92
|
+
credentials = oauth.Credentials(
|
|
93
|
+
access_token="<YOUR ACCESS TOKEN>",
|
|
94
|
+
refresh_token="<YOUR REFRESH TOKEN>",
|
|
95
|
+
token_uri="https://oauth2.googleapis.com/token",
|
|
96
|
+
client_id="<YOUR CLIENT ID>",
|
|
97
|
+
client_secret="<YOUR CLIENT SECRET>"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
service = service_builder.build_service(service=Service.CHAT, key=credentials)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### 2. Using an `OAuthKey`
|
|
77
104
|
```
|
|
78
105
|
from service_framework.services import Service
|
|
79
106
|
from service_framework import service_builder
|
|
@@ -93,12 +120,3 @@ Here, we are creating the key as an `OAuthKey` object as we have clearly got the
|
|
|
93
120
|
tokens and client_[id|secret] from elsewhere. Creating the service is then as
|
|
94
121
|
simple as invoking the `service_builder.build_service` method which will return
|
|
95
122
|
you a service you can use.
|
|
96
|
-
|
|
97
|
-
### Other parameters
|
|
98
|
-
|
|
99
|
-
`service_builder.build_service()` can also take 2 other optional parameters.
|
|
100
|
-
|
|
101
|
-
| Parameter | Description |
|
|
102
|
-
| :-: | - |
|
|
103
|
-
| api_key | Some APIs require an API key as well as the OAuth credentials |
|
|
104
|
-
| extra_scopes | Any extra OAUth scopes required for the operation |
|
|
@@ -18,10 +18,12 @@ ready for use.
|
|
|
18
18
|
|
|
19
19
|
`service_builder.build_service()` needs two mandatory pieces of information:
|
|
20
20
|
|
|
21
|
-
| Parameter | Description |
|
|
22
|
-
| :-: | - |
|
|
23
|
-
| key | The credentials to use to authenticate the user to the service it has to create |
|
|
24
|
-
| service | The Google API endpoint it is trying to connect to. |
|
|
21
|
+
| Parameter | Type | Description |
|
|
22
|
+
| :-: | - | - |
|
|
23
|
+
| key | str | The credentials to use to authenticate the user to the service it has to create. |
|
|
24
|
+
| service | Service | The Google API endpoint it is trying to connect to. |
|
|
25
|
+
| api_key | _See below_ | _Optional_ An API key for those services which require an API key in addition to credentials. |
|
|
26
|
+
| extra_scopes | List[str] | _Optional_ Extra OAuth scopes needed. |
|
|
25
27
|
|
|
26
28
|
### `key`
|
|
27
29
|
|
|
@@ -29,7 +31,7 @@ These can be supplied in one of 4 ways.
|
|
|
29
31
|
|
|
30
32
|
1. A valid `google.oauth2.Credentials` object, created and passed to the
|
|
31
33
|
service builder.
|
|
32
|
-
1.
|
|
34
|
+
1. A `str` which is the name of a local file containing the `json`
|
|
33
35
|
representation of an OAuth credentials object.
|
|
34
36
|
1. A `Mapping` object which is a `json` keyfile `dict`
|
|
35
37
|
2. An `OAuthKey` object from this package, which is a `dataclass` object
|
|
@@ -38,11 +40,36 @@ These can be supplied in one of 4 ways.
|
|
|
38
40
|
### `service`
|
|
39
41
|
|
|
40
42
|
This is an Enum in the `service_framework.service` module, which defines
|
|
41
|
-
the Google service you're planning to connect to. All
|
|
42
|
-
|
|
43
|
+
the Google service you're planning to connect to. All the standard Google
|
|
44
|
+
services are included (as of the date listed in the `Services.py` file).
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
If a
|
|
47
|
+
new service has been added but this library has yet to be updated, you can
|
|
48
|
+
request it by using either `Service('<UNLISTED SERVICE>')` or
|
|
49
|
+
`Service.from_value('<UNLISTED SERVICE>')`. This will cause the library to
|
|
50
|
+
attempt to fetch the service's definition from Google and will create an
|
|
51
|
+
entry in the enum for this new service.
|
|
45
52
|
|
|
53
|
+
### Examples
|
|
54
|
+
|
|
55
|
+
#### 1. Using `Credentials`
|
|
56
|
+
```
|
|
57
|
+
from service_framework.services import Service
|
|
58
|
+
from service_framework import service_builder
|
|
59
|
+
from google.oauth2 import credentials as oauth
|
|
60
|
+
|
|
61
|
+
credentials = oauth.Credentials(
|
|
62
|
+
access_token="<YOUR ACCESS TOKEN>",
|
|
63
|
+
refresh_token="<YOUR REFRESH TOKEN>",
|
|
64
|
+
token_uri="https://oauth2.googleapis.com/token",
|
|
65
|
+
client_id="<YOUR CLIENT ID>",
|
|
66
|
+
client_secret="<YOUR CLIENT SECRET>"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
service = service_builder.build_service(service=Service.CHAT, key=credentials)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### 2. Using an `OAuthKey`
|
|
46
73
|
```
|
|
47
74
|
from service_framework.services import Service
|
|
48
75
|
from service_framework import service_builder
|
|
@@ -62,12 +89,3 @@ Here, we are creating the key as an `OAuthKey` object as we have clearly got the
|
|
|
62
89
|
tokens and client_[id|secret] from elsewhere. Creating the service is then as
|
|
63
90
|
simple as invoking the `service_builder.build_service` method which will return
|
|
64
91
|
you a service you can use.
|
|
65
|
-
|
|
66
|
-
### Other parameters
|
|
67
|
-
|
|
68
|
-
`service_builder.build_service()` can also take 2 other optional parameters.
|
|
69
|
-
|
|
70
|
-
| Parameter | Description |
|
|
71
|
-
| :-: | - |
|
|
72
|
-
| api_key | Some APIs require an API key as well as the OAuth credentials |
|
|
73
|
-
| extra_scopes | Any extra OAUth scopes required for the operation |
|
|
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-service-builder"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.1.1"
|
|
8
8
|
authors = [{ name = "David Harcombe", email = "david.harcombe@gmail.com" }]
|
|
9
9
|
description = "Helper library for easier creation of Google services."
|
|
10
10
|
readme = "README.md"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-service-builder
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: Helper library for easier creation of Google services.
|
|
5
5
|
Author-email: David Harcombe <david.harcombe@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -49,10 +49,12 @@ ready for use.
|
|
|
49
49
|
|
|
50
50
|
`service_builder.build_service()` needs two mandatory pieces of information:
|
|
51
51
|
|
|
52
|
-
| Parameter | Description |
|
|
53
|
-
| :-: | - |
|
|
54
|
-
| key | The credentials to use to authenticate the user to the service it has to create |
|
|
55
|
-
| service | The Google API endpoint it is trying to connect to. |
|
|
52
|
+
| Parameter | Type | Description |
|
|
53
|
+
| :-: | - | - |
|
|
54
|
+
| key | str | The credentials to use to authenticate the user to the service it has to create. |
|
|
55
|
+
| service | Service | The Google API endpoint it is trying to connect to. |
|
|
56
|
+
| api_key | _See below_ | _Optional_ An API key for those services which require an API key in addition to credentials. |
|
|
57
|
+
| extra_scopes | List[str] | _Optional_ Extra OAuth scopes needed. |
|
|
56
58
|
|
|
57
59
|
### `key`
|
|
58
60
|
|
|
@@ -60,7 +62,7 @@ These can be supplied in one of 4 ways.
|
|
|
60
62
|
|
|
61
63
|
1. A valid `google.oauth2.Credentials` object, created and passed to the
|
|
62
64
|
service builder.
|
|
63
|
-
1.
|
|
65
|
+
1. A `str` which is the name of a local file containing the `json`
|
|
64
66
|
representation of an OAuth credentials object.
|
|
65
67
|
1. A `Mapping` object which is a `json` keyfile `dict`
|
|
66
68
|
2. An `OAuthKey` object from this package, which is a `dataclass` object
|
|
@@ -69,11 +71,36 @@ These can be supplied in one of 4 ways.
|
|
|
69
71
|
### `service`
|
|
70
72
|
|
|
71
73
|
This is an Enum in the `service_framework.service` module, which defines
|
|
72
|
-
the Google service you're planning to connect to. All
|
|
73
|
-
|
|
74
|
+
the Google service you're planning to connect to. All the standard Google
|
|
75
|
+
services are included (as of the date listed in the `Services.py` file).
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
If a
|
|
78
|
+
new service has been added but this library has yet to be updated, you can
|
|
79
|
+
request it by using either `Service('<UNLISTED SERVICE>')` or
|
|
80
|
+
`Service.from_value('<UNLISTED SERVICE>')`. This will cause the library to
|
|
81
|
+
attempt to fetch the service's definition from Google and will create an
|
|
82
|
+
entry in the enum for this new service.
|
|
76
83
|
|
|
84
|
+
### Examples
|
|
85
|
+
|
|
86
|
+
#### 1. Using `Credentials`
|
|
87
|
+
```
|
|
88
|
+
from service_framework.services import Service
|
|
89
|
+
from service_framework import service_builder
|
|
90
|
+
from google.oauth2 import credentials as oauth
|
|
91
|
+
|
|
92
|
+
credentials = oauth.Credentials(
|
|
93
|
+
access_token="<YOUR ACCESS TOKEN>",
|
|
94
|
+
refresh_token="<YOUR REFRESH TOKEN>",
|
|
95
|
+
token_uri="https://oauth2.googleapis.com/token",
|
|
96
|
+
client_id="<YOUR CLIENT ID>",
|
|
97
|
+
client_secret="<YOUR CLIENT SECRET>"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
service = service_builder.build_service(service=Service.CHAT, key=credentials)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### 2. Using an `OAuthKey`
|
|
77
104
|
```
|
|
78
105
|
from service_framework.services import Service
|
|
79
106
|
from service_framework import service_builder
|
|
@@ -93,12 +120,3 @@ Here, we are creating the key as an `OAuthKey` object as we have clearly got the
|
|
|
93
120
|
tokens and client_[id|secret] from elsewhere. Creating the service is then as
|
|
94
121
|
simple as invoking the `service_builder.build_service` method which will return
|
|
95
122
|
you a service you can use.
|
|
96
|
-
|
|
97
|
-
### Other parameters
|
|
98
|
-
|
|
99
|
-
`service_builder.build_service()` can also take 2 other optional parameters.
|
|
100
|
-
|
|
101
|
-
| Parameter | Description |
|
|
102
|
-
| :-: | - |
|
|
103
|
-
| api_key | Some APIs require an API key as well as the OAuth credentials |
|
|
104
|
-
| extra_scopes | Any extra OAUth scopes required for the operation |
|
|
@@ -8,7 +8,8 @@ python_service_builder.egg-info/requires.txt
|
|
|
8
8
|
python_service_builder.egg-info/top_level.txt
|
|
9
9
|
service_framework/__init__.py
|
|
10
10
|
service_framework/__init_test.py
|
|
11
|
-
service_framework/list_services.py
|
|
12
11
|
service_framework/service_builder.py
|
|
12
|
+
service_framework/service_finder.py
|
|
13
13
|
service_framework/services.py
|
|
14
|
-
service_framework/services_test.py
|
|
14
|
+
service_framework/services_test.py
|
|
15
|
+
service_framework/update_services.py
|
|
@@ -12,27 +12,11 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import dataclasses
|
|
15
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, Mapping
|
|
16
16
|
|
|
17
17
|
import dataclasses_json
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def lazy_property(f: Callable):
|
|
21
|
-
"""Decorator that makes a property lazy-evaluated.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
f: the function to convert to a lazy property.
|
|
25
|
-
"""
|
|
26
|
-
attr_name = '_lazy_' + f.__name__
|
|
27
|
-
|
|
28
|
-
@property
|
|
29
|
-
def _lazy_property(self) -> Any:
|
|
30
|
-
if not hasattr(self, attr_name):
|
|
31
|
-
setattr(self, attr_name, f(self))
|
|
32
|
-
return getattr(self, attr_name)
|
|
33
|
-
return _lazy_property
|
|
34
|
-
|
|
35
|
-
|
|
36
20
|
def metadata(base: Mapping[str, Any], **custom) -> Mapping[str, Any]:
|
|
37
21
|
"""Merges properties into the metadata and returns the merged result.
|
|
38
22
|
|
|
@@ -119,6 +103,6 @@ def camel_field(default: Any = None,
|
|
|
119
103
|
@dataclasses.dataclass
|
|
120
104
|
class ServiceDefinition(object):
|
|
121
105
|
"""Defines a Google Service for the builder."""
|
|
122
|
-
service_name:
|
|
123
|
-
version:
|
|
124
|
-
discovery_service_url:
|
|
106
|
+
service_name: str = camel_field()
|
|
107
|
+
version: str = camel_field()
|
|
108
|
+
discovery_service_url: str = camel_field()
|
|
@@ -16,39 +16,46 @@ import json
|
|
|
16
16
|
import urllib.parse
|
|
17
17
|
import urllib.request
|
|
18
18
|
from collections import namedtuple
|
|
19
|
-
from contextlib import closing
|
|
20
|
-
from pprint import pprint
|
|
19
|
+
from contextlib import closing
|
|
21
20
|
from typing import Mapping
|
|
22
21
|
from urllib.request import urlopen
|
|
23
22
|
|
|
24
|
-
from
|
|
23
|
+
from service_framework import ServiceDefinition
|
|
25
24
|
|
|
26
|
-
from service_framework.services import ServiceDefinition
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
"""
|
|
26
|
+
class ServiceFinder(object):
|
|
27
|
+
"""ServiceFinder
|
|
28
|
+
"""
|
|
29
|
+
def __call__(cls, value, *args, **kwargs) -> ServiceDefinition:
|
|
30
|
+
"""What to do when the `ServiceFinder` is invoked
|
|
30
31
|
|
|
32
|
+
Usage:
|
|
33
|
+
```
|
|
34
|
+
finder = ServiceFinder()
|
|
35
|
+
finder('CHAT')
|
|
36
|
+
```
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
api = ServiceLister().find(name=value.lower())
|
|
35
|
-
if api:
|
|
36
|
-
(service_name, version, url) = api[value.upper()]
|
|
37
|
-
definition = ServiceDefinition(
|
|
38
|
-
service_name=service_name,
|
|
39
|
-
version=version,
|
|
40
|
-
discovery_service_url=url)
|
|
41
|
-
return definition
|
|
38
|
+
Args:
|
|
39
|
+
value (str): the name of the service to find
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
Raises:
|
|
42
|
+
Exception: No valid Google service of this name exists
|
|
45
43
|
|
|
44
|
+
Returns:
|
|
45
|
+
ServiceDefinition: the service definition
|
|
46
|
+
"""
|
|
47
|
+
if api := ServiceFinder.find(name=value.lower()):
|
|
48
|
+
return api[value.upper()]
|
|
49
|
+
|
|
50
|
+
else:
|
|
51
|
+
raise Exception(f'No Google service found with the name {value.upper()}')
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
def find_all(
|
|
49
|
-
return
|
|
53
|
+
@classmethod
|
|
54
|
+
def find_all(cls) -> Mapping[str, ServiceDefinition]:
|
|
55
|
+
return cls.find(None)
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
@classmethod
|
|
58
|
+
def find(cls, name: str) -> Mapping[str, ServiceDefinition]:
|
|
52
59
|
Components = namedtuple(
|
|
53
60
|
typename='Components',
|
|
54
61
|
field_names=['scheme', 'netloc', 'url', 'path', 'query', 'fragment']
|
|
@@ -76,21 +83,7 @@ class ServiceLister(object):
|
|
|
76
83
|
api_list = json.loads(_api_list.read())
|
|
77
84
|
if items := api_list.get('items', None):
|
|
78
85
|
for api in items:
|
|
79
|
-
apis[api['name'].upper()] = (
|
|
86
|
+
apis[api['name'].upper()] = ServiceDefinition(
|
|
87
|
+
api['name'], api['version'], api['discoveryRestUrl'])
|
|
80
88
|
|
|
81
89
|
return apis
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def main(unused) -> None:
|
|
85
|
-
del unused
|
|
86
|
-
|
|
87
|
-
# apis = ServiceLister().find(name='CHAT'.lower())
|
|
88
|
-
apis = ServiceLister().find_all()
|
|
89
|
-
# pprint(apis, indent=2)
|
|
90
|
-
for k, v in apis.items():
|
|
91
|
-
print(f'{k} = ServiceDefinition{v}')
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if __name__ == '__main__':
|
|
95
|
-
with suppress(SystemExit):
|
|
96
|
-
app.run(main)
|