Command documentation in jquery-terminal with authentication token - jquery-terminal

I'm creating a jquery terminal with server side authentication by following the example JSON-RPC with authentication. It works well, but when I type "help" to get information on a particular command, the authentication token is included as the first parameter. I'm worried that this may confuse the users or make them think they have to type a token into the terminal.
For example, in the demo for the example, typing "help ls" returns:
> help ls
ls token path
list directory if token is valid
Is there any way I can configure jquery-terminal to filter out the token, so that typing "help ls" returns something like this?
> help ls
ls path
list directory if token is valid
I've been trying to work out if this can be done by writing a custom "help" command, but am not sure how to do this while still using the documentation in the JSON-RPC response.

Related

How can I pass arguments to shell script in other command with questions

I have a small doubts because I don't know how can I prepare shell script which should execute other command with questions...
It means e.g. that I have to connect with VPN client and need to answer a several question. Accept trusting (yes/no), then choose VPN option (VPN/VPN-1), introduce login and password. I would like to have one script with all parameters (of course exclude password).
Any ideas? Thanks
If the answers file works, you can avoid placing the password into the file using replacement token. For example, write 'PASSWORD in the file, and then use 'sed' (or other tool) to replace it at run time.
Possible to use 'read -s password' or other method to get the password at run-time.
read -s REAL_PASSWORD
sed -e 's/__PASSWORD__/$REAL_PASSWORD/' | command-to-setup
If the number of items in the answer file is small, and do not change, you can inline them into your script
read -s REAL_PASSWORD
command-to-setup <<__ANSWERS__
yes
VPN-1
login
$REAL_PASSWORD
__ANSWERS__

Unable to Authenticate Application Default Credentials

