Skip to content

opnmind/osenv-tool

Repository files navigation

Build Status Code style: black

osenv-tool - OpenStack Environment loader

TODO

Idee: Einen Token generieren der vorübergehend Zugriff gewährt

  • find a alternative for using env vars
  • add edit function to change one password from a existing list (partly)
  • add to write function to add a new tenant to an existing list
  • better description to activate keyring
  • move the bashrc integration from the installation process to the tool directly (e.g. osenv-tool --integrate-bashrc [-b])
  • Test case file encryption

Requirements

  • Python 3
  • gnome-keyring package

Description

Steps to use:

  1. Setup virtual environment

For virtualenv you can install "python2-virtualenv" or "python3-virtualenv" system package.

# create a python 3 environment
$ virtualenv -p /usr/bin/python3 venv
$ source venv/bin/activate
  1. Install Requirements and osenv tool.
$ pip install git+https://github.com/opnmind/osenv-tool.git
  1. Create an encrypted configuration file with all your needed credentials. (RSA Encryption with 4096 bit Key)
$ osenv-tool -w [~/.ostackrc.enc]
  1. Put your configuration into gnome-keyring.
$ osenv-tool -r [~/.ostackrc.enc]
# better for automatic source given output
$ $(osenv-tool -r [~/.ostackrc.enc])
  1. List available environment's.
$ osenv-tool -l
PROD
PREPROD
  1. Load a given environment.
$ osenv-tool -e PROD
# better for automatic source given output
$ $(osenv-tool -e PROD)
  1. Unset ENV variables if environment isn't needed anymore.
$ osenv-tool -c
# better for automatic source given output
$ $(osenv-tool -c)
  1. Edit a existing encoded file.
$ osenv-tool -i [~/.ostackrc.enc]

Usage with bashrc

Now the setup process added the snippet durring the installation to the .bashrc.d directory as 10-osenv.bashrc file.

DEPRECATED: If you want the full support, then you have to add those code snippet to you ~/.bashrc. With this little trick you are able to source the user variables in your shell session.

# Clean up your environment.
$ osenv -c

# Load your desired .ostackrc environment.
$ osenv -e PROD
mkdir ~/.bashrc.d
chmod 0700 ~/.bashrc.d

for file in ~/.bashrc.d/*.bashrc;
do
    source$filedone

##--OSENV--BEGIN--##
# Catch output and source it to the active environment
osenv() {
    arg1=$1
    arg2=$2

    # source environment
    if [[ $arg1 == "-e" ]]; then
        echo "Load .ostackrc for ${arg2}"
        $(osenv-tool -e ${arg2})

    # clean up
    elif [[ $arg1 == "-c" ]]; then
        echo "Clean up .ostackrc variables."
        $(osenv-tool -c)
    
    # read 
    elif [[ $arg1 == "-r" ]]; then
        echo "Read encoded .ostackrc file."
        $(osenv-tool -r ${arg2})

    # forward the rest
    else
        osenv-tool $@
    fi
}
##--OSENV--END--##

Hint: Everytime you expose only the active enviroment to the Session Variables.

$ osenv-tool -h
usage: osenv-tool [-h]
              (--version | -e <environment-name> | -l | -c | -r [<encoded-file>] | -w [<encoded-file>] | -i [<encoded-file>])

Create and load .ostackrc credentials confidentialy.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -e <environment-name>, --environment <environment-name>
                        Load .ostackrc environment name.
  -l, --list            List available .ostackrc environments.
  -c, --clean           Clean up active .ostackrc environment.
  -r [<encoded-file>], --read [<encoded-file>]
                        Read encoded file and set content to session
                        variables. Default filename is ~/.ostackrc.enc.
  -w [<encoded-file>], --write [<encoded-file>]
                        Create and write encoded file with multiple ostackrc
                        environments. Default filename is ~/.ostackrc.enc.
  -i [<encoded-file>], --edit [<encoded-file>]
                        Edit a encoded file and write it back. Default
                        filename is ~/.ostackrc.enc.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published