Esempio n. 1
0
def _parse_edgerc(file, section):
    if not os.path.isfile(file):
        return None
    edgerc = EdgeRc(file)
    config = {
        "access_token": edgerc.get(section, 'access_token'),
        "client_token": edgerc.get(section, 'client_token'),
        "host": edgerc.get(section, 'host'),
        "max-body": edgerc.getint(section, 'max-body'),
        "secret": edgerc.get(section, 'client_secret'),
        "signed-header": edgerc.get(section, 'headers_to_sign')
    }

    # The EdgeRc library ensures the whole file must be valid. If host is empty then there's no config found.
    if config['host'] is None:
        return None

    return config
Esempio n. 2
0
    def get_auth(self, username: str = None, password: str = None):
        rc_path = os.path.expanduser(RC_PATH or os.getenv("RC_PATH") or '~/.edgerc')

        if not os.path.exists(rc_path):
            err_msg = "\nERROR: The provided %s file does not exist\n" % rc_path
            err_msg += "ERROR: Please generate credentials for the script functionality\n"
            err_msg += "ERROR: and run 'python gen_edgerc.py %s' to generate the credential file\n"
            sys.stderr.write(err_msg)
            sys.exit(1)

        try:
            rc = EdgeRc(rc_path)
        except (configparser.DuplicateSectionError, configparser.MissingSectionHeaderError, UnicodeDecodeError):
            err_msg = '''
ERROR: {0} is not a valid .edgerc file
ERROR: Please generate credentials for the script functionality
ERROR: and run 'python gen_edgerc.py %s' to generate the credential file
'''.format(rc_path)
            sys.stderr.write(err_msg)
            sys.exit(2)

        if not rc.has_section(username):
            err_msg = "\nERROR: No section named '%s' was found in your .edgerc file\n" % username
            err_msg += "ERROR: Please generate credentials for the script functionality\n"
            err_msg += "ERROR: and run 'python gen_edgerc.py %s' to generate the credential file\n"
            sys.stderr.write(err_msg)
            sys.exit(3)

        host = rc.get(username, 'host')
        host = host.replace("https://", "")
        host = host.replace("/", "")
        host += "/"
        auth = HTTPieEdgeGridAuth(
            hostname=host,
            client_token=rc.get(username, 'client_token'),
            client_secret=rc.get(username, 'client_secret'),
            access_token=rc.get(username, 'access_token'),
            max_body=rc.getint(username, 'max_body')
        )
        return auth
    def get_auth(self, username, password):
        home = os.environ['HOME']	
        rc = EdgeRc("%s/.edgerc" % home) 
 
        if not rc.has_section(username):
            err_msg = "\nERROR: No section named '%s' was found in your .edgerc file\n" % username
            err_msg += "ERROR: Please generate credentials for the script functionality\n"
            err_msg += "ERROR: and run 'python gen_edgerc.py %s' to generate the credential file\n"
            sys.stderr.write(err_msg)
            sys.exit(1)

        host=rc.get(username, 'host')
        host=host.replace("https://", "")
        host= host.replace ("/","")
        host += "/"
        auth = HTTPieEdgeGridAuth(
            hostname = host,
            client_token=rc.get(username, 'client_token'),
            client_secret=rc.get(username, 'client_secret'),
            access_token=rc.get(username, 'access_token'),
            max_body=rc.getint(username, 'max_body')
        )
        return auth
Esempio n. 4
0
    def get_auth(self, username, password):
        rc_path = os.path.expanduser("~/.edgerc")
        rc = EdgeRc(rc_path)

        if not rc.has_section(username):
            err_msg = "\nERROR: No section named '%s' was found in your .edgerc file\n" % username
            err_msg += "ERROR: Please generate credentials for the script functionality\n"
            err_msg += "ERROR: and run 'python gen_edgerc.py %s' to generate the credential file\n"
            sys.stderr.write(err_msg)
            sys.exit(1)

        host = rc.get(username, 'host')
        host = host.replace("https://", "")
        host = host.replace("/", "")
        host += "/"
        auth = HTTPieEdgeGridAuth(hostname=host,
                                  client_token=rc.get(username,
                                                      'client_token'),
                                  client_secret=rc.get(username,
                                                       'client_secret'),
                                  access_token=rc.get(username,
                                                      'access_token'),
                                  max_body=rc.getint(username, 'max_body'))
        return auth