shellhub icon indicating copy to clipboard operation
shellhub copied to clipboard

Command line tool to shellshub

Open leoheck opened this issue 4 years ago • 41 comments
trafficstars

Hello, how do I connect shellhub form ssh? Do you have any tutorial?

leoheck avatar Oct 04 '21 21:10 leoheck

@leoheck thanks for contacting us. Take a look at https://docs.shellhub.io/user-manual/devices/connecting/

otavio avatar Oct 04 '21 21:10 otavio

Thanks, I don't need to use shellhub. These browser only applications slow down the whole process. I don't need it at all. But these guys from my team is using it. So, then I was thinking that it would be perfect if you guys coud have a command line tool that connects to the shellhub and allows easy access to the machines there. This would be a real improvement for shelhub.

leoheck avatar Oct 05 '21 00:10 leoheck

As mentioned, it is possible to connect from command line as explained on the link I pointed above.

otavio avatar Oct 05 '21 00:10 otavio

Maybe I am failing to explain this. I know how use the ssh. I know how to use the shellhub to connect into a device. Now, what I am saying is to have a tool (command line tool), lets call it shellhub

then we cloud do like this

connect to the platform with my credentials $ shellhub leandro password: ********

This is going to ask my password and will give me a terminal with some commands like

list_devices connect_device DEVICE_NAME

Then a advanced user could use this form the command line, and also from a computer that does not provide any gui.

leoheck avatar Oct 05 '21 00:10 leoheck

A command-line UI is indeed a very good idea. We need people to help to do it thought. Are you willing to help here?

otavio avatar Oct 05 '21 02:10 otavio

Yeah, definitely. Do you have any info to share to get access so I can try something? I was trying briefly to get access to the website from the command line with curl yesterday but the very quick test I made I was seeing a response saying I needed javascript support.

-- Leandro Heck

On Mon, Oct 4, 2021 at 11:07 PM Otavio Salvador @.***> wrote:

A command-line UI is indeed a very good idea. We need people to help to do it thought. Are you willing to help here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shellhub-io/shellhub/issues/1324#issuecomment-933998601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJX7YAZTD7ETMFKMNYKISTUFJMVHANCNFSM5FKIM7QA .

leoheck avatar Oct 05 '21 14:10 leoheck

We're publishing the OpenAPI docs in next release. Those are a good reference.

otavio avatar Oct 05 '21 15:10 otavio

https://docs.shellhub.io/api

gustavosbarreto avatar Dec 01 '21 16:12 gustavosbarreto

Beautiful, thanks.

leoheck avatar Dec 01 '21 16:12 leoheck

@gustavosbarreto do you have any example of how I can get a list of my devices with curl?

leoheck avatar Dec 01 '21 17:12 leoheck

more precisely, a list of the ssid fields

leoheck avatar Dec 01 '21 17:12 leoheck

Alright, this is working fine for me.

# Get the Bearer token using cURL and jq
TOKEN=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data "${login_data}" "${URL}/api/login" | jq -r '.token')

Now, how do I get the devices list? I am not getting the devices with this command https://docs.shellhub.io/api/#tag/device/paths/~1api~1devices/get

leoheck avatar Dec 01 '21 17:12 leoheck

It looks like it is getting a single computer.

leoheck avatar Dec 01 '21 17:12 leoheck

Ah, it has query parameters. It would be good to have some examples of the payload in the right panel, maybe.

leoheck avatar Dec 01 '21 17:12 leoheck

Even after using this, I am just getting the first one. image

This is what I am trying right now. image

leoheck avatar Dec 01 '21 17:12 leoheck

ah, it looks like what I want to access is this. https://docs.shellhub.io/api/#tag/session/paths/~1api~1sessions/get

leoheck avatar Dec 01 '21 23:12 leoheck

Or maybe not. There is something weird going on.

leoheck avatar Dec 01 '21 23:12 leoheck

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

