Ejemplo n.º 1
0
def dummy_droplet():
    return Droplet(
        name="d_name",
        _log="a log here",
        token="token-here",
        id=1,
        ssh_keys=[SSHKey(id=1, name="ssh1"), SSHKey(id=1, name="ssh2")],
    )
Ejemplo n.º 2
0
def do_ssh():
    return [
        SSHKey(
            name="fake_key_1",
            fingerprint="44:90:8c:62:6e:53:3b:d8:1a:67:34:2f:94:02:e4:87",
        ),
        SSHKey(
            name="fake_key_2",
            fingerprint="66:a1:2a:23:4d:5c:8b:58:e7:ef:2f:e5:49:3b:3d:32",
        ),
        SSHKey(
            name="fake_key_3",
            fingerprint="aa:bb:cc:dd:ee:ff:aa:bb:cc:dd:ee:ff:aa:bb:cc:dd",
        ),
    ]
Ejemplo n.º 3
0
    def set_ssh_key(self, check_ssh):

        # Where our RSA key chould exist
        self.key_file = (os.path.expanduser('~') + '/.ssh/id_rsa.pub')
        key_file = (os.path.expanduser('~') + '/.ssh/id_rsa.pub')

        # If the RSA key doesn't exist, create it
        if check_ssh == True:
            if os.path.isfile(key_file) != True:
                os.system("ssh-keygen -b 2048 -t rsa -f " + key_file +
                          " -q -N ")
            # Set the member value ssh_key to the value of this file
            ssh_file = open(key_file)
            self.ssh_key = ssh_file.read().strip()
            ssh_file.close()

        if check_ssh == True:
            # Upload the SSH key to digital ocean if it isn't there already
            key_installed = False
            manager = digitalocean.Manager(token=self.token)
            keys = manager.get_all_sshkeys()
            for key in keys:
                if key.public_key == self.ssh_key:
                    key_installed = True
            if key_installed == False:
                key = SSHKey(token=digitalocean_token,
                             name='ocean_key_' +
                             str(random.randint(11111, 99999)),
                             public_key=self.ssh_key)
                key.create()
Ejemplo n.º 4
0
Archivo: vm.py Proyecto: ctfctl/ctfctl
def add_pub_key(path, name):
    with open(path) as f:
        user_ssh_key = f.read()

    key = SSHKey(token=TOKEN, name=name, public_key=user_ssh_key)
    key.create()
    print(f'[+] added ssh-key: {name}')
Ejemplo n.º 5
0
def upload_ssh_key(file_pub_name, hostname):
    user_ssh_key = open(file_pub_name).read()
    key = SSHKey(token=Configuration['DO_TOKEN'],
                 name=hostname,
                 public_key=user_ssh_key)
    key.create()
    print 'Uploaded Keypair'
    return key.id
Ejemplo n.º 6
0
def dropletSSHKey():
    user_ssh_key = open(f'/home/{USER}/.ssh/id_rsa.pub').read()
    key = SSHKey(token=API_SECRET,
                 name='archyDesktop',
                 public_key=user_ssh_key)
    key.create()
    print("Key Created")
    input("Press [Enter] to return to the main screen")
    main()
Ejemplo n.º 7
0
def test_post_public_key(m_ask_for_public_key_name, m_create_ssh_key):
    name = "public_key_name"
    m_ask_for_public_key_name.return_value = name
    m_create_ssh_key.return_value = SSHKey(name=name)
    res = helpers.post_public_key("token", "public_key")
    assert m_ask_for_public_key_name.call_count == 1
    assert m_create_ssh_key.call_count == 1
    assert type(res) is list
    assert len(res) == 1
    assert type(res[0]) is SSHKey
Ejemplo n.º 8
0
def createKey():
    user_ssh_key = open(conf.digital_ocean['ssh-key']).read()
    key = SSHKey(token=conf.digital_ocean['token'],
                 name="template-ssh-key",
                 public_key=user_ssh_key)
    try:
        key.create()
    except Exception as e:
        print("[!] Already Created: " + str(e))
        return

    print('[+] Key Added to DigitalOcean Account')
Ejemplo n.º 9
0
def createKey():
    user_ssh_key = open(conf.digital_ocean['ssh-key']).read(
    )  #get public key to upload to digital ocean
    key = SSHKey(token=conf.digital_ocean['token'],
                 name="jumper-ssh-key",
                 public_key=user_ssh_key)
    try:
        key.create()  #If key is already created, an error will throw.
    except Exception as e:
        print("[!] Already Created: " + str(e))
        return  #break on thrown Exception

    print('[+] Key Added to DigitalOcean Account')
