diff --git a/docs/channels.md b/docs/channels.md index c1be396..20f375a 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -11,14 +11,14 @@ --- - + ## class `Channels` - + ### method `__init__` @@ -35,7 +35,7 @@ __init__(url: str) --- - + ### method `create` @@ -47,7 +47,7 @@ Creates channel entity in the database --- - + ### method `create_bulk` @@ -59,7 +59,7 @@ Creates multiple channels in a bulk --- - + ### method `disable` @@ -71,7 +71,7 @@ Deletes a channel entity from database --- - + ### method `get` @@ -83,7 +83,7 @@ Gets a channel entity for a logged-in user --- - + ### method `get_all` @@ -95,7 +95,7 @@ Gets all channels from database --- - + ### method `get_by_thing` @@ -107,7 +107,7 @@ Gets all channels to which a specific thing is connected to --- - + ### method `identify_thing` @@ -119,7 +119,7 @@ Validates thing's key and returns it's ID if key is valid --- - + ### method `update` diff --git a/docs/groups.md b/docs/groups.md index fc739fb..571a54c 100644 --- a/docs/groups.md +++ b/docs/groups.md @@ -35,7 +35,7 @@ __init__(url: str) --- - + ### method `assign` @@ -71,7 +71,7 @@ Creates group entity in the database --- - + ### method `disable` @@ -107,7 +107,7 @@ Gets all groups from database --- - + ### method `members` @@ -119,7 +119,7 @@ Get list of members ID's from group --- - + ### method `memberships` @@ -143,7 +143,7 @@ Gets parents for a specific group from database --- - + ### method `share_groups` @@ -155,7 +155,7 @@ Adds access rights on thing groups to the user group --- - + ### method `unassign` diff --git a/docs/things.md b/docs/things.md index 8605b50..32d329d 100644 --- a/docs/things.md +++ b/docs/things.md @@ -35,7 +35,19 @@ __init__(url: str) --- - + + +### method `authorise_thing` + +```python +authorise_thing(access_request: dict, token: str) +``` + +Authorises thing + +--- + + ### method `connect` @@ -47,7 +59,7 @@ Connects thing and channel --- - + ### method `connects` @@ -83,7 +95,7 @@ Creates multiple things in a bulk --- - + ### method `disable` @@ -95,7 +107,7 @@ Deletes a thing entity from database --- - + ### method `disconnect` @@ -107,7 +119,7 @@ Disconnect thing and channel --- - + ### method `disconnects` @@ -155,6 +167,18 @@ Gets all things to which a specific thing is connected to --- + + +### method `share_thing` + +```python +share_thing(user_id: str, channel_id: str, actions: dict, token: str) +``` + +Share thing + +--- + ### method `update` @@ -165,6 +189,42 @@ update(thing_id: str, thing: dict, token: str) Updates thing entity +--- + + + +### method `update_thing_owner` + +```python +update_thing_owner(thing_id: str, thing: dict, token: str) +``` + +Updates thing secret + +--- + + + +### method `update_thing_secret` + +```python +update_thing_secret(thing_id: str, thing: dict, token: str) +``` + +Updates thing secret + +--- + + + +### method `update_thing_tags` + +```python +update_thing_tags(thing_id: str, thing: dict, token: str) +``` + +Updates thing secret + diff --git a/docs/users.md b/docs/users.md index ff5d96f..867b3dc 100644 --- a/docs/users.md +++ b/docs/users.md @@ -33,6 +33,18 @@ __init__(url: str) +--- + + + +### method `authorise_user` + +```python +authorise_user(access_request: dict, token: str) +``` + +Authorises user + --- @@ -47,7 +59,7 @@ Registers new user account given email and password. New account will be uniquel --- - + ### method `disable` @@ -59,7 +71,7 @@ Disables an enabled user account for a given user ID. --- - + ### method `enable` @@ -71,7 +83,7 @@ Enables a disabled user account for a given user ID. --- - + ### method `get` @@ -83,7 +95,7 @@ Gets a user information --- - + ### method `get_all` @@ -107,7 +119,43 @@ Generates an access token when provided with proper credentials. --- - + + +### method `refresh_token` + +```python +refresh_token(user: dict, token: str) +``` + +Refreshes Access and Refresh Token used for authenticating into the system. + +--- + + + +### method `reset_password` + +```python +reset_password(password: str, confirm_password: str, token: str) +``` + +Changes user password with the reset_request token + +--- + + + +### method `reset_password_request` + +```python +reset_password_request(email: str, url: str) +``` + +User Password reset request + +--- + + ### method `update` @@ -119,7 +167,7 @@ Updates info on currently logged in user. Info is updated using authorization us --- - + ### method `update_password` @@ -129,6 +177,42 @@ update_password(old_secret: str, new_secret: str, user_token: str) Changes user password +--- + + + +### method `update_user_identity` + +```python +update_user_identity(user: dict, user_token: str) +``` + +Updates Identity of the user + +--- + + + +### method `update_user_owner` + +```python +update_user_owner(user: dict, user_token: str) +``` + +Updating user tags in the database + +--- + + + +### method `update_user_tags` + +```python +update_user_tags(user: dict, user_token: str) +``` + +Updating user tags in the database + diff --git a/examples/examples.py b/examples/examples.py index 036f3ca..c2becbf 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -7,15 +7,15 @@ things_url=default_url + ":9000", reader_url=default_url + ":9204", http_adapter_url=default_url, - certs_url=default_url + ":8204", - bootstrap_url=default_url + ":8202", + certs_url=default_url + ":9019", + bootstrap_url=default_url + ":9013", auth_url=default_url, ) -''' + """To start working with the Mainflux system, you need to create a user account""" mf_resp = mfsdk.users.create( - user={"credentials": {"identity": "example25@example.com", "secret": "12345678"}}, + user={"credentials": {"identity": "", "secret": ""}}, token="", ) if mf_resp.error.status == 0: @@ -25,81 +25,173 @@ """To log in to the Mainflux system, you need to create a user token""" mf_resp = mfsdk.users.login( - user={ "identity" : "example20@example.com", "secret": "12345678"} + user={ "identity" : "", "secret": ""} ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + +"""Refreshes Access and Refresh Token used for authenticating into the system.""" +user= { + "credentials": { + "identity": "", + "secret": "" + }, + "id": "", + "name": "" +} +mf_resp = mfsdk.users.refresh_token( + user= user, + token="" +) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + """You can always check the user entity that is logged in by entering the user ID and token""" -mf_resp = mfsdk.users.get(user_id="0f047968-b170-4dd4-85f5-6e03e1b3798e", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTE3NTIxOTcsImlhdCI6MTY5MTc1MTI5NywiaWRlbnRpdHkiOiJleGFtcGxlMTJAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiIwZjA0Nzk2OC1iMTcwLTRkZDQtODVmNS02ZTAzZTFiMzc5OGUiLCJ0eXBlIjoiYWNjZXNzIn0.REa8wv-veZm2fpAeLe3jO9SMYMnyPrcT07YTmx4M_lOE3wYYal26HYp8RHd6z3Igy7ccadSKiqaygyvrpkMLzw") +mf_resp = mfsdk.users.get(user_id="", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' -"""Updating user entities in the database""" + +"""Updates user entities in the database""" user = { - "id": "", - "name": "", + "id": "", + "name": "", "metadata": { "foo": "bar" } } -mf_resp = mfsdk.users.update( - user_token="", user=user -) +mf_resp = mfsdk.users.update(user_token="", user=user) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Updates user identity in the database""" +user = { + "credentials": { + "identity": "", + }, + "id": "" +} +mf_resp = mfsdk.users.update_user_identity(user_token="", user=user) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + +"""Updates user tags in the database""" +user = { + "id": "", + "name": "", + "tags": [ + "yellow", + "orange" + ] +} +mf_resp = mfsdk.users.update_user_tags(user_token="", user=user) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Updates user owner in the database""" +user = { + "credentials": { + "identity": "", + "secret": "" + }, + "id": "", + "owner": "" +} +mf_resp = mfsdk.users.update_user_owner(user_token="", user=user) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""User Password reset request""" +mf_resp = mfsdk.users.reset_password_request(email= "", url= "") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""User Password reset with the reset_request token""" +mf_resp = mfsdk.users.reset_password(password="", confirm_password="", token= "") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + """You can get all users in the database by calling the get_all () function""" mf_resp = mfsdk.users.get_all( query_params={"offset": 0, "limit": 5}, - admin_token="", + user_token="" ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' -mf_resp = mfsdk.users.disable(user_id="46c266a8-084d-4863-b013-9d27be7617e5", user_token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTE4MTIxMjQsImlhdCI6MTY5MTc1ODEyNCwiaWRlbnRpdHkiOiJleGFtcGxlMTVAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiJhZTE4ZjZiZS01OTJmLTQ1NjAtOGIxNy1jMmUxYmYyNzNhYWUiLCJ0eXBlIjoiYWNjZXNzIn0.SO3Z6-mNbYFEuJDlO1E477nQblg0UR6r0C7aR8jhRcTpDA62isovYjXhdoDdjPrRrDb7K1hHSHrxHhMFPiYz7w") + +"""Disables user""" +mf_resp = mfsdk.users.disable(user_id="", user_token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) - -mf_resp = mfsdk.users.enable(user_id="46c266a8-084d-4863-b013-9d27be7617e5", user_token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTE4MTIxMjQsImlhdCI6MTY5MTc1ODEyNCwiaWRlbnRpdHkiOiJleGFtcGxlMTVAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiJhZTE4ZjZiZS01OTJmLTQ1NjAtOGIxNy1jMmUxYmYyNzNhYWUiLCJ0eXBlIjoiYWNjZXNzIn0.SO3Z6-mNbYFEuJDlO1E477nQblg0UR6r0C7aR8jhRcTpDA62isovYjXhdoDdjPrRrDb7K1hHSHrxHhMFPiYz7w") + +"""Enables user""" +mf_resp = mfsdk.users.enable(user_id="", user_token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -"""Changing the user password can be done by calling -the update password function""" -''' -""" +"""Changing the user password can be done by calling the update password function""" mf_resp = mfsdk.users.update_password( - old_secret="", secret="", - user_token="" + old_secret="", new_secret="", + user_token="" ) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Authorising a User""" +access_request = { + "subject": "", + "object": "", + "Action": "", + "Entity_type": "" +} +mf_resp = mfsdk.users.authorise_user(access_request=access_request, token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) +"""Authorising a Thing""" +access_request = { + "subject": "", + "object": "", + "Action": "", + "Entity_type": "" +} +mf_resp = mfsdk.things.authorise_thing(access_request=access_request, token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -""" -''' + """To create a thing, you need the thing name and a user token""" mf_resp = mfsdk.things.create( - thing={"name": "thing1"}, token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ") + thing={"name": ""}, token="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -108,8 +200,8 @@ """You can create multiple things at once by entering a series of things structures and a user token""" mf_resp = mfsdk.things.create_bulk( - things=[{"name": "thing_8"}, {"name": "thing_9"}, {"name": "thing_10"}], - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ", + things=[{"name": ""}, {"name": ""}, {"name": ""}], + token="", ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -117,7 +209,7 @@ print(mf_resp.error.message) """You can get thing information by entering the thing ID and user token""" -mf_resp = mfsdk.things.get(token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ", thing_id="6d591627-8657-43af-bfaa-79047b5f8ec3") +mf_resp = mfsdk.things.get(thing_id= "", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -125,23 +217,62 @@ """You can get all things in the database by calling the get_all () function""" mf_resp = mfsdk.things.get_all( - query_params={"offset": 0, "limit": 5}, token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ" + query_params={"offset": 0, "limit": 5}, token="" ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -"""Updating a thing entity in a database""" +"""Updates a thing entity in a database""" mf_resp = mfsdk.things.update( - thing_id="6d591627-8657-43af-bfaa-79047b5f8ec3", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ", thing={"name": "thing_1"} + thing_id="", token="", thing={"name": ""} ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -"You can get all thing connected to channel" +"""Updates a thing secret in a database""" +mf_resp = mfsdk.things.update_thing_secret( + thing_id="", token="", thing={"secret": ""} +) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Updates a thing's tags in a database""" +thing= { + "id": "", + "name": "", + "tags": [ + "dev","back" + ] + } +mf_resp = mfsdk.things.update_thing_tags( + thing_id="", token="", thing=thing +) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Updates a thing's owner""" +thing= { + "id": "", + "name": "", + "owner": "", +} +mf_resp = mfsdk.things.update_thing_owner( + thing_id="", token="", thing=thing +) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""You can get all thing connected to channel""" mf_resp = mfsdk.things.get_by_channel( channel_id="", query_params={"offset": 1, "limit": 5}, @@ -153,7 +284,7 @@ print(mf_resp.error.message) """To disable a thing you need a thing ID and a user token""" -mf_resp = mfsdk.things.disable(thing_id="2ad76a79-640b-44c3-ab1c-3894d4013391", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ") +mf_resp = mfsdk.things.disable(thing_id="", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -161,7 +292,7 @@ """Connect thing to channel""" mf_resp = mfsdk.things.connect( - channel_id="6a4c094d-b192-4e7b-837f-6d2a2bae12d5", thing_id="769c8d58-bc7e-4003-8e5b-84301534ba7f", action="m_write", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMzI1ODUsImlhdCI6MTY5MjI3ODU4NSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.hAJllwSCLDOqJseCKkTtw4qI9EyuBat6qaLGsvdsU-OGVS6-VkkK6boiDQ-_Men9CT6oUpzzTmW3e0dRF72j3g" + channel_id="", thing_id="", action="", token="" ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -170,7 +301,7 @@ """Disconnect thing from channel""" mf_resp = mfsdk.things.disconnect( - channel_id="2b7ff10e-9294-47a9-a66b-e8f7de7c5a8b", thing_id="6d591627-8657-43af-bfaa-79047b5f8ec3", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMzI1ODUsImlhdCI6MTY5MjI3ODU4NSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.hAJllwSCLDOqJseCKkTtw4qI9EyuBat6qaLGsvdsU-OGVS6-VkkK6boiDQ-_Men9CT6oUpzzTmW3e0dRF72j3g" + channel_id="", thing_id="", token="" ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -179,10 +310,10 @@ """Connect things to channels""" mf_resp = mfsdk.things.connects( - thing_ids=["769c8d58-bc7e-4003-8e5b-84301534ba7f", "a937d27a-b0aa-4e4f-a85e-bb95bf0ac1bf"], - channel_ids=["6a4c094d-b192-4e7b-837f-6d2a2bae12d5"], - action="m_read", - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ", + thing_ids=["", ""], + channel_ids=[""], + action="", + token="", ) if mf_resp.error.status == 0: @@ -201,9 +332,21 @@ else: print(mf_resp.error.message) +"""Share thing""" +mf_resp = mfsdk.things.share_thing( + channel_id= "", + user_id= "", + actions= ["action"], + token= "" +) +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + """To create a channel, you need a channel and a token""" mf_resp = mfsdk.channels.create( - channel={"name": "channel_3"}, token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ") + channel={"name": ""}, token="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -211,8 +354,8 @@ """As with things, you can create multiple channels at once""" mf_resp = mfsdk.channels.create_bulk( - channels=[{"name": "channel_6"}, {"name": "channel_7"}], - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ", + channels=[{"name": ""}, {"name": ""}], + token="", ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -221,18 +364,17 @@ """Update channel entities in the database""" mf_resp = mfsdk.channels.update( - channel_id="2b7ff10e-9294-47a9-a66b-e8f7de7c5a8b", - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ", - channel={"name": "channel_3"}, + channel_id="", + token="", + channel={"name": ""}, ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + """You can get channel information by entering the channel ID and user token""" -mf_resp = mfsdk.channels.get(token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ", channel_id="2b7ff10e-9294-47a9-a66b-e8f7de7c5a8b") +mf_resp = mfsdk.channels.get(token="", channel_id="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -241,7 +383,7 @@ """You can get all channels in the database by calling the get_all () function""" mf_resp = mfsdk.channels.get_all( - query_params={"offset": 0, "limit": 5}, token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ" + query_params={"offset": 0, "limit": 5}, token="" ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -250,78 +392,72 @@ """A list of all the channels to which a given thing is connected""" mf_resp = mfsdk.channels.get_by_thing( - thing_id="2ad76a79-640b-44c3-ab1c-3894d4013391", query_params={"offset": 0, "limit": 5}, - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ" + thing_id="", query_params={"offset": 0, "limit": 5}, + token="" ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) - """Identifies thing when given thing key""" -mf_resp = mfsdk.channels.identify_thing(thing_key="a0c5471a-b7a6-4337-81af-b6113f41d898", user_token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ") +mf_resp = mfsdk.channels.identify_thing(thing_key="", user_token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) - """Delete channels from the database""" mf_resp = mfsdk.channels.disable( - channel_id="2b7ff10e-9294-47a9-a66b-e8f7de7c5a8b", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIwNTUxNzIsImlhdCI6MTY5MjAwMTE3MiwiaWRlbnRpdHkiOiJleGFtcGxlMTlAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI2OWFkNjk0Ny0xZGQ1LTRmNzItYTQ3NC1kMGZmNDE0MTUyYTEiLCJ0eXBlIjoiYWNjZXNzIn0.mlfRaQG69XmKUei9KW2287Kvk7_EiuAVeGbmq9aojA2FzzoicRxsTWkwEJGuhwWBHxQgBMe99j5rdb6EbJHkWQ") + channel_id="", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + """To create a group, you need the group name and a user token""" mf_resp = mfsdk.groups.create( - group={"name": "group_D", "parent_id": "d6198103-4724-427e-b052-e6ad544c8864"}, token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIyNjk5MzEsImlhdCI6MTY5MjIxNTkzMSwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.vDHq7AOvppvknsKPdAxnGjsErUZ25_gAbZJ1zom3QqZ1sNAoPPU5AyVor-EgMeq1yvhggh8wzLx-9TSK6pQcCA") + group={"name": "", "parent_id": ""}, token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) """You can get group information by entering the group ID and token""" -mf_resp = mfsdk.groups.get(group_id="1705dbd3-e542-4a38-8bef-aa7c33bdcf2d", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ") +mf_resp = mfsdk.groups.get(group_id="", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + """Group update""" group={ - "id": "75b2f10c-b903-4205-8af5-9d672be26d63", - "name": "group_15" + "id": "", + "name": "" } mf_resp = mfsdk.groups.update( - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIyNjk5MzEsImlhdCI6MTY5MjIxNTkzMSwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.vDHq7AOvppvknsKPdAxnGjsErUZ25_gAbZJ1zom3QqZ1sNAoPPU5AyVor-EgMeq1yvhggh8wzLx-9TSK6pQcCA", group= group + token="", group= group, group_id="group_id" ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' -''' + """You can get groups in the database by calling the get_all () function""" mf_resp = mfsdk.groups.get_all( - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ", query_params={"offset": 0, "limit": 5} + token="", query_params={"offset": 0, "limit": 5} ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) - """Assign user, thing or channel to a group""" mf_resp = mfsdk.groups.assign( - group_id="d6198103-4724-427e-b052-e6ad544c8864", - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMjEyNzgsImlhdCI6MTY5MjI2NzI3OCwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.o5l7GX9OXrTr_st-gc1FNPwf7Kx-7FYrO7JUfXOUIL9GR0lKqBuwOLHpQav_8RCWmO1EFsiRzo1hsWRE1BKoXA", - members_ids="9c398baf-5520-48ed-86de-572be9405d5b", - member_type=["g_update"], + group_id="", + token="", + members_ids="", + member_type=[""], ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -330,9 +466,9 @@ """Unassign""" mf_resp = mfsdk.groups.unassign( - group_id="d6198103-4724-427e-b052-e6ad544c8864", - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMjEyNzgsImlhdCI6MTY5MjI2NzI3OCwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.o5l7GX9OXrTr_st-gc1FNPwf7Kx-7FYrO7JUfXOUIL9GR0lKqBuwOLHpQav_8RCWmO1EFsiRzo1hsWRE1BKoXA", - members_ids="9c398baf-5520-48ed-86de-572be9405d5b", + group_id="", + token="", + members_ids="", ) if mf_resp.error.status == 0: print(mf_resp.value) @@ -341,7 +477,7 @@ """Get list of children from group""" mf_resp = mfsdk.groups.children( - group_id="75b2f10c-b903-4205-8af5-9d672be26d63", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIyNjk5MzEsImlhdCI6MTY5MjIxNTkzMSwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.vDHq7AOvppvknsKPdAxnGjsErUZ25_gAbZJ1zom3QqZ1sNAoPPU5AyVor-EgMeq1yvhggh8wzLx-9TSK6pQcCA", + group_id="", token="", query_params={"offset": 0, "limit": 5} ) if mf_resp.error.status == 0: @@ -351,7 +487,7 @@ """Get list of parents from group""" mf_resp = mfsdk.groups.parents( - group_id="b7cbb7c3-39af-4577-bae9-f83f3674b364", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIyNjk5MzEsImlhdCI6MTY5MjIxNTkzMSwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.vDHq7AOvppvknsKPdAxnGjsErUZ25_gAbZJ1zom3QqZ1sNAoPPU5AyVor-EgMeq1yvhggh8wzLx-9TSK6pQcCA", + group_id="", token="", query_params={"offset": 0, "limit": 5} ) if mf_resp.error.status == 0: @@ -361,7 +497,7 @@ """Get list of members from group""" mf_resp = mfsdk.groups.members( - group_id="d6198103-4724-427e-b052-e6ad544c8864", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMjEyNzgsImlhdCI6MTY5MjI2NzI3OCwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.o5l7GX9OXrTr_st-gc1FNPwf7Kx-7FYrO7JUfXOUIL9GR0lKqBuwOLHpQav_8RCWmO1EFsiRzo1hsWRE1BKoXA", + group_id="", token="", query_params={"offset": 0, "limit": 5} ) if mf_resp.error.status == 0: @@ -371,8 +507,8 @@ """Get list of memberships from member""" mf_resp = mfsdk.groups.memberships( - member_id="9c398baf-5520-48ed-86de-572be9405d5b", - token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMjEyNzgsImlhdCI6MTY5MjI2NzI3OCwiaWRlbnRpdHkiOiJleGFtcGxlMjRAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI5ZjczNGQ1Yi03NTgwLTQ5NzEtYmM0Mi1hYWYxMTlhZTg5MGEiLCJ0eXBlIjoiYWNjZXNzIn0.o5l7GX9OXrTr_st-gc1FNPwf7Kx-7FYrO7JUfXOUIL9GR0lKqBuwOLHpQav_8RCWmO1EFsiRzo1hsWRE1BKoXA", + member_id="", + token="", query_params={"offset": 0, "limit": 5}, ) if mf_resp.error.status == 0: @@ -381,7 +517,7 @@ print(mf_resp.error.message) """Delete group from the database""" -mf_resp = mfsdk.groups.disable(group_id="29474bea-a8d6-4e5c-9336-5de0c8ca9aaf", user_token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIxNDM0MTEsImlhdCI6MTY5MjA4OTQxMSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.BgXBpOdkOP6s2QMLdzv4jHsl3rX16ZkA_r34BS4wL8UA_xr5gWxeyqaNL8x9tkNNRz4RML40Lo2lGtd2sMvVZQ") +mf_resp = mfsdk.groups.disable(group_id="", user_token="") if mf_resp.error.status == 0: print(mf_resp.value) else: @@ -389,16 +525,105 @@ """Sends message via HTTP protocol""" mf_resp = mfsdk.messages.send( - channel_id="6a4c094d-b192-4e7b-837f-6d2a2bae12d5", msg="Hello", thing_key="a0c5471a-b7a6-4337-81af-b6113f41d898" + channel_id="", msg="<[message]>", thing_key="" ) if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) -''' + """Reads messages from database for a given channel""" -mf_resp = mfsdk.messages.read(channel_id="6a4c094d-b192-4e7b-837f-6d2a2bae12d5", token="eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTIzMzI1ODUsImlhdCI6MTY5MjI3ODU4NSwiaWRlbnRpdHkiOiJleGFtcGxlMjBAZXhhbXBsZS5jb20iLCJpc3MiOiJjbGllbnRzLmF1dGgiLCJzdWIiOiI4N2MxZTY5MC1kMDFhLTRhN2YtOGYyNy0xZjhhOWE2ZGIwMmUiLCJ0eXBlIjoiYWNjZXNzIn0.hAJllwSCLDOqJseCKkTtw4qI9EyuBat6qaLGsvdsU-OGVS6-VkkK6boiDQ-_Men9CT6oUpzzTmW3e0dRF72j3g") +mf_resp = mfsdk.messages.read(channel_id="", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Issue certs""" +mf_resp = mfsdk.certs.issue(thing_id="",valid="10h", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""View Certs""" +mf_resp = mfsdk.certs.view_by_thing(thing_id="", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""View Certs""" +mf_resp = mfsdk.certs.view_by_serial(cert_id="", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Revoke Certs""" +mf_resp = mfsdk.certs.revoke(thing_id="", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Adds new config to the list of config owned by user identified using the provided access token.""" +config = { + "external_id": "", + "external_key": "", + "thing_id": "", + "name": "" +} +mf_resp = mfsdk.bootstrap.add(config=config, token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) +"""Updating state represents enabling/disabling Config, i.e.connecting and disconnecting corresponding Mainflux Thing to the list of Channels.""" +config = { + "external_id": "", + "external_key": "", + "thing_id": "", + "name": "" +} +mf_resp = mfsdk.bootstrap.whitelist(config=config, token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Retrieves a configuration with given config id""" +mf_resp = mfsdk.bootstrap.view(thing_id= "", token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Update is performed by replacing the current resource data with values provided in a request payload. Note that the owner, ID, external ID, external key, Mainflux Thing ID and key cannot be changed.""" +config = { + "external_id": "", + "external_key": "", + "thing_id": "", + "name": "" +} +mf_resp = mfsdk.bootstrap.update(config=config, token="") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Retrieves a configuration with given external ID and external key.""" +mf_resp = mfsdk.bootstrap.bootstrap(external_id="", external_key= "") +if mf_resp.error.status == 0: + print(mf_resp.value) +else: + print(mf_resp.error.message) + +"""Removes a Config. In case of successful removal the service will ensure that the removed config is disconnected from all the Mainflux channels.""" + +mf_resp = mfsdk.bootstrap.remove(config_id= "", token="") if mf_resp.error.status == 0: print(mf_resp.value) else: print(mf_resp.error.message) + \ No newline at end of file diff --git a/mainflux/channels.py b/mainflux/channels.py index 69fdeec..0d4109a 100644 --- a/mainflux/channels.py +++ b/mainflux/channels.py @@ -3,13 +3,12 @@ from mainflux import response from mainflux import errors from mainflux import utils -from mainflux import things class Channels: - channels_endpoint = "channels" - things_endpoint = "things" - identify_endpoint = "identify" + CHANNELS_ENDPOINT = "channels" + THINGS_ENDPOINT = "things" + IDENTIFY_ENDPOINT = "identify" def __init__(self, url: str): self.url = url @@ -18,7 +17,7 @@ def create(self, channel: dict, token: str): """Creates channel entity in the database""" mf_resp = response.Response() http_resp = requests.post( - self.url + "/" + self.channels_endpoint, + self.url + "/" + self.CHANNELS_ENDPOINT, json=channel, headers=utils.construct_header(token, utils.CTJSON), ) @@ -35,7 +34,7 @@ def create_bulk(self, channels: list, token: str): """Creates multiple channels in a bulk""" mf_resp = response.Response() http_resp = requests.post( - self.url + "/" + self.channels_endpoint + "/bulk", + self.url + "/" + self.CHANNELS_ENDPOINT + "/bulk", json=channels, headers=utils.construct_header(token, utils.CTJSON), ) @@ -52,7 +51,7 @@ def get(self, channel_id: str, token: str): """Gets a channel entity for a logged-in user""" mf_resp = response.Response() http_resp = requests.get( - self.url + "/" + self.channels_endpoint + "/" + channel_id, + self.url + "/" + self.CHANNELS_ENDPOINT + "/" + channel_id, headers=utils.construct_header(token, utils.CTJSON), ) if http_resp.status_code != 200: @@ -68,7 +67,7 @@ def get_all(self, query_params: dict, token: str): """Gets all channels from database""" mf_resp = response.Response() http_resp = requests.get( - self.url + "/" + self.channels_endpoint, + self.url + "/" + self.CHANNELS_ENDPOINT, headers=utils.construct_header(token, utils.CTJSON), params=query_params, ) @@ -85,7 +84,7 @@ def get_by_thing(self, thing_id: str, query_params: dict, token: str): """Gets all channels to which a specific thing is connected to""" mf_resp = response.Response() http_resp = requests.get( - self.url + "/" + self.things_endpoint + "/" + thing_id + "/" + self.channels_endpoint, + self.url + "/" + self.THINGS_ENDPOINT + "/" + thing_id + "/" + self.CHANNELS_ENDPOINT, headers=utils.construct_header(token, utils.CTJSON), params=query_params, ) @@ -101,7 +100,7 @@ def get_by_thing(self, thing_id: str, query_params: dict, token: str): def update(self, channel_id: str, channel: dict, token: str): """Updates channel entity""" http_resp = requests.put( - self.url + "/" + self.channels_endpoint + "/" + channel_id, + self.url + "/" + self.CHANNELS_ENDPOINT + "/" + channel_id, json=channel, headers=utils.construct_header(token, utils.CTJSON), ) @@ -116,7 +115,7 @@ def update(self, channel_id: str, channel: dict, token: str): def disable(self, channel_id: str, token: str): """Deletes a channel entity from database""" http_resp = requests.post( - self.url + "/" + self.channels_endpoint + "/" + channel_id + "/disable", + self.url + "/" + self.CHANNELS_ENDPOINT + "/" + channel_id + "/disable", headers=utils.construct_header(token, utils.CTJSON), ) mf_resp = response.Response() @@ -130,7 +129,7 @@ def disable(self, channel_id: str, token: str): def identify_thing(self, thing_key: str): """Validates thing's key and returns it's ID if key is valid""" http_resp = requests.post( - self.url + "/" + self.identify_endpoint, + self.url + "/" + self.IDENTIFY_ENDPOINT, headers=utils.construct_header(utils.ThingPrefix + thing_key, utils.CTJSON), ) mf_resp = response.Response() diff --git a/mainflux/things.py b/mainflux/things.py index 2515a79..a6fb053 100644 --- a/mainflux/things.py +++ b/mainflux/things.py @@ -248,9 +248,9 @@ def disconnect(self, thing_id: str, channel_id: str, token: str): ) return mf_resp - def share_thing(self, user_id: str, group_id: str, actions: dict, token: str): + def share_thing(self, user_id: str, channel_id: str, actions: dict, token: str): """Share thing""" - payload = {"object": group_id, "subject": user_id, "Actions": actions, "External": True} + payload = {"object": channel_id, "subject": user_id, "Actions": actions, "External": True} http_resp = requests.post( self.URL + "/policies", headers=utils.construct_header(token, utils.CTJSON), diff --git a/tests/test_users.py b/tests/test_users.py index 7041cc4..1d94d10 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -1,6 +1,6 @@ from mainflux import sdk -import json, requests_mock +import requests_mock s = sdk.SDK() user = { @@ -66,8 +66,11 @@ "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", "access_type": "access" } +password= "12345678" +confirm_password="12345678" +email={"admin@example.com": "email"} url = "http://localhost" - +url2 = "http://localhost/password/reset-request" def test_create_user(requests_mock): requests_mock.register_uri("POST", url + "/users", headers={"location": "/users/" + user_id}, json=user, status_code=201) @@ -80,21 +83,30 @@ def test_create_user_bad_user(requests_mock): r = s.users.create(user=user) assert r.error.status == 1 assert r.error.message == "Failed due to using an existing identity." - - + def test_login_user(requests_mock): requests_mock.register_uri("POST", url + "/users/tokens/issue", json=token, status_code=201) r = s.users.login(user=user) assert r.error.status == 0 assert token == r.value - def test_login_user_bad_email(requests_mock): requests_mock.register_uri("POST", url + "/users/tokens/issue", status_code=409) r = s.users.login(user=user) assert r.error.status == 1 assert r.error.message == "Failed due to using an existing email address." + +def test_refresh_token(requests_mock): + requests_mock.register_uri("POST", url + "/users/tokens/refresh", json=token, status_code=201) + r = s.users.refresh_token(user=user, token=token["refresh_token"]) + assert r.error.status == 0 + assert token == r.value +def test_refresh_token_bad_token(requests_mock): + requests_mock.register_uri("POST", url + "/users/tokens/refresh",json=token, status_code=404) + r = s.users.refresh_token(user=user, token=token["refresh_token"]) + assert r.error.status == 1 + assert r.error.message == "A non-existent entity request." def test_get_user(requests_mock): requests_mock.register_uri("GET", url + "/users/" + user_id, json=user, status_code=200) @@ -102,53 +114,102 @@ def test_get_user(requests_mock): assert r.error.status == 0 assert user == r.value - def test_get_user_bad_token(requests_mock): requests_mock.register_uri("GET", url + "/users/" + user_id, json=user, status_code=401) r = s.users.get(user_id=user_id, token=token["access_token"]) assert r.error.status == 1 assert r.error.message == "Missing or invalid access token provided." - def test_get_all_users(requests_mock): requests_mock.register_uri("GET", url + "/users", json=[user, user2], status_code=200) r = s.users.get_all(query_params=None, user_token=token["access_token"]) assert r.error.status == 0 assert [user, user2] == r.value - def test_get_all_user_bad_request(requests_mock): requests_mock.register_uri("GET", url + "/users" , json=user, status_code=422) r = s.users.get_all(query_params=None, user_token=token["access_token"]) assert r.error.status == 1 assert r.error.message == "Database can't process request." - def test_update_user(requests_mock): requests_mock.register_uri("PATCH", url + "/users/" + user["id"], json=user, status_code=200) r = s.users.update(user=user, user_token=token["access_token"]) assert r.error.status == 0 - def test_non_existing_user_update(requests_mock): requests_mock.register_uri("PATCH",url + "/users/" + user["id"], json=user, status_code=404) r = s.users.update(user=user, user_token=token["access_token"]) assert r.error.status == 1 assert r.error.message == "Failed due to non existing user." +def test_update_user_identity(requests_mock): + requests_mock.register_uri("PATCH", url + "/users/" + user["id"] + "/identity", json=user, status_code=200) + r = s.users.update_user_identity(user=user, user_token=token["access_token"]) + assert r.error.status == 0 + +def test_non_existing_user_identity_update(requests_mock): + requests_mock.register_uri("PATCH",url + "/users/" + user["id"] + "/identity", json=user, status_code=401) + r = s.users.update_user_identity(user=user, user_token=token["access_token"]) + assert r.error.status == 1 + assert r.error.message == "Missing or invalid access token provided." + +def test_update_user_tags(requests_mock): + requests_mock.register_uri("PATCH", url + "/users/" + user["id"] + "/tags", json=user, status_code=200) + r = s.users.update_user_tags(user=user, user_token=token["access_token"]) + assert r.error.status == 0 + + +def test_non_existing_user_tags_update(requests_mock): + requests_mock.register_uri("PATCH",url + "/users/" + user["id"] + "/tags", json=user, status_code=401) + r = s.users.update_user_tags(user=user, user_token=token["access_token"]) + assert r.error.status == 1 + assert r.error.message == "Missing or invalid access token provided." + +def test_update_user_owner(requests_mock): + requests_mock.register_uri("PATCH", url + "/users/" + user["id"] + "/owner", json=user, status_code=200) + r = s.users.update_user_owner(user=user, user_token=token["access_token"]) + assert r.error.status == 0 + +def test_non_existing_user_owner_update(requests_mock): + requests_mock.register_uri("PATCH",url + "/users/" + user["id"] + "/owner", json=user, status_code=401) + r = s.users.update_user_owner(user=user, user_token=token["access_token"]) + assert r.error.status == 1 + assert r.error.message == "Missing or invalid access token provided." def test_update_user_password(requests_mock): requests_mock.register_uri("PATCH", url + "/users" + "/secret", status_code=200) r = s.users.update_password(old_secret=old_secret, new_secret=new_secret, user_token=token["access_token"]) assert r.error.status == 0 - def test_update_user_password_bad_token(requests_mock): requests_mock.register_uri("PATCH",url + "/users" + "/secret", status_code=415) r = s.users.update_password(old_secret=old_secret, new_secret=new_secret, user_token=token["access_token"]) assert r.error.status == 1 assert r.error.message == "Missing or invalid content type." +def test_reset_password_request(requests_mock): + requests_mock.register_uri("POST", url + "/password/reset-request", json=email, status_code=201) + r = s.users. reset_password_request(email=email, url=url2) + assert r.error.status == 0 + +def test_reset_password_request_bad_email(requests_mock): + requests_mock.register_uri("POST",url + "/password/reset-request", status_code=400) + r = s.users. reset_password_request(email=email, url=url2) + assert r.error.status == 1 + assert r.error.message == "Failed due to malformed JSON." + +def test_reset_password(requests_mock): + requests_mock.register_uri("PUT", url + "/password/reset", status_code=201) + r = s.users. reset_password(password=password, confirm_password=confirm_password, token=token) + assert r.error.status == 0 + +def test_reset_password_bad_token(requests_mock): + requests_mock.register_uri("PUT",url + "/password/reset", status_code=400) + r = s.users. reset_password(password=password, confirm_password=confirm_password, token=token) + assert r.error.status == 1 + assert r.error.message == "Failed due to malformed JSON." + def test_enable_user(requests_mock): requests_mock.register_uri("POST", url + "/users/" + user["id"] + "/enable", json=user, status_code=204) r = s.users.enable(user_id=user["id"], user_token= token["access_token"])