leoheck avatar Dec 01 '21 23:12 leoheck

Alright, it looks that I am just seeing one of the namespaces. How do I change the namespace?

leoheck avatar Dec 02 '21 00:12 leoheck

This is getting namespaces

Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

leoheck avatar Dec 02 '21 00:12 leoheck

This is getting namespaces

Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

@henrybarreto can you please take a look into this?

gustavosbarreto avatar Dec 02 '21 01:12 gustavosbarreto

This is getting namespaces Devices count is 17 while devices is 0, this is strange. Sessions is 0 too. Are you sure these numbers are right? I meant, are they returning the right info? image

@henrybarreto can you please take a look into this?

Yes, I can.

I'll check what is happening.

henrybarreto avatar Dec 02 '21 01:12 henrybarreto

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Even after using this, I am just getting the first one. image

This is what I am trying right now. image

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Hi, Leo.

If I'm not misleading, --data in cURL is to send a data inside the request's body, but to list devices, you need to send it as query parameters, so your request will become this:

curl -s -X GET  -H 'Authorization: Bearer token' -H 'Accept: application/json' 'localhost/api/devices?per_page=20&page=1'

henrybarreto avatar Dec 02 '21 02:12 henrybarreto

Hi. The -d or --data (to send a json) are the same as you are showing. I got more data with the session list instead of the devices list

My current issue is how do I change the namespace. Those commands access my development namespace and couldn't find any way to change the namespace yet.

On Wed, Dec 1, 2021, 23:17 Henry Barreto @.***> wrote:

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Even after using this, I am just getting the first one. [image: image] https://user-images.githubusercontent.com/1277920/144286672-dfd73c77-2ac5-464b-afc6-3609b500b674.png

This is what I am trying right now. [image: image] https://user-images.githubusercontent.com/1277920/144286748-0f39ca0f-821f-4df3-8c27-5c1414dedd6c.png

How do I show all my devices? I can just list one. I have at least 20. Do you have any idea?

Hi, Leo.

If I'm not misleading, --data in cURL is to send a data inside the request's body, but to list devices, you need to send it as query parameters, so your request will become this:

curl -s -X GET -H 'Authorization: Bearer token' -H 'Accept: application/json' 'localhost/api/devices?per_page=20&page=1'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shellhub-io/shellhub/issues/1324#issuecomment-984230068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJX7YCNWI42BVTEJNUITEDUO3JKFANCNFSM5FKIM7QA .

leoheck avatar Dec 02 '21 02:12 leoheck

Sorry, so. :D

To "change" namespace, you need to do a GET request to http://localhost/api/auth/token/<namespace's tenant>. It will return to you a new token that "points" to this new namespace.

henrybarreto avatar Dec 02 '21 02:12 henrybarreto

This was my last try some minutes ago. Let me check... AH, it looks like the /auth/ path was missing...

Please, check your API docs, it looks like it misses this info t/api/auth/token/<namespace's tenant> I tried to locate it now quickly and I was not able to.

leoheck avatar Dec 02 '21 02:12 leoheck

This is what I was trying. Note the different (wrong) URL I was using.

image

leoheck avatar Dec 02 '21 02:12 leoheck

perfect, got the token. now, how do I use it? it is just a matter of replacing the normal token I was using?

leoheck avatar Dec 02 '21 02:12 leoheck

This was my last try some minutes ago. Let me check... AH, it looks like the /auth/ path was missing...

Please, check your API docs, it looks like it misses this info t/api/auth/token/<namespace's tenant> I tried to locate it now quickly and I was not able to.

Okay. It is true; I've forgotten this route.

As soon as possible, I'll add this.

Thank you :D

henrybarreto avatar Dec 02 '21 02:12 henrybarreto

perfect, got the token. now, how do I use it? it is just a matter of replacing the normal token I was using?

Exactly.

henrybarreto avatar Dec 02 '21 02:12 henrybarreto