Ejemplo n.º 10
0
    def do_ssh_key(self):
        all_key = self.manager.get_all_sshkeys()
        for key in all_key:
            if key.name == SSH_KEY_NAME:
                return key

        key = SSHKey(
            token=self.token,
            name=SSH_KEY_NAME,
            public_key=self.config['ssh']['public'],
        )
        key.create()
        return key
Ejemplo n.º 11
0
        def Add_SSHKey(digo, tag: str, open_ssh_key: str):
            """Add a new OpenSSH key.
			Args:
				digo (DigitalOcean): Instantiated DigitalOcean credential object.
				tag (str):
				open_ssh_key (str): asymKeys['public']?
			Returns
				SSHKey: DigitalOcean SSHKey.
			"""
            key = SSHKey(token=digo.access_token,
                         name=tag,
                         public_key=open_ssh_key)
            resp = key.create()
            return key
Ejemplo n.º 12
0
def post_public_key(token: str, public_key: str) -> List[SSHKey]:
    """
    Given the API token and the public key, posts the public key to
    the account.

    :param str token: the API token
    :param str public_key: the public key
    :return: a list of one element digitalocean.SSHKey
    """
    name = questions.ask_for_public_key_name()
    ssh_key = SSHKey(token=token, name=name, public_key=public_key)

    # Post the ssh key to DO in order to get an ssh key id
    ssh_key = api.create_ssh_key(ssh_key)
    return [ssh_key]
Ejemplo n.º 13
0
def create():
	
	user = getpass.getuser()
	user_ssh_key = open('/home/{}/.ssh/id_rsa.pub'.format(user)).read()
	key = SSHKey(token='bb7f9e5b82a17b7304efde1b9cd886fc329f09340fa172c3c27d890b099c25cb',
				 name='uniquehostname',
				 public_key=user_ssh_key)

	try:
		key.create()
	except:
		pass

	print ("key stored in Digital Ocean account")
	print (key.name)

	# Create Droplet
	# get all ssh keys stored in the digitalocean account
	keys = manager.get_all_sshkeys()

	# droplet = Droplet(token='bb7f9e5b82a17b7304efde1b9cd886fc329f09340fa172c3c27d890b099c25cb',
	# 							name=request.args.get('name'),
	# 							region='blr1', # Bangalore
	# 							image='docker-16-04', # Docker
	# 							size_slug='512mb',  # '512mb'
	# 							ssh_keys=keys, #Automatic conversion
	# 							backups=False)


	# from chrome extension

	repo_url = request.args.get('giturl')
	droplet = Droplet(token='bb7f9e5b82a17b7304efde1b9cd886fc329f09340fa172c3c27d890b099c25cb',
						name=request.args.get('name'),
						region=request.args.get('region'),
						image='docker-16-04',
						size_slug=request.args.get('size'),
						ssh_keys=keys,
						backups=False)

	droplet.create()
	
	thread = Thread(target=commandrun, args=[droplet])
	thread.start()

	print ("droplet id {}".format(droplet.id))
	print ("DO Created & ssh tested")
	return ("DO Created & ssh tested")
def create_rsa():
    start = timer()
    ssh_name = 'RSA-' + name
    print("[+] Loading {} ... ".format(rsa_pub), end=" ")
    user_ssh_key = open(rsa_pub).read()
    key = SSHKey(token=token, name=ssh_name, public_key=user_ssh_key)
    try:
        key.create()
        print(timer() - start)
        return [key]

    except DataReadError:
        print(
            "[!] SSH {} Key is already in use on your account ( Generate new rsa file )"
            .format(ssh_name))
        exit(0)
Ejemplo n.º 15
0
def login():
	if request.args.get('code') is None:
		abort(404)
	# Get from Chrome extension
	token = request.args.get('code')
	manager = Manager(token=token)

	# Instantiate ``api`` object to setup authentication for DO API.
	my_droplets = manager.get_all_droplets()
	# Check for success
	print(my_droplets)

	user_ssh_key = request.args.get('ssh')
	key = SSHKey(token='bb7f9e5b82a17b7304efde1b9cd886fc329f09340fa172c3c27d890b099c25cb',
				 name='uniquehostname',
				 public_key=user_ssh_key)
	# key is created succesfully.
	key.create()
	return "Login Success"
