Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
it-bott-integrasjoner
cim-client
Commits
fbc26353
Commit
fbc26353
authored
Nov 04, 2020
by
Trond Aasan
Browse files
CIM-27 Refactor
Use CimEndpoints in CimClient constructor instead of delegating arguments
parent
4b4dec6b
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
fbc26353
...
...
@@ -3,12 +3,13 @@
Python client for accessing the CIM-API.
```
python
from
cim_client
import
CimClient
from
cim_client
import
CimClient
,
CimEndpoints
from
cim_client.models
import
Person
,
PersonList
c
=
CimClient
(
url
=
'https://example.com'
,
update_person_url
=
'/_webservices/?ws=contacts/upsert/1.0'
,
delete_person_url
=
'/_webservices/?ws=contacts/delete/1.0'
,
tokens
=
{
'api_key'
:
{
'X-Gravitee-API-Key'
:
'c-d-a-b'
},})
c
=
CimClient
(
CimEndpoints
(
url
=
'https://example.com'
,
update_person_url
=
'/_webservices/?ws=contacts/upsert/1.0'
,
delete_person_url
=
'/_webservices/?ws=contacts/delete/1.0'
),
tokens
=
{
'api_key'
:
{
'X-Gravitee-API-Key'
:
'c-d-a-b'
},})
upd_schema
=
c
.
get_update_person_schema
()
del_schema
=
c
.
get_delete_person_schema
()
...
...
cim_client/__init__.py
View file @
fbc26353
from
.client
import
CimClient
from
.client
import
CimClient
,
CimEndpoints
from
.version
import
get_distribution
__all__
=
[
'CimClient'
]
__all__
=
[
'CimClient'
,
'CimEndpoints'
]
__version__
=
get_distribution
().
version
cim_client/client.py
View file @
fbc26353
...
...
@@ -84,9 +84,7 @@ class CimClient(object):
}
def
__init__
(
self
,
url
:
str
,
update_person_url
:
Union
[
str
,
None
]
=
None
,
delete_person_url
:
Union
[
str
,
None
]
=
None
,
endpoints
:
Union
[
CimEndpoints
,
dict
],
tokens
:
dict
=
None
,
headers
:
Union
[
None
,
dict
]
=
None
,
return_objects
:
bool
=
True
,
...
...
@@ -95,25 +93,17 @@ class CimClient(object):
):
"""
CIM API client.
:param str url: Base API URL
:param str update_person_url: Relative URL to update person endpoint
:param str delete_person_url: Relative URL to delete person endpoint
:param CimEndpoints endpoints: API endpoints
:param dict tokens: Tokens for the different APIs
:param dict headers: Append extra headers to all requests
:param bool return_objects: Return objects instead of raw JSON
:param bool use_sessions: Keep HTTP connections alive (default True)
:param tuple auth: (username, password) for simple http auth
"""
if
update_person_url
and
delete_person_url
:
self
.
urls
=
CimEndpoints
(
url
,
update_person_url
,
delete_person_url
)
elif
update_person_url
:
self
.
urls
=
CimEndpoints
(
url
,
update_person_url
)
elif
delete_person_url
:
self
.
urls
=
CimEndpoints
(
url
,
delete_person_url
=
delete_person_url
)
else
:
self
.
urls
=
CimEndpoints
(
url
)
if
isinstance
(
endpoints
,
dict
):
endpoints
=
CimEndpoints
(
**
endpoints
)
self
.
endpoints
=
endpoints
self
.
tokens
=
tokens
if
tokens
else
{}
self
.
auth
=
auth
if
auth
else
None
self
.
headers
=
merge_dicts
(
self
.
default_headers
,
headers
)
...
...
@@ -180,7 +170,7 @@ class CimClient(object):
checks whether the schema has changed lately so you don't update
using an outdated schema.
"""
url
=
self
.
url
s
.
get_update_person_schema
()
url
=
self
.
endpoint
s
.
get_update_person_schema
()
response
=
self
.
get
(
url
,
auth
=
self
.
auth
,
headers
=
self
.
tokens
.
get
(
'api_key'
,
None
))
...
...
@@ -195,7 +185,7 @@ class CimClient(object):
checks whether the schema has changed lately so you don't update
using an outdated schema.
"""
url
=
self
.
url
s
.
get_delete_person_schema
()
url
=
self
.
endpoint
s
.
get_delete_person_schema
()
response
=
self
.
get
(
url
,
auth
=
self
.
auth
,
headers
=
self
.
tokens
.
get
(
'api_key'
,
None
))
...
...
@@ -213,9 +203,9 @@ class CimClient(object):
someone. You will have to compare with what you posted.
"""
if
delete
:
url
=
self
.
url
s
.
delete_person
()
url
=
self
.
endpoint
s
.
delete_person
()
else
:
url
=
self
.
url
s
.
update_person
()
url
=
self
.
endpoint
s
.
update_person
()
if
type
(
persondata
)
is
list
:
persondata
=
PersonList
(
persons
=
persondata
)
...
...
example-config.json
View file @
fbc26353
{
"_"
:
"Config example for the cim_client command-line utility"
,
"client"
:
{
"url"
:
"https://api-gateway.uio.no/sws/v2/"
,
"update_person_url"
:
"/_webservices/?ws=contacts/upsert/1.0"
,
"delete_person_url"
:
"/_webservices/?ws=contacts/delete/1.0"
,
"endpoints"
:
{
"url"
:
"https://api-gateway.uio.no/sws/v2/"
,
"update_person_url"
:
"/_webservices/?ws=contacts/upsert/1.0"
,
"delete_person_url"
:
"/_webservices/?ws=contacts/delete/1.0"
},
"tokens"
:
{
"api_key"
:
"foooooo-bbbbbb-aaaaaa-rrrrr"
},
...
...
tests/conftest.py
View file @
fbc26353
...
...
@@ -25,7 +25,7 @@ def custom_endpoints(baseurl):
@
pytest
.
fixture
def
client
(
baseurl
):
return
CimClient
(
baseurl
)
return
CimClient
(
CimEndpoints
(
baseurl
)
)
@
pytest
.
fixture
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment