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

Bootstrap command #18

Merged
merged 6 commits into from
Jul 25, 2019
Merged

Bootstrap command #18

merged 6 commits into from
Jul 25, 2019

Conversation

xen0l
Copy link
Owner

@xen0l xen0l commented Jul 22, 2019

This PR adds bootstrap command, which allows to download session-manager-plugin and install it, so it doesn't require sudo. Fixes #15.

@codecov
Copy link

codecov bot commented Jul 23, 2019

Codecov Report

Merging #18 into master will decrease coverage by 2.06%.
The diff coverage is 76.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
- Coverage   88.23%   86.17%   -2.07%     
==========================================
  Files           8        9       +1     
  Lines         374      470      +96     
==========================================
+ Hits          330      405      +75     
- Misses         44       65      +21
Impacted Files Coverage Δ
aws_gate/exceptions.py 100% <100%> (ø) ⬆️
aws_gate/cli.py 50.64% <28.57%> (-3.9%) ⬇️
aws_gate/bootstrap.py 84.33% <84.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dcbd80...6d86a39. Read the comment docs.

@xen0l xen0l marked this pull request as ready for review July 25, 2019 16:25
@xen0l xen0l merged commit ebbc747 into master Jul 25, 2019
@xen0l xen0l deleted the bootstrap branch July 25, 2019 18:21
@alanjds
Copy link
Contributor

alanjds commented Sep 5, 2019

My 2 cents: If you want to bootstrap the Linux plugin (as we made internally on GetNinjas), you can use https://github.com/getninjas/unix_ar

Our internal CLI is something alike this:

SSM_PLUGIN_PATH = {
    'darwin': {
        'download': 'https://s3.amazonaws.com/session-manager-downloads/plugin/latest/mac/sessionmanager-bundle.zip',
        'bundlepath': 'sessionmanager-bundle/bin/session-manager-plugin',
    },
    'linux': {  # yapf: nolint
        'download': 'https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb',
        'bundlepath': 'usr/local/sessionmanagerplugin/bin/session-manager-plugin',
    }
}

def _extract_from_deb(debfile: 'filelike', targetfile: str) -> 'filelike':
    """Extract `targetfile` from debfile"""
    import unix_ar
    import tarfile
    logger.debug('Extracting from debfile: %s', targetfile)
    ar_file = unix_ar.open(debfile)
    tarball = ar_file.open('data.tar.gz/')  # default interest location on .deb files
    tar_file = tarfile.open(fileobj=tarball)  # handles gz decompression internally
    return tar_file.extractfile(targetfile)

def _extract_from_zip(zipball: 'filelike', targetfile: str) -> 'filelike':
    """Extract `targetfile` from zipball"""
    logger.debug('Extracting from zipball: %s', targetfile)
    import zipfile
    return zipfile.ZipFile(zipball).open(targetfile)

(...)

# download = io.BytesIO()
final_binary = open('session-manager-plugin', 'wb')
if platform == 'darwin':
    filelike = _extract_from_zip(download, SSM_PLUGIN_PATH[platform]['bundlepath'])
elif platform == 'linux':
    filelike = _extract_from_deb(download, SSM_PLUGIN_PATH[platform]['bundlepath'])

final_binary.write(filelike.read())
final_binary.flush()
os.chmod(final_binary.name, stat.S_IREAD | stat.S_IEXEC)  # chmod u+rw

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

Successfully merging this pull request may close these issues.

Add bootstrap command
2 participants