Ejemplo n.º 16
0
def test_handle_ssh_keys_remote(
    m_ask_for_remote_ssh_keys_selection,
    m_ask_for_public_key_path,
    m_validate_public_key,
):
    m = mock.Mock()
    msg = "No ssh keys selected or found on DO! " \
          "Enter the path to your public key"
    m_ask_for_remote_ssh_keys_selection.return_value = []
    m_ask_for_public_key_path.return_value = "path/to/public/key"
    m_validate_public_key.return_value = None
    helpers.handle_ssh_keys(manager=m, addition_method="remote")

    m_ask_for_remote_ssh_keys_selection.assert_called_once_with(m)
    m_ask_for_public_key_path.assert_called_once_with(msg)

    m_ask_for_remote_ssh_keys_selection.return_value = [SSHKey(name='name')]
    res = helpers.handle_ssh_keys(manager=m, addition_method="remote")
    assert type(res) is list
    assert len(res) == 1
    assert type(res[0]) is SSHKey
    assert res[0].name == 'name'
Ejemplo n.º 17
0
if input('Add Google Maps? (Y/n): ') in ["", "y", "Y"]:
    json_vars["google_maps"] = {
        "api_key": "AIzaSyB0Ycb0-W0SoyQ8AzosjQGzGQ9yg1q8kKo"
    }

if input('Create DigitalOcean Droplet? (Y/n): ') in ["", "y", "Y"]:
    import digitalocean
    from digitalocean import SSHKey
    do_token = input('DigitalOcean token: ')
    manager = digitalocean.Manager(token=do_token)
    keys = manager.get_all_sshkeys()
    if len(keys) == 0:
        print('uploading your private key to digitalocean...')
        user_ssh_key = open(input('Public key path: ')).read()
        key = SSHKey(token=do_token,
                     name=socket.gethostname(),
                     public_key=user_ssh_key)
        key.create()
        keys = manager.get_all_sshkeys()
    print('creating droplet...')
    droplet = digitalocean.Droplet(
        token=do_token,
        name=input('Droplet name: '),
        region='sfo2',  # Amsterdam
        image='ubuntu-16-04-x64',  # Ubuntu 16.04 x64
        size_slug=input(f'{DIGITALOCEAN_SIZES}\nDroplet size: '),  # 512MB
        ssh_keys=keys,  # Automatic conversion
        backups=False)
    droplet.create()
    actions = droplet.get_actions()
    action = actions[0]
Ejemplo n.º 18
0
#!/usr/bin/python

### code used to import SSH key from workstation/jumpbox to droplet


from digitalocean import SSHKey

user_ssh_key = open('/home/myuser/.ssh/id_rsa.pub').read()

key = SSHKey(token='XXXXXXXXX',
	     name='my_website_key',
	     public_key=user_ssh_key )
		
	    

key.create()
Ejemplo n.º 19
0
 def add_key(self, key):
     user_ssh_key = key["public_key"]
     key = SSHKey(token=self.access_token,
                  name=key["name"],
                  public_key=user_ssh_key.strip())
     key.create()
Ejemplo n.º 20
0
        while True:
            existDroplet = manager.get_droplet(droplet_id=newDroplet.id)
            if existDroplet.ip_address != None:
                with open('hosts', 'w') as file:
                    file.write("""[jenkins-server]\n""" + existDroplet.ip_address)
                break

    except NameError as error:
        print("You hit an error ", error)

elif answer in noAnswers:
    print("Example: /Users/yoiurname/.ssh/id_rsa.pub")
    path = input("Please enter path to ssh-public_key :")
    try:
        user_ssh_key = open(path).read()
        key = SSHKey(token=myToken, name='newsshkey', public_key=user_ssh_key)
        key.create()

        manager = digitalocean.Manager(token=myToken)
        keys = manager.get_all_sshkeys()
        newDroplet = digitalocean.Droplet(token=myToken, name=nameDroplet, region="nyc1", \
        size_slug='1gb', image='centos-7-x64', ssh_keys=keys, backups=False)
        newDroplet.create()

        while True:
            existDroplet = manager.get_droplet(droplet_id=newDroplet.id)
            if existDroplet.ip_address != None:
                with open('hosts', 'w') as file:
                    file.write("""[jenkins-server]\n""" + existDroplet.ip_address)
                break
        print("Make sure you can login to this server :" + existDroplet.ip_address)
Ejemplo n.º 21
0
from digitalocean import SSHKey
import digitalocean
user_ssh_key = open('/Users/fsadykov/.ssh/id_rsa.pub').read()
key = SSHKey(token='6636374f68fc47bb1fbbf4bfd2a1f946a8e07409a8d097fff506a484bc50e7a4',
             name='My Mac',
             public_key=user_ssh_key)
key.create()


droplet = digitalocean.Droplet(token="6636374f68fc47bb1fbbf4bfd2a1f946a8e07409a8d097fff506a484bc50e7a4",
                               name='DropletWithSSHKeys',
                               region='ams3', # Amster
                               image='centos-7-x64', # Ubuntu 14.04 x64
                               size_slug='512mb',  # 512MB
                               ssh_keys=keys, #Automatic conversion
                               backups=False)
droplet.create()