Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to run command before request #78

Open
dkuku opened this issue Mar 30, 2019 · 3 comments
Open

Allow to run command before request #78

dkuku opened this issue Mar 30, 2019 · 3 comments

Comments

@dkuku
Copy link

dkuku commented Mar 30, 2019

this would be useful to get an auth token
I'm thinking about something:

export TOKEN=Cookie=`curl https://swapi.co/api/people/1/ |jq --arg --raw-output '.name'`
echo $TOKEN

a way to pipe the curl output would be also usefull - when the return value is long it's hard to check it in vim - piping to jq or tail could be interesting

@diepm
Copy link
Owner

diepm commented Apr 5, 2019

A recent PR has added an ability to read an env variable. Do you think it works (though how the env variable is set is outside VRC)?

@emaniacs
Copy link

emaniacs commented Dec 21, 2020

a way to pipe the curl output would be also usefull - when the return value is long it's hard to check it in vim - piping to jq or tail could be interesting

i create pr for pipe option, you can pull from it
#93

@felipejoribeiro
Copy link

Ended up with something like this:

    function RunWithPreCommand()
      local pre = vim.fn.findfile('pre.sh', '.;')
      if pre ~= '' then
        vim.fn.system('bash ' .. pre)
      end
      vim.cmd('call VrcQuery()')
    end

    MAPKEY('n', '<leader>r', ':lua RunWithPreCommand()<CR>', { noremap = true, silent = true })

It runs authentication code which resides in pre.sh:

#!/bin/bash

REFRESH_KEY=XXXXXXXX
URL=https://www.my/auth/provider/verifyPassword?key=$REFRESH_KEY
HEADER="Content-Type: application/json"
BODY='{"email": "[email protected]", "password": "123456", "returnSecureToken": true}'

IDTOKEN=$(curl --silent -X POST -H "$HEADER" -d "$BODY" $URL | jq -r '.token')

sed -i "s/X-AUTH:.*$/X-AUTH: Token $IDTOKEN/" api/headers

So, it looks for a bash script in the project's directory, and executes it exporting the output to a headers file. Then you can execute all your queries reading the headers from this file, like so:

# host
http://localhost:8000

# curl options
# --verbose  # show request headers
--silent   # don't show progress
# --include  # show response headers
--insecure # allow insegure SSL connections
-H @api/headers

# query
GET /v1/cancel-order/1/

Hope this helps. o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants