hcloud-ssh-key-authorized

Description

Add ssh key to Hetzner cloud.

Variables

Name Type Default Description

api_token

string --

The hcloud API token. Required

key_content

string --

The content of the public ssh key. Required

name

string --

The alias of the ssh key on hcloud. Required

password

string --

The password to unlock the key (only used if key doesn't exist already).

path

string ~/.ssh/id_ed25519

The path to the private ssh key.

The path to the public key will be infered (added '.pub').

user

string --

The name of the ssh key owner.

Code

doc:
  short_help: Add ssh key to Hetzner cloud.
args:
  _import: ssh-key-exists
  name:
    doc:
      short_help: The alias of the ssh key on hcloud.
    type: string
    required: true
  api_token:
    doc:
      short_help: The hcloud API token.
    type: string
    required: true
    secret: true
  key_content:
    doc:
      short_help: The content of the public ssh key.
    type: string
    required: true
    excludes: path
  path:
    doc:
      short_help: The path to the private ssh key.
      help: |
        The path to the private ssh key.

        The path to the public key will be infered (added '.pub').
    type: string
    required: true
    excludes: key_content

frecklets:
- ssh-key-exists:
    frecklet::skip: '{{:: path | true_if_empty ::}}'
    path: '{{:: path ::}}'
    password: '{{:: password ::}}'
    user: '{{:: user ::}}'
- frecklet:
    name: hcloud-ssh-key-authorized.at.yml
    type: ansible-tasklist
    properties:
      elevated: false
      internet: true
      idempotent: true
    desc:
      short: "add ssh key with alias '{{:: name ::}}' to hcloud account"
      long: |
        {%:: if path -::%}
        Read the public key file '{{:: path ::}}.pub' and use the the content to create or overwrite a trusted ssh key on the hcloud project that is associated with the provided 'api_token', using the following details:{%:: else -::%}
        Use the 'key_content' string ( {{:: key_content ::}} ) to create or overwrite a trusted ssh key on the hcloud project that is associated with the provided 'api_token', using the following details:{%:: endif ::%}

            api_token: <your secret token>
            ssh key alias: {{:: name ::}}
    resources:
      python-package:
      - hcloud
      ansible-tasklist:
      - internally-register-public-ssh-key.at.yml
  task:
    become: false
  vars:
    __api_token__: '{{:: api_token ::}}'
    __name__: '{{:: name ::}}'
    __key_content__: '{{:: key_content ::}}'
    __path_to_key__: '{{:: path ::}}'
    __use_become__: '{{:: user | false_if_empty ::}}'
frecklecute --community hcloud-ssh-key-authorized --help

Usage: frecklecute hcloud-ssh-key-authorized [OPTIONS]

  Add ssh key to Hetzner cloud.

Options:
  --api-token API_TOKEN      The hcloud API token.  [required]
  --name NAME                The alias of the ssh key on hcloud.  [required]
  --key-content KEY_CONTENT  The content of the public ssh key.
  --password PASSWORD        The password to unlock the key (only used if key
                             doesn't exist already).
  --path PATH                The path to the private ssh key.
  --user USER                The name of the ssh key owner.
  --help                     Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.hcloud_ssh_key_authorized.HcloudSshKeyAuthorized
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class HcloudSshKeyAuthorized(AutoPycklet):
    """Add ssh key to Hetzner cloud.

       Args:
         api_token: The hcloud API token.
         key_content: The content of the public ssh key.
         name: The alias of the ssh key on hcloud.
         password: The password to unlock the key (only used if key doesn't exist already).
         path: The path to the private ssh key.
         user: The name of the ssh key owner.

    """

    FRECKLET_ID = "hcloud-ssh-key-authorized"

    api_token: str = None
    key_content: str = None
    name: str = None
    password: str = None
    path: str = None
    user: str = None


    def __post_init__(self):
        super(HcloudSshKeyAuthorized, self).__init__(var_names=["api_token", "key_content", "name", "password", "path", "user"])


frecklet_class = HcloudSshKeyAuthorized
# -*- coding: utf-8 -*-


#
# module path: pycklets.hcloud_ssh_key_authorized.HcloudSshKeyAuthorized
#


from pyckles import AutoPycklet

class HcloudSshKeyAuthorized(AutoPycklet):
    """Add ssh key to Hetzner cloud.

       Args:
         api_token: The hcloud API token.
         key_content: The content of the public ssh key.
         name: The alias of the ssh key on hcloud.
         password: The password to unlock the key (only used if key doesn't exist already).
         path: The path to the private ssh key.
         user: The name of the ssh key owner.

    """

    FRECKLET_ID = "hcloud-ssh-key-authorized"

    def __init__(self, api_token=None, key_content=None, name=None, password=None, path="~/.ssh/id_ed25519", user=None):

        super(HcloudSshKeyAuthorized, self).__init__(var_names=["api_token", "key_content", "name", "password", "path", "user"])
        self._api_token = api_token
        self._key_content = key_content
        self._name = name
        self._password = password
        self._path = path
        self._user = user

    @property
    def api_token(self):
        return self._api_token

    @api_token.setter
    def api_token(self, api_token):
        self._api_token = api_token

    @property
    def key_content(self):
        return self._key_content

    @key_content.setter
    def key_content(self, key_content):
        self._key_content = key_content

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, password):
        self._password = password

    @property
    def path(self):
        return self._path

    @path.setter
    def path(self, path):
        self._path = path

    @property
    def user(self):
        return self._user

    @user.setter
    def user(self, user):
        self._user = user



frecklet_class = HcloudSshKeyAuthorized