Beispiel #1
0
 def auth_token(self):
     token = api.get_auth_token(self.sane_config.get('halo', 'api_host'),
                                self.key, self.secret)
     self.assertIsNotNone(
         token, 'Could not exectue the API using '
         'the key, secret and host provided.')
     return token
Beispiel #2
0
def main(args, config):
    # get the default section from the config file
    dsection = config._sections['halo']

    if sane(config):
        # Get API key, set in config structure
        dsection["auth_token"] = api.get_auth_token(*[
            dsection[x] for x in ("api_host", "api_key", "api_secret",
                                  "proxy_host", "proxy_port")
        ])
        # Get the policy stuff
        infobundle = fn.get_all_policies(*[
            dsection[x]
            for x in ("api_host", "auth_token", "proxy_host", "proxy_port")
        ])

        fn.get_specific(
            dsection["api_host"],
            dsection["auth_token"],
            dsection["repo_base_path"] or ".",
            infobundle,
            dsection["proxy_host"],
            dsection["proxy_port"],
        )

        # Write files to disk, return bool
        if fn.localcommit(dsection["repo_base_path"]):
            print("Updated files written to disk.")
            print(
                fn.remotepush(dsection["repo_base_path"] or ".",
                              dsection["repo_commit_comment"]))
        else:
            sys.exit("Error message: Failure to write locally!")
def main(args, config):
    # get the default section from the config file
    dsection = config._sections['halo']

    if sane(config):
        # Get API key, set in config structure
        dsection["auth_token"] = api.get_auth_token(
            *[dsection[x] for x in
             ("api_host", "api_key", "api_secret",
              "proxy_host", "proxy_port")])
        # Get the policy stuff
        infobundle = fn.get_all_policies(
            *[dsection[x] for x in
             ("api_host", "auth_token",
              "proxy_host", "proxy_port")])

        fn.get_specific(
            dsection["api_host"],
            dsection["auth_token"],
            dsection["repo_base_path"] or ".",
            infobundle,
            dsection["proxy_host"],
            dsection["proxy_port"],
            )

        # Write files to disk, return bool
        if fn.localcommit(dsection["repo_base_path"]):
            print("Updated files written to disk.")
            print(fn.remotepush(
                dsection["repo_base_path"] or ".",
                dsection["repo_commit_comment"]))
        else:
            sys.exit("Error message: Failure to write locally!")
def main(argv):
    # Parse args from CLI
    cli = parse_cli(argv)
    # Dictionary of config items
    config = parse_config(cli)
    # Error Message
    usagetext = (
        "halo-policy-backup.py -c CONFIGFILE (OPTIONAL)" +
        "Please specify your file name, if not using the default config file\n"
        +
        "NOTE: Format of config file should follow the default config file\n")

    # Sanity Checks
    # Check if the directory for each policy exist
    directoryexist = sanity.check_path(config["repo_base_path"])
    if directoryexist == False:
        sys.exit(
            "Error message: Please make changes according to above error message"
        )
    # Check the information in config file
    goodconfig = sanity.config(config)
    if goodconfig == False:
        sys.exit(
            "Error message: Please make sure you have filled all the required information in config file"
        )

    # Get API key, set in config structure
    config["auth_token"] = api.get_auth_token(config["api_host"],
                                              config["api_key"],
                                              config["api_secret"],
                                              config["prox"])
    # Get the policy stuff
    infobundle = fn.get_all_policies(config["api_host"], config["auth_token"],
                                     config["prox"])
    finalbundle = fn.get_specific(config["api_host"], config["auth_token"],
                                  config["prox"], config["repo_base_path"],
                                  infobundle)
    # Write files to disk, return bool
    localsuccess = fn.localcommit(config["repo_base_path"])
    if localsuccess == False:
        sys.exit("Error message: Failure to write locally!")
    else:
        print "Updated files written to disk."
        remotesuccess = fn.remotepush(config["repo_base_path"],
                                      config["repo_commit_comment"])
        print remotesuccess
def main(argv):
    # Parse args from CLI
    cli = parse_cli(argv)
    # Dictionary of config items
    config = parse_config(cli)
    # Error Message
    usagetext = (
        "halo-policy-backup.py -c CONFIGFILE (OPTIONAL)"
        + "Please specify your file name, if not using the default config file\n"
        + "NOTE: Format of config file should follow the default config file\n"
    )

    # Sanity Checks
    # Check if the directory for each policy exist
    directoryexist = sanity.check_path(config["repo_base_path"])
    if directoryexist == False:
        sys.exit("Error message: Please make changes according to above error message")
    # Check the information in config file
    goodconfig = sanity.config(config)
    if goodconfig == False:
        sys.exit("Error message: Please make sure you have filled all the required information in config file")

    # Get API key, set in config structure
    config["auth_token"] = api.get_auth_token(
        config["api_host"], config["api_key"], config["api_secret"], config["prox"]
    )
    # Get the policy stuff
    infobundle = fn.get_all_policies(config["api_host"], config["auth_token"], config["prox"])
    finalbundle = fn.get_specific(
        config["api_host"], config["auth_token"], config["prox"], config["repo_base_path"], infobundle
    )
    # Write files to disk, return bool
    localsuccess = fn.localcommit(config["repo_base_path"])
    if localsuccess == False:
        sys.exit("Error message: Failure to write locally!")
    else:
        print "Updated files written to disk."
        remotesuccess = fn.remotepush(config["repo_base_path"], config["repo_commit_comment"])
        print remotesuccess
Beispiel #6
0
def set_config_items(config,argv):
    try:
        opts, args = getopt.getopt(argv, "hs:c:a",["search_string=","configfile="])
    except getopt.GetoptError:
        print config['usagetext']
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print config['usagetext']
            sys.exit()
        elif opt == '-a':
            config['search_string'] = 'ALL'
        elif opt in ("-s","--search_string"):
            config['search_string'] = arg
        elif opt in ("-c","--configfile"):
            config['configfile'] = arg
    execfile(config['configfile'], config)
    if not sanity_check(config):
        print "Config is not sane!"
        sys.exit(2)
    config['prox'] = {'host': config['prox_host'], 'port': config['prox_port'] }
    config['authtoken'] = api.get_auth_token(config['host'], config['clientid'], config['clientsecret'], config['prox'])
    return(config)
Beispiel #7
0
 def login(self, userid, password):
     api.authToken = api.get_auth_token(api.apiKey, userid, password)