source/soca/cluster_web_ui/api/v1/ldap/activedirectory/user.py [39:74]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    try:
        user_home = config.Config.USER_HOME
        key = rsa.generate_private_key(backend=crypto_default_backend(), public_exponent=65537, key_size=2048)
        private_key = key.private_bytes(
            crypto_serialization.Encoding.PEM,
            crypto_serialization.PrivateFormat.TraditionalOpenSSL,
            crypto_serialization.NoEncryption())
        public_key = key.public_key().public_bytes(
            crypto_serialization.Encoding.OpenSSH,
            crypto_serialization.PublicFormat.OpenSSH
        )
        private_key_str = private_key.decode('utf-8')
        public_key_str = public_key.decode('utf-8')
        # Create user directory structure
        user_path = f"{user_home}/{username}/.ssh"
        os.makedirs(user_path)

        # Copy default .bash profile
        shutil.copy('/etc/skel/.bashrc', f'{"/".join(user_path.split("/")[:-1])}/')
        shutil.copy('/etc/skel/.bash_profile', f'{"/".join(user_path.split("/")[:-1])}/')
        shutil.copy('/etc/skel/.bash_logout', f'{"/".join(user_path.split("/")[:-1])}/')

        # Create SSH keypair
        print(private_key_str, file=open(user_path + '/id_rsa', 'w'))
        print(public_key_str, file=open(user_path + '/id_rsa.pub', 'w'))
        print(public_key_str, file=open(user_path + '/authorized_keys', 'w'))

        # Adjust file/folder ownership
        for path in [f"{user_home}/{username}",
                     f"{user_home}/{username}/.ssh",
                     f"{user_home}/{username}/.ssh/authorized_keys",
                     f"{user_home}/{username}/.ssh/id_rsa",
                     f"{user_home}/{username}/.ssh/id_rsa.pub",
                     f"{user_home}/{username}/.bashrc",
                     f"{user_home}/{username}/.bash_profile",
                     f"{user_home}/{username}/.bash_logout"]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



source/soca/cluster_web_ui/api/v1/ldap/openldap/user.py [37:73]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    try:
        user_home = config.Config.USER_HOME
        key = rsa.generate_private_key(backend=crypto_default_backend(), public_exponent=65537, key_size=2048)
        private_key = key.private_bytes(
            crypto_serialization.Encoding.PEM,
            crypto_serialization.PrivateFormat.TraditionalOpenSSL,
            crypto_serialization.NoEncryption())
        public_key = key.public_key().public_bytes(
            crypto_serialization.Encoding.OpenSSH,
            crypto_serialization.PublicFormat.OpenSSH
        )
        private_key_str = private_key.decode('utf-8')
        public_key_str = public_key.decode('utf-8')

        # Create user directory structure
        user_path = f"{user_home}/{username}/.ssh"
        os.makedirs(user_path)

        # Copy default .bash profile
        shutil.copy('/etc/skel/.bashrc', f'{"/".join(user_path.split("/")[:-1])}/')
        shutil.copy('/etc/skel/.bash_profile', f'{"/".join(user_path.split("/")[:-1])}/')
        shutil.copy('/etc/skel/.bash_logout', f'{"/".join(user_path.split("/")[:-1])}/')

        # Create SSH keypair
        print(private_key_str, file=open(user_path + '/id_rsa', 'w'))
        print(public_key_str, file=open(user_path + '/id_rsa.pub', 'w'))
        print(public_key_str, file=open(user_path + '/authorized_keys', 'w'))

        # Adjust file/folder ownership
        for path in [f"{user_home}/{username}",
                     f"{user_home}/{username}/.ssh",
                     f"{user_home}/{username}/.ssh/authorized_keys",
                     f"{user_home}/{username}/.ssh/id_rsa",
                     f"{user_home}/{username}/.ssh/id_rsa.pub",
                     f"{user_home}/{username}/.bashrc",
                     f"{user_home}/{username}/.bash_profile",
                     f"{user_home}/{username}/.bash_logout"]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



