<commit_before>from cloudify import ctx
from cloudify import exceptions as cfy_exc
from cloudify.decorators import operation
import os.path
from os import chmod
from Crypto.PublicKey import RSA
from Crypto import Random

AUTO_GENERATE = 'auto_generate'
PRIVATE_KEY = 'private_key'
PUBLIC_KEY = 'public_key'
PATH = 'path'
KEY = 'key'
USER = 'user'


@operation
def creation_validation(**kwargs):
    """
        check availability of path used in field private_key_path of
        node properties
    """
    key = ctx.node.properties.get(PRIVATE_KEY)
    if key.get(PATH):
        key_path = os.path.expanduser(key)
        if not os.path.isfile(key_path):
            raise cfy_exc.NonRecoverableError(
                "Private key file {0} is absent".format(key_path))


@operation
def create(**kwargs):
    ctx.instance.runtime_properties[PUBLIC_KEY] = {}
    ctx.instance.runtime_properties[PRIVATE_KEY] = {}
    ctx.instance.runtime_properties[PUBLIC_KEY][USER] = ctx.node.properties.get(PUBLIC_KEY).get(USER)
    if ctx.node.properties.get(AUTO_GENERATE):
        ctx.logger.info("Generating ssh keypair")
        Random.atfork()  # uses for strong key generation
        public, private = _generate_pair()
        ctx.instance.runtime_properties[PRIVATE_KEY][PATH] = _create_path()
        ctx.instance.runtime_properties[PRIVATE_KEY][KEY] = private
        ctx.instance.runtime_properties[PUBLIC_KEY][KEY] = public
        _save_key_file(ctx.instance.runtime_properties[PRIVATE_KEY][PATH],
                       ctx.instance.runtime_properties[PRIVATE_KEY][KEY])
    else:
        ctx.instance.runtime_properties[PUBLIC_KEY][KEY] = ctx.node.properties.get(PUBLIC_KEY).get(KEY)<commit_msg>CFY-3206 Copy private key path to rintime properties<commit_after>from cloudify import ctx
from cloudify import exceptions as cfy_exc
from cloudify.decorators import operation
import os.path
from os import chmod
from Crypto.PublicKey import RSA
from Crypto import Random

AUTO_GENERATE = 'auto_generate'
PRIVATE_KEY = 'private_key'
PUBLIC_KEY = 'public_key'
PATH = 'path'
KEY = 'key'
USER = 'user'


@operation
def creation_validation(**kwargs):
    """
        check availability of path used in field private_key_path of
        node properties
    """
    key = ctx.node.properties.get(PRIVATE_KEY)
    if key.get(PATH):
        key_path = os.path.expanduser(key)
        if not os.path.isfile(key_path):
            raise cfy_exc.NonRecoverableError(
                "Private key file {0} is absent".format(key_path))


@operation
def create(**kwargs):
    ctx.instance.runtime_properties[PUBLIC_KEY] = {}
    ctx.instance.runtime_properties[PRIVATE_KEY] = {}
    ctx.instance.runtime_properties[PUBLIC_KEY][USER] = ctx.node.properties.get(PUBLIC_KEY).get(USER)
    if ctx.node.properties.get(AUTO_GENERATE):
        ctx.logger.info("Generating ssh keypair")
        Random.atfork()  # uses for strong key generation
        public, private = _generate_pair()
        ctx.instance.runtime_properties[PRIVATE_KEY][PATH] = _create_path()
        ctx.instance.runtime_properties[PRIVATE_KEY][KEY] = private
        ctx.instance.runtime_properties[PUBLIC_KEY][KEY] = public
        _save_key_file(ctx.instance.runtime_properties[PRIVATE_KEY][PATH],
                       ctx.instance.runtime_properties[PRIVATE_KEY][KEY])
    else:
        ctx.instance.runtime_properties[PUBLIC_KEY][KEY] = ctx.node.properties.get(PUBLIC_KEY).get(KEY)
        ctx.instance.runtime_properties[PRIVATE_KEY][PATH] = ctx.node.properties[PRIVATE_KEY].get(PATH)
{'fraction_non_alphanumeric': 0.10319479785128641, 'fraction_numerical': 0.0016963528413910093, 'mean_word_length': 3.787550744248985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4979116', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1071, 'n_words': 214}