def test_convert_to_api_with_email(self):
     user = '******'
     email = '*****@*****.**'
     password = '******'
     expected = {
         'username':
         '******',
         'email':
         '*****@*****.**',
         'name':
         'r-infraops-git',
         'password':
         '******',
         'ssh-key':
         'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCJlrG43+2eJDNi3pkIph8PHCqJAoTRq1sRVZZ9tW0AXSXROOcxB1wLHFIx9iiBKNKqrxSRmFyKaWtvMjSqxL7e62Ll+QfjQGt8UyyiTVfWFx+aGy8YUil3OPej7UayOS3Izk6zwDUvRAjP41kIdZEP8oRTvRbUdo3j8sLIaSkF/yiYtqehSl2yZasQAOubLBbk4hq5sgLfmdyScb6J+zRn5SEwMHNufTbPQXArAeZa+zVA4y/zrCecPRIKfWCi6JadaZRS7DPa2Eyj1ShLVDqD7vIT4EyhAIkPFXam+MK641DyoNj9HSHv5FaAt6fSvQaH9PR/MCSSSdwgb6YT/Jx [email protected]'
     }
     role_user = CreateRoleAccount(self.users_filename,
                                   self.ssl_auth_filename,
                                   account_name=user,
                                   account_password=password,
                                   account_email=email)
     role_user.convert_to_api()
     actual = role_user.new_user
     self.assertEqual(expected, actual,
                      "Expected {}, but got {}".format(expected, actual))
 def test_failed_import_ssh_sls(self):
     user = "******"
     password = "******"
     role_user = CreateRoleAccount(
         self.bad_users_filename, self.bad_ssl_auth_filename, account_name=user, account_password=password
     )
     with self.assertRaises(yaml.scanner.ScannerError):
         role_user.import_ssh_sls()
 def test_failed_import_ssh_sls(self):
     user = '******'
     password = '******'
     role_user = CreateRoleAccount(self.bad_users_filename,
                                   self.bad_ssl_auth_filename,
                                   account_name=user,
                                   account_password=password)
     with self.assertRaises(yaml.scanner.ScannerError):
         role_user.import_ssh_sls()
    def test_bad_convert_to_api_without_username(self):

        with self.assertRaises(StandardError):
            user = "******"
            password = "******"
            role_user = CreateRoleAccount(
                self.users_filename, self.ssl_auth_filename, account_name=user, account_password=password
            )
            role_user.convert_to_api()
    def test_bad_convert_to_api_without_username(self):

        with self.assertRaises(StandardError):
            user = '******'
            password = '******'
            role_user = CreateRoleAccount(self.users_filename,
                                          self.ssl_auth_filename,
                                          account_name=user,
                                          account_password=password)
            role_user.convert_to_api()