I am following the docs here and it says:
The simplest way for applications to authenticate to a Google Cloud Platform API service is by using Application Default Credentials (ADC). Services using ADC first search for credentials within a GOOGLE_APPLICATION_CREDENTIALS environment variable; Google Cloud recommends you set this environment variable to point to your service account key file (the .json file downloaded when you created a service account key, as explained in Set Up a Service Account.
And it says to use this command:
$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
In the Google Shell, I have attempted this:
<INSERT_SOMETHING>"~$ $ export GOOGLE_APPLICATION_CREDENTIALS=</Users/grantespanet/Downloads/myfile.json>
But I get this error: -bash: syntax error near unexpected token newline
I have also tried this:
<INSERT_SOMETHING>:~$ $ export GOOGLE_APPLICATION_CREDENTIALS=/Users/grantespanet/Downloads/myfile.json
but nothing happens
I know the command is pointing to the correct file location. How can I successfully Authenticate Application Default Credentials?
The command you are executing is a variable assignment. Variable GOOGLE_APPLICATION_CREDENTIALS is given the value that follows the = sign.
The export keyword has the effect of making this variable available to child processes of the shell you are executing it from. In plain terms, it means any program you launch from the shell will have a copy of that variable (with its value) and can use it.
It is entirely normal for that command to produce no visible result or output.
The instructions you have probably require you to launch other commands after this one, which will use this value. Try performing the next steps.

Script "heroku login" in a CI environment

Is there a sanctioned way to either script or bypass the Heroku Toolbelt's login prompt? I've come across a number of hacks which claim to provide a solution (expect, environment variables, interpolating environment variables in .netrc, etc.), but I'd really like to find a stable solution.
From what I see in the docs, there's three ways one can go about this.
Method 1: Login via CLI
The first one is to authenticate via Login&Password (bleh). Knowing the input format - login on one line, password on the other - we can cat or echo the data in:
Via secure env vars:
(
echo "$HEROKU_CREDENTIALS_EMAIL" # or you can plaintext it, if you're feeling adventurous
echo "$HEROKU_CREDENTIALS_PASSWORD"
) | heroku login
Highlighted the important parts (variable names and security).
Or via an encrypted file:
Prepare a file named .heroku_cred in the repo root:
pdoherty926#gmail.com
IAmPdohertyAndThisIsMyPasswordIWorkHereWithMyOldMan
Then encrypt it:
travis encrypt-file .heroku_cred
That'll give you two things: a file named .heroku_cred.enc in the repo root and a command that'll decrypt the file on Travis. git add the encrypted file (be careful to not grab the unencrypted file by accident!) and add the command to before_install. Then, to the place where you want to authenticate with Heroku add:
cat .heroku_cred | heroku login
Now, this method sucks for two reasons: first, you're using your literal password, which is terrible, because if it leaks you're 100% fucked and if you ever change it your builds will start spuriously failing.
Method 2: Environment Variable
The next method is using the HEROKU_API_KEY env var, which might "interfere with the normal functioning of auth commands", but that doesn't matter, because you're not authenticating in other ways anyway.
Doing this requires no changes to .travis.yml, only a secure environment variable named HEROKU_API_KEY containing the output from
heroku auth:token
Ran on your machine (where you're probably authenticated).
Highlighted the important parts (variable names and security).
This method combines both security (OAuth token used, which can just be revoked) and simplicity of setup.
Method 3: Write directly to token storage file
There's the third way, too: using ~/.netrc, which'll cooperate with the whole ecosystem as if you authenticated via the CLI with username and password (but you're using an OAuth token instead, which is better).
The steps to follow on this one are similar to 1.2:
First create a file named .heroku-netrc, which contains the part of your ~/.netrc responsible for authenticating with Heroku (details) like this:
machine api.heroku.com
login me#example.com
password c4cd94da15ea0544802c2cfd5ec4ead324327430
machine git.heroku.com
login me#example.com
password c4cd94da15ea0544802c2cfd5ec4ead324327430
Then, to encrypt it, run:
travis encrypt .heroku-netrc
You'll get a decryption command (add it to before_install) and .heroku-netrc.enc, which you should git add (be careful not to add the unencrypted .heroku-netrc). Afterwards, add this to the install step:
cat .heroku-netrc >> $HOME/.netrc

Map keys in lynx to run shell-command

Is it possible to add a custom keymap to lynx (in the config file ~/.lynxrc), which sends information (e.g. the current URL, html, title, etc.) to a shell command?
An example use case:
I am on OSX and the shell has a command open, which attempts to open anything given to it in a default fashion. So, if I am in lynx and want to move the current webpage to the default browser I would want to call open current-url from the shell.
Another:
Collating an organized bookmark file by sending URL and title to a shell script (or something else).
Using the default keymap ! opens up the default shell, but it doesn't give me the URL nor does it run a single command and exit back to lynx as I would want for this.
Any ideas would be greatly appreciated.
I actually ended up finding a couple ways to handle this. Some are more ideal than others. It took some digging through the default lynx.cfg file to figure some of this out.
The following are the two most successful ways I accomplished sending info to a shell command from lynx:
place a variation of this in your lynx.cfg file. It can only send the URL, so it is limited by not being able to handle the title or any other information from the webpage without parsing a lynx dump itself. (This must be configured with --enable-extern, which is not available with MacPorts version of lynx, so you gotta install from source).
# in lynx.cfg
# EXTERNAL:<url>:<command> %s:<norestriction>:<allow_for_activate>[:environment]
# Ex 1: send the url to `open <url>` to open default browser
EXTERNAL:http:open %s:TRUE
# Ex 2: download with wget if ftp page
EXTERNAL:ftp:wget %s &:TRUE
# By default ',' and '.' map to running EXTERNAL on the page and link respectively
# KEYMAP:,:EXTERN_PAGE # Run external program with current page
# KEYMAP:.:EXTERN_LINK # Run external program with current link
Create a script and run it with printer to collect print environment variables.
# in lynx.cfg
# PRINTER:<name>:<command>:<option>:<lines/page>[:<environment>]
PRINTER:openurl:/Users/username/bin/openurl %s:TRUE
Then the script openurl, which opens the url in a default browser (OSX) contains:
#!/bin/sh
# /Users/username/bin/openurl
url=$LYNX_PRINT_URL
title=$LYNX_PRINT_TITLE
# other variables exist like the date etc... look them up :)
# http://osr600doc.sco.com/en/INT_lynxDoc/keystrokes/environments.html
# perform magic ...
/usr/bin/open $url
There may be other ways like using the lynxified proxies lynxexec, lynxprog, and lynxcgi, but I was unable to successfully pass variables with these methods in my own tests. If you know a way to get title and url information from these methods I would be interested in hearing it. The example #1 above could essentially grab the title and other information by invoking lynx or some other browser, so it is essentially possible to get everything done with that method. Also, it allows a single key mapped to perform the function, which the print screen adds several keystrokes to the mix, which is undesirable. I recommend #1 above.

OS X Command-line URL filter

I have a bash script that uses bash's "read" builtin to obtain a username and password from the user and then uses them as part of an AFP URL. I'm encountering some problems, however, when passwords contain characters that affect URL parsing (';' for example).
I've looked around for a command-line utility that can do URL-filtering but haven't found one. Does anybody know of such a utility? I would like to be able to do something like the following:
mount_afp "afp://`urlfilter $USER`:`urlfilter $PASS`#server.com".
You can use a simple one-line Python script to do this:
echo $USER | python -c 'import urllib; print urllib.quote(raw_input())'
Note that, while acceptable for your usage, urllib.quote is designed for use on URL components, not the entire URL. See #120951 for more.

Resources