codenotary / immugw

Apache License 2.0
23 stars 4 forks source link

Need help with IMMUGW ... #12

Closed vmdave9 closed 2 years ago

vmdave9 commented 3 years ago

Hello, all. I am a newbie to using the REST api that IMMUGW provides. My first attempt is this:

dave@vmubuntu:~$ curl --location --request POST '192.168.xxx.xx:3323/login' --header 'Authorization;' --header 'Content-Type: application/json' --data-raw '{ "user": "aW1tdWRi", "password": "aW1tdWRi"
}' which returns:

{"token":"v2.public.eyJkYXRhYmFzZSI6IjAiLCJleHAiOiIyMDIxLTA4LTE4VDEyOjI5OjE5LTA1OjAwIiwic3ViIjoiaW1tdWRiIn26sqUKmwUguz29TgkXmMYrn_xVFWDv0okochwvGU7vVcuAQ6AQZt4iFGEtxYetMRbq-VM0j2_WdCeYlbsYf-UF.aW1tdWRi","warning":"aW1tdWRiIHVzZXIgaGFzIHRoZSBkZWZhdWx0IHBhc3N3b3JkOiBwbGVhc2UgY2hhbmdlIGl0IHRvIGVuc3VyZSBwcm9wZXIgc2VjdXJpdHk="}

I take it that the token I need to use in other calls to the api starts with "v2.public. ---" and ends with "bsYf-" but what is the "warning" for and what does it mean? And does the token include the " marks or not?

It would be very helpful for me if someone could provide a complete, working example of using the api to log onto immudb, set a default database, issue a set command, and log off, including all of the needed curl commands with proper punctuation. Something I can use as a template, if it were.

Also,when using the api what values need to be specified in base64 and what do not? Many thanks; appreciate the help here. DJ

mmeloni commented 3 years ago

Hi @vmdave9, immugw is built on top of grpc-gateway, so everything that originally is []byte type is automatically b64 encoded. Have you already take a look at the README? At the end you will find curl examples with payloads. You need to use the token as it cames from login or use database methods. Let me know if that works

vmdave9 commented 3 years ago

Hi, Mmeloni. I very much appreciate your time and effect here to help me get this to work. I have read the README file, and I have been able to start both the immudb server and immugw, running on the same Linux platform, like so: For immudb: dave@dave-ThinkPad-T480:~/immudb-demo$ ./immudb -a 192.168.128.12


() | | |
| | |
| | ' ` | ' ` | | | |/ ` | ' \ | | | | | | | | | | | | || | (| | |) | ||| || ||| || ||_,|_,|_.__/

immudb 1.0.5 Commit : 73043acda487aabead663a2930e58bb5e4070285 Built by: bart@codenotary.com Built at: Mon, 02 Aug 2021 08:48:12 CDT Static : true ================ Config ================ Data dir : ./data Address : 192.168.128.12:3322 Metrics address : 192.168.128.12:9497/metrics Config file : configs/immudb.toml Max recv msg size: 33554432 Auth enabled : true Dev mode : false Default database : defaultdb Maintenance mode : false Synced mode : true

Superadmin default credentials Username : immudb Password : immudb

immudb 2021/08/17 09:49:57 INFO: Reading snapshot at 'data/systemdb/index/commit'... immudb 2021/08/17 09:49:57 INFO: Successfully read snapshot at 'data/systemdb/index/commit' immudb 2021/08/17 09:49:57 INFO: Indexing in progress at 'data/systemdb' immudb 2021/08/17 09:49:57 INFO: Binary Linking up to date at 'data/systemdb' immudb 2021/08/17 09:49:57 INFO: Database 'systemdb' successfully opened (replica = false) immudb 2021/08/17 09:49:57 INFO: Loading SQL Engine for database 'systemdb' (replica = false)... immudb 2021/08/17 09:49:57 INFO: Flushing index 'data/systemdb/index'... immudb 2021/08/17 09:49:57 INFO: Flushing not needed at 'data/systemdb/index' immudb 2021/08/17 09:49:57 INFO: SQL Engine ready for database 'systemdb' (replica = false) immudb 2021/08/17 09:49:57 INFO: Reading snapshot at 'data/defaultdb/index/commit'... immudb 2021/08/17 09:49:57 INFO: Successfully read snapshot at 'data/defaultdb/index/commit' immudb 2021/08/17 09:49:57 INFO: Indexing in progress at 'data/defaultdb' immudb 2021/08/17 09:49:57 INFO: Binary Linking up to date at 'data/defaultdb' immudb 2021/08/17 09:49:57 INFO: Database 'defaultdb' successfully opened (replica = false) immudb 2021/08/17 09:49:57 INFO: Started with an empty database immudb 2021/08/17 09:49:57 INFO: Loading SQL Engine for database 'defaultdb' (replica = false)... immudb 2021/08/17 09:49:57 INFO: Flushing index 'data/defaultdb/index'... immudb 2021/08/17 09:49:57 INFO: Flushing not needed at 'data/defaultdb/index' immudb 2021/08/17 09:49:57 INFO: SQL Engine ready for database 'defaultdb' (replica = false) immudb 2021/08/17 09:49:57 INFO: pgsl server is running at port 5432 immudb 2021/08/17 09:49:57 INFO: Webconsole enabled: 192.168.128.12:8080 immudb 2021/08/17 09:49:57 INFO: Web API server enabled on 192.168.128.12:8080/api (http) You can now use immuadmin and immuclient CLIs to login with the immudb superadmin user and start using immudb. immudb 2021/08/17 12:30:46 INFO: Flushing index 'data/systemdb/index'... immudb 2021/08/17 12:30:46 INFO: Flushing not needed at 'data/systemdb/index' immudb 2021/08/17 12:30:47 INFO: Flushing index 'data/systemdb/index'... immudb 2021/08/17 12:30:47 INFO: Flushing not needed at 'data/systemdb/index' immudb 2021/08/17 12:30:47 INFO: Flushing index 'data/systemdb/index'... immudb 2021/08/17 12:30:47 INFO: Flushing not needed at 'data/systemdb/index' immudb 2021/08/18 07:53:14 INFO: 1 transaction/s to be indexed at 'data/defaultdb' immudb 2021/08/18 09:38:23 INFO: 1 transaction/s to be indexed at 'data/defaultdb'

and for immugw: ^Cdave@dave-ThinkPad-T480:~/immudb-demo/immugw$ ./immugw -a 192.168.128.12 -k 192.168.128.12 --logfile /home/dave/immudb-demo/immugw2.log

The 192.168.128.12 address is the IP address of the host Linux system.

So now I log on: dave@vmubuntu:~$ curl --location --request POST '192.168.128.12:3323/login' --header 'Authorization;' --header 'Content-Type: application/json' --data-raw '{ "user": "aW1tdWRi", "password": "aW1tdWRi" }' and I get back: {"token":"v2.public.eyJkYXRhYmFzZSI6IjAiLCJleHAiOiIyMDIxLTA4LTIxVDEwOjI5OjA5LTA1OjAwIiwic3ViIjoiaW1tdWRiIn3V5XCcswjwSdPqvSOP0V2vTmJAW1LWjei1FOpTiUaMZMNKsxvoHN-sQCM8y5H69mtO10Q7lnMqHzAs4hJu4AEJ.aW1tdWRi","warning":"aW1tdWRiIHVzZXIgaGFzIHRoZSBkZWZhdWx0IHBhc3N3b3JkOiBwbGVhc2UgY2hhbmdlIGl0IHRvIGVuc3VyZSBwcm9wZXIgc2VjdXJpdHk="} and because of your comment above, I can see that the 'warning' is this: immudb user has the default password: please change it to ensure proper security

However, I then want to log out of immudb, so I do this: dave@vmubuntu:~$ curl --location --request POST '192.168.128.12:3323/logout' --header 'Authorization: {{"v2.public.eyJkYXRhYmFzZSI6IjAiLCJleHAiOiIyMDIxLTA4LTIxVDEwOjI5OjA5LTA1OjAwIiwic3ViIjoiaW1tdWRiIn3V5XCcswjwSdPqvSOP0V2vTmJAW1LWjei1FOpTiUaMZMNKsxvoHN-sQCM8y5H69mtO10Q7lnMqHzAs4hJu4AEJ.aW1tdWRi"}}' --header 'Content-Type: application/json' but I get back this error: {"code": 13, "message": "failed to marshal error message"}

Sorry for the long post here, but as you can clearly tell, I really don't know what I'm doing ....:-) Many thanks. DJ

mmeloni commented 2 years ago

Thanks @vmdave9 I'm fixing the error handling on logout. The problem was that you are using a bad formatted token on logout and immudb is not recognizing your client as a logged one. The correct curl call in order to logout is something like:

curl --location --request POST '127.0.0.1:3323/logout' --header 'Authorization: v2.public.eyJkYXRhYmFzZSI6Ii0xIiwiZXhwIjoiMjAyMS0wOC0yNlQxMDowMjo0OCswMjowMCIsInN1YiI6ImltbXVkYiJ9c9VBi_RwJ_XEfbZvn0RA03XajrOzsHS97EzqTZDTut7TsDNx8bf3b06FfWPUE0G_ooe9oLUGUvmiua5qG4hRCA.aW1tdWRi' --header 'Content-Type: application/json'
mmeloni commented 2 years ago

Ok, just released immugw 1.0.5 with compatibility with immudb 1.0.5. This will fix the unmarshalling error