aybabtme / godotto

Among other things, a DigitalOcean REPL
Apache License 2.0
9 stars 4 forks source link

not being able to auth with do — open -api.token: no such file or directory #12

Closed xmudrii closed 7 years ago

xmudrii commented 7 years ago

hey y'all

i found this project randomly, is this thing still working? i saw some commits from past few hours.

i dl-ed this, but when i try to auth using my token:

dorepl -api.token $DOTOKEN

it returns me following err:

dorepl: open -api.token: no such file or directory

i tried many combinations, including: writing it directly (without env var), writing it with ", ' or even without it, and many others... token is working very well with other api services (e.g. doctl), even generated new one just in case.

tyvm

ps. working on bash for windows (ubuntu 16.04): tried with both bash and zsh, no avail

/cc @aybabtme @iheanyi

aybabtme commented 7 years ago

hey @xmudrii

this project is still working. when I do this:

$ dorepl -api.token "lolll"
dorepl: can't query DigitalOcean account, is your token valid?

it works for me...! I don't have a Windows machine, but if you feel like investigating, I'll be happy to look at a patch!

xmudrii commented 7 years ago

hi @aybabtme

it's almost same output for me when I enter random token like that:

dorepl: can't query DigitalOcean account, is your token valid?
invalid character 'U' looking for beginning of value

(same command), i just have one more error. but when i supply valid token, i get error like i reported

i'll try some debugging and if i find something, i'll report back

aybabtme commented 7 years ago

invalid character 'U' looking for beginning of value is a bug with the API right now, peeps are working on it :P

Seems tho that the API toke is being passed.

xmudrii commented 7 years ago

I changed env var to DO_TOKEN and got logged in. I'm trying to trace issue, i'll report here with my findings

xmudrii commented 7 years ago

@aybabtme I found something. Don't you mind please explaining me a thing? Here's what I found:

In cmd/dorepl/main.go at the line 95, it says: if len(os.Args[1:]) == 0. Shouldn't it be if len(os.Args[1:]) != 0 instead? When I change it, it works. logged in successfully. But I guess it will not work if you have token set as the default environmental variable (such as DO_TOKEN).

Do you have any idea how we can fix this one?

aybabtme commented 7 years ago

Hah good find! The problem is that os.Args returns exactly the args as they are given to the process, including the -api.token flag. To get the args without the parsed flags, the code should be using flag.Args() instead :)

xmudrii commented 7 years ago

@aybabtme changing if to if len(flag.Args()) == 0 { seems to work for all variants (flag provided, default env variable, repl file such as one from the example). If you want I can create PR. I can also let you do it, if you want. :D

aybabtme commented 7 years ago

I'm good, happy to let you do it if you feel like it.