def main():
    args = parse_arguments()
    config = import_config(args.config_file)

    pillar_periodic = config.get('repo', 'pillar_periodic')
    gitlab_token = config.get('gitlab', 'token')
    gitlab_url = config.get('gitlab', 'url')
    role_account_name = args.account_name

    if args.account_email:
        email = args.account_email
    else:
        email = None

    if args.password:
        password = args.password
    else:
        password = generate_random_password(args.random_password_length)

    try:
        assert os.path.isdir(pillar_periodic)
    except:
        print "Unable to located pillar_periodic directory"
        sys.exit(1)

    try:
        repo = git.cmd.Git(pillar_periodic)
        repo.pull()
    except:
        e = sys.exc_info()[0]
        print "Failed to pull down changes to pillar_periodic, error: {}".format(e)
        sys.exit(1)

    ssh_path = os.path.join(pillar_periodic, "core/accountz/ssh_auth.sls")
    user_path = os.path.join(pillar_periodic, "core/accountz/users.sls")

    # Okay lets create this account
    gl_connection = CreateRoleAccount(user_path, ssh_path, account_name=role_account_name,
                                      account_password=password, account_email=email, gitlab_key=gitlab_token,
                                      gitlab_url=gitlab_url)

    gl_connection.convert_to_api()
    role_user_id = gl_connection.send_to_gitlab()

    if gl_connection.verify_create(role_user_id):
        print "{} Role user successfully created".format(role_account_name)
        try:
            print "The random password is {}".format(password)
        except:
            pass
    else:
        print "{} Role user not created".format(role_account_name)
 def test_import_ssh_sls(self):
     """
     Testing the import_ssh_sls function
     """
     user = "******"
     password = "******"
     role_user = CreateRoleAccount(
         self.users_filename, self.ssl_auth_filename, account_name=user, account_password=password
     )
     expected = dict
     role_user.import_ssh_sls()
     actual = type(role_user.ssh)
     self.assertEqual(expected, actual, "Expected type {}. but got {},".format(expected, actual))
 def test_import_ssh_sls(self):
     """
     Testing the import_ssh_sls function
     """
     user = '******'
     password = '******'
     role_user = CreateRoleAccount(self.users_filename,
                                   self.ssl_auth_filename,
                                   account_name=user,
                                   account_password=password)
     expected = dict
     role_user.import_ssh_sls()
     actual = type(role_user.ssh)
     self.assertEqual(
         expected, actual,
         "Expected type {}. but got {},".format(expected, actual))
 def test_convert_to_api_without_email(self):
     user = "******"
     password = "******"
     expected = {
         "username": "******",
         "email": "*****@*****.**",
         "name": "r-infraops-git",
         "password": "******",
         "ssh-key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCJlrG43+2eJDNi3pkIph8PHCqJAoTRq1sRVZZ9tW0AXSXROOcxB1wLHFIx9iiBKNKqrxSRmFyKaWtvMjSqxL7e62Ll+QfjQGt8UyyiTVfWFx+aGy8YUil3OPej7UayOS3Izk6zwDUvRAjP41kIdZEP8oRTvRbUdo3j8sLIaSkF/yiYtqehSl2yZasQAOubLBbk4hq5sgLfmdyScb6J+zRn5SEwMHNufTbPQXArAeZa+zVA4y/zrCecPRIKfWCi6JadaZRS7DPa2Eyj1ShLVDqD7vIT4EyhAIkPFXam+MK641DyoNj9HSHv5FaAt6fSvQaH9PR/MCSSSdwgb6YT/Jx [email protected]",
     }
     role_user = CreateRoleAccount(
         self.users_filename, self.ssl_auth_filename, account_name=user, account_password=password
     )
     role_user.convert_to_api()
     actual = role_user.new_user
     self.assertEqual(expected, actual, "Expected {}, but got {}".format(expected, actual))
示例#10
0
def main():
    args = parse_arguments()
    config = import_config(args.config_file)

    pillar_periodic = config.get('repo', 'pillar_periodic')
    gitlab_token = config.get('gitlab', 'token')
    gitlab_url = config.get('gitlab', 'url')
    role_account_name = args.account_name

    if args.account_email:
        email = args.account_email
    else:
        email = None

    if args.password:
        password = args.password
    else:
        password = generate_random_password(args.random_password_length)

    try:
        assert os.path.isdir(pillar_periodic)
    except:
        print "Unable to located pillar_periodic directory"
        sys.exit(1)

    try:
        repo = git.cmd.Git(pillar_periodic)
        repo.pull()
    except:
        e = sys.exc_info()[0]
        print "Failed to pull down changes to pillar_periodic, error: {}".format(
            e)
        sys.exit(1)

    ssh_path = os.path.join(pillar_periodic, "core/accountz/ssh_auth.sls")
    user_path = os.path.join(pillar_periodic, "core/accountz/users.sls")

    # Okay lets create this account
    gl_connection = CreateRoleAccount(user_path,
                                      ssh_path,
                                      account_name=role_account_name,
                                      account_password=password,
                                      account_email=email,
                                      gitlab_key=gitlab_token,
                                      gitlab_url=gitlab_url)

    gl_connection.convert_to_api()
    role_user_id = gl_connection.send_to_gitlab()

    if gl_connection.verify_create(role_user_id):
        print "{} Role user successfully created".format(role_account_name)
        try:
            print "The random password is {}".format(password)
        except:
            pass
    else:
        print "{} Role user not created".format(role_account_name)