#/usr/bin/env python

import six
import base64
import argparse
import requests

from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5

__version__ = '1.0.0'


def handle_args():
    desc = ('Foo')
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument('--version', action='version',
                        version=__version__)

    parser.add_argument('-r', '--repo', required=True,
                        help='Repository slug (:owner/:name)')
    parser.add_argument('string', help='String to encrypt')

    args = parser.parse_args()
    return args


def get_public_key(repo):
    keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
    try:
        r = requests.get(keyurl)
        r.raise_for_status()
    except Exception as e:
        raise SystemExit(e)
    else:
        try:
            key = r.json()
        except Exception as e:
            raise SystemExit(e)

    return key.get('key')


def encrypt(repo, string):
    public_key = get_public_key(repo)
    key = RSA.importKey(public_key)
    cipher = PKCS1_v1_5.new(key)
    return base64.b64encode(cipher.encrypt(string))


def main():
    args = handle_args()
    encrypted = encrypt(args.repo, args.string)
    six.print_('secure: "{0}"'.format(encrypted))


if __name__ == '__main__':
    main()

@@ -1,9 +1,10 @@
 #
+!
 /usr/bin
@@ -14,16 +14,684 @@
 v python
+%0A# -*- coding: utf-8 -*-%0A#%0A# Copyright 2014 Matt Martz %3Cmatt@sivle.net%3E%0A# All Rights Reserved.%0A#%0A#    Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A#    not use this file except in compliance with the License. You may obtain%0A#    a copy of the License at%0A#%0A#         http://www.apache.org/licenses/LICENSE-2.0%0A#%0A#    Unless required by applicable law or agreed to in writing, software%0A#    distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A#    License for the specific language governing permissions and limitations%0A#    under the License.
 %0A%0Aimport

Add license header to py file