예제 #1
0
 def __init__(self, service_url):        
     self.service_url = service_url
     result = urlparse.urlparse(service_url)
     self.host = result.netloc
     self.query = result.path      
     self.ep = self.__get_ep(self.query)
     self.path = self.__get_path(self.query)
     self.user = result.username  
     self.password = result.password
     
     result = get_go_auth(ca_certs=None, username=self.user, password=self.password)
     saml_cookie = result.cookie
     
     self.api = api_client.TransferAPIClient(username=self.user,
                                             saml_cookie=saml_cookie
                                             )
     status_code, status_message, data = self.api.task_list()
     
     # initialize ssh client
     self.__state=State.New
예제 #2
0
def process_args(args=None, parser=None):
    from optparse import OptionParser

    if not parser:
        usage = "usage: %prog username [options]"
        parser = OptionParser(usage=usage)

    parser.add_option("-C", "--server-ca-file", dest="server_ca_file",
                      help="ca file for validating server",
                      metavar="SERVER_CA_FILE")
    parser.add_option("-c", "--cert", dest="cert_file",
                      help="client cert file", metavar="CERT_FILE")
    parser.add_option("-k", "--key", dest="key_file",
                      help="client key file", metavar="KEY_FILE")
    parser.add_option("-s", "--saml-cookie", dest="saml_cookie",
                      help="alternate authentication method",
                      metavar="COOKIE_DATA")
    parser.add_option("-p", "--password-prompt", dest="password_prompt",
                      action="store_true", default=False,
                      help="prompt for GO password for authentication")
    parser.add_option("-b", "--base-url", dest="base_url",
                      help="alternate base URL", metavar="URL")
    parser.add_option("-t", "--socket-timeout", dest="timeout", type="int",
                      help="timeout in seconds for underlying TCP socket",
                      metavar="TIMEOUT_SECONDS")
    parser.add_option("-a", "--max-attempts", dest="max_attempts", type="int",
                      help="retry up to this many times on connection errors",
                      metavar="ATTEMPTS")
    parser.set_defaults(base_url=DEFAULT_BASE_URL,
                        max_attempts=1,
                        timeout=socket._GLOBAL_DEFAULT_TIMEOUT)

    options, args = parser.parse_args(args)
    if len(args) < 1:
        parser.error("username arguments is required")

    if options.password_prompt:
        if options.saml_cookie or options.key_file or options.cert_file:
            parser.error("use only one authentication method: -p, -k/-c, or -s")
        username = args[0]
        success = False
        for i in xrange(5):
            try:
                result = get_go_auth(ca_certs=options.server_ca_file,
                                     username=username)
                args[0] = result.username
                options.saml_cookie = result.cookie
                success = True
                break
            except InterfaceError as e:
                sys.stderr.write("authentication to GO failed")
                if i < 4:
                     sys.stderr.write(", please try again")
                sys.stderr.write("\n")
                username = None
        if not success:
            sys.stderr.write("too many failed attempts, exiting\n")
            sys.exit(2)
    elif options.saml_cookie:
        if options.key_file or options.cert_file:
            parser.error("use only one authentication method: -p, -k/-c, or -s")
    else:
        # If only one of -k/-c is specified, assume both the key and cert are
        # in the same file.
        if not options.key_file:
            if not options.cert_file:
                parser.error(
                    "specify one authentication method: -p, -k/-c, or -s")
            options.key_file = options.cert_file
        if not options.cert_file:
            options.cert_file = options.key_file

    return options, args
예제 #3
0
def process_args(args=None, parser=None):
    from optparse import OptionParser

    if not parser:
        usage = "usage: %prog username -k KEY_FILE -c CERT_FILE " \
              + "-C SERVER_CA_FILE"
        parser = OptionParser(usage=usage)

    parser.add_option("-C",
                      "--server-ca-file",
                      dest="server_ca_file",
                      help="ca file for validating server",
                      metavar="SERVER_CA_FILE")
    parser.add_option("-c",
                      "--cert",
                      dest="cert_file",
                      help="client cert file",
                      metavar="CERT_FILE")
    parser.add_option("-k",
                      "--key",
                      dest="key_file",
                      help="client key file",
                      metavar="KEY_FILE")
    parser.add_option("-s",
                      "--saml-cookie",
                      dest="saml_cookie",
                      help="alternate authentication method",
                      metavar="COOKIE_DATA")
    parser.add_option("-p",
                      "--password-prompt",
                      dest="password_prompt",
                      action="store_true",
                      default=False,
                      help="prompt for GO password for authentication")
    parser.add_option("-b",
                      "--base-url",
                      dest="base_url",
                      help="alternate base URL",
                      metavar="URL")
    parser.add_option("-t",
                      "--socket-timeout",
                      dest="timeout",
                      type="int",
                      help="timeout in seconds for underlying TCP socket",
                      metavar="TIMEOUT_SECONDS")
    parser.add_option("-a",
                      "--max-attempts",
                      dest="max_attempts",
                      type="int",
                      help="retry up to this many times on connection errors",
                      metavar="ATTEMPTS")
    parser.set_defaults(base_url=DEFAULT_BASE_URL,
                        max_attempts=1,
                        timeout=socket._GLOBAL_DEFAULT_TIMEOUT)

    options, args = parser.parse_args(args)
    if len(args) < 1:
        parser.error("username arguments is required")

    if not options.server_ca_file:
        parser.error("missing required option -C (--server-ca-file)")

    if options.password_prompt:
        if options.saml_cookie or options.key_file or options.cert_file:
            parser.error(
                "use only one authentication method: -p, -k/-c, or -s")
        username = args[0]
        success = False
        for i in xrange(5):
            try:
                result = get_go_auth(ca_certs=options.server_ca_file,
                                     username=username)
                args[0] = result.username
                options.saml_cookie = result.cookie
                success = True
                break
            except InterfaceError as e:
                sys.stderr.write("authentication to GO failed")
                if i < 4:
                    sys.stderr.write(", please try again")
                sys.stderr.write("\n")
                username = None
        if not success:
            sys.stderr.write("too many failed attempts, exiting\n")
            sys.exit(2)
    elif options.saml_cookie:
        if options.key_file or options.cert_file:
            parser.error(
                "use only one authentication method: -p, -k/-c, or -s")
    elif not options.key_file or not options.cert_file:
        parser.error("specify one authentication method: -p, -k/-c, or -s")

    return options, args