trek10inc / awsume

A utility for easily assuming AWS IAM roles from the command line.
https://awsu.me
MIT License
494 stars 90 forks source link

Installation can corrupt .bashrc #23

Closed hartror closed 6 years ago

hartror commented 6 years ago

When I pip installed awsume as expected it modified my .bashrc, however it corrupted the file as there was no newline at eof. In my case the fault is likely the previous tool that modified it but it is a common enough edge case that it should be addressed.

ps. Loving the tool, will be getting the whole team on it once this issue is fixed!

mbarneyjr commented 6 years ago

Awsume should have placed newlines, \n, at the beginning and end of both the alias definition and the auto-complete function declaration. I'm unable to replicate the issue you're experiencing, so can you give me some more details about your environment, such as the OS, which version of python, what terminal you're using, and anything else you think might help?

Thanks for the bug report!

hartror commented 6 years ago

This reproduces the issue:

Dockerfile:

FROM ubuntu

RUN apt-get update \
    && apt-get install -y build-essential curl python-dev
RUN curl https://bootstrap.pypa.io/get-pip.py | python
RUN echo -n "# Comment without newline" > ~/.bashrc
RUN pip install awsume

CMD cat ~/.bashrc

Running:

$ docker build -t awsume_bashrc_test .
Sending build context to Docker daemon  2.048kB
<snip>
$ docker run -it awsume_bashrc_test
# Comment without newline#AWSume alias to source the AWSume script
alias awsume=". awsume"

#Auto-Complete function for AWSume
_awsume() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(awsumepy --rolesusers)
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0
}
complete -F _awsume awsume
mbarneyjr commented 6 years ago

Thanks for the dockerfile!

I just released version 2.1.5, which fixes this issue, thanks again for the bug report!