Пример #1
0
def list(cli):
    """
    Get list of accounts or a specific one
    """
    uid = cli._arg(0)
    url = "" 
    if len(uid) == 0 :
        url = build_url("account")
    else:
        url = build_url("account/" + uid)
    log.debug(url)
    if cli.args.format == 'json':
        httpiecolor.console_response(httpapi.doapi(url))
    else:
        resp = httpapi.doapi(url)
        if resp.status_code < 400:
            data = json.loads(resp.text)
            out = [['Name', "YourId","Account ID","apikey"]]
            if "data" in data:
                if isinstance(data["data"],dict):
                    httpiecolor.console_response(resp)
                else:
                    for u in data["data"]:
                        out.append([u["name"],u["fid"],u["aid"],u["apikey"]])
                    print("")
                    pprint_table(sys.stdout,out)
Пример #2
0
def list(cli):
    """
    Get list of Users or a specific one
    """
    uid = cli._arg(0)
    url = "" 
    if len(uid) == 0 :
        url = build_url("user")
    else:
        url = build_url("user/" + uid)
    log.debug(url)
    if cli.args.format == 'json':
        httpiecolor.console_response(httpapi.doapi(url))
    else:
        resp = httpapi.doapi(url)
        if resp.status_code < 400:
            data = json.loads(resp.text)
            out = [['Name', "Email","Roles"]]
            if "data" in data:
                if isinstance(data["data"],dict):
                    httpiecolor.console_response(resp)
                else:
                    for u in data["data"]:
                        roles = ""
                        if "roles" in u and type(u["roles"]) == type([]):
                            roles = ",".join(u['roles'])
                        out.append([u["name"],u["email"],roles])
                    print("")
                    pprint_table(sys.stdout,out)
Пример #3
0
def list(cli):
    """
    Get list of accounts or a specific one
    """
    uid = cli._arg(0)
    url = ""
    if len(uid) == 0:
        url = build_url("account")
    else:
        url = build_url("account/" + uid)
    log.debug(url)
    if cli.args.format == 'json':
        httpiecolor.console_response(httpapi.doapi(url))
    else:
        resp = httpapi.doapi(url)
        if resp.status_code < 400:
            data = json.loads(resp.text)
            out = [['Name', "YourId", "Account ID", "apikey"]]
            if "data" in data:
                if isinstance(data["data"], dict):
                    httpiecolor.console_response(resp)
                else:
                    for u in data["data"]:
                        out.append(
                            [u["name"], u["fid"], u["aid"], u["apikey"]])
                    print("")
                    pprint_table(sys.stdout, out)
Пример #4
0
def create(cli):
    """
    Create A New user
    """
    url = build_url("user")
    user = {}
    user['email'] = raw_input('What is their email: ')
    user['name'] = raw_input('What is their full name?: ')
    auth = raw_input('How will they logon?  [google,github,password] (default = google): ')
    if auth == "google" or auth == "":
        pass
    if auth == "google":
        needsEmail = False
        if "email" not in user:
            needsEmail = True
        elif len(user["email"]) < 4:
            needsEmail = True
        if needsEmail:
            user['email'] =raw_input("To use google login requires google email: ")
    if auth == "password":
        user['password'] = raw_input('Password? ')
    if cli.args.preview:
        print("would have sent %s data=\n%s" % (url, user))
        return 
    log.debug(user)
    resp = httpapi.doapi(url, data=user, method="POST")
    httpiecolor.console_response(resp)
Пример #5
0
def create(cli):
    """
    Create A New account
    """
    data = {}
    data['fid'] = raw_input('What is the unique id for this account?: ')
    data['name'] = raw_input('What is the name of this account?: ')
    log.debug(data)
    resp = httpapi.doapi(build_url("account"), data=data, method="POST")
    httpiecolor.console_response(resp)
Пример #6
0
def create(cli):
    """
    Create A New account
    """
    data = {}
    data['fid'] = raw_input('What is the unique id for this account?: ')
    data['name'] = raw_input('What is the name of this account?: ')
    log.debug(data)
    resp = httpapi.doapi(build_url("account"), data=data, method="POST")
    httpiecolor.console_response(resp)
Пример #7
0
 def api(self):
     """call arbitrary api
     """
     if not self.valid():
         return
     url = self._arg(0)
     if len(url) < 1:
         log.error("Requires url arg:    lytics api account  [user,account,query,meta etc]")
         return
     url = build_url(url)
     log.debug(url)
     httpiecolor.console_response(httpapi.doapi(url))
Пример #8
0
    def sendjson(self,rawdata, method="GET"):
        """
        sends the data to collection servers via http
        """
        #log.debug("HERE %s" % rawdata)
        aid = self.args.aid 
        if len(aid) == 0:
            aid = self.args.key

        url = self.args.api +"/c/%s" % (aid)
        if len(self.args.stream) > 0:
            url = self.args.api +"/c/%s/%s" % (aid, self.args.stream)

        log.debug("URL1  method=%s  url==%s" % (method, url))
        if self.args.preview:
            print("would have sent %s data=\n%s" % (url, rawdata))
            return 
        if self.args.format == 'json':
            httpiecolor.console_response(httpapi.doapi(url, data=rawdata, method=method))
        else:
            httpiecolor.console_response(httpapi.doapi(url, data=rawdata, method=method))
Пример #9
0
 def api(self):
     """call arbitrary api
     """
     if not self.valid():
         return
     url = self._arg(0)
     if len(url) < 1:
         log.error("Requires url arg:    lytics api account  [user,account,query,meta etc]")
         return
     url = build_url(url)
     log.debug(url)
     resp = httpapi.doapi(url)
     print(resp.json)
Пример #10
0
    def sendjson(self, rawdata, method="GET"):
        """
        sends the data to collection servers via http
        """
        #log.debug("HERE %s" % rawdata)
        aid = self.args.aid
        if len(aid) == 0:
            aid = self.args.key

        url = self.args.api + "/c/%s" % (aid)
        if len(self.args.stream) > 0:
            url = self.args.api + "/c/%s/%s" % (aid, self.args.stream)

        log.debug("URL1  method=%s  url==%s" % (method, url))
        if self.args.preview:
            print("would have sent %s data=\n%s" % (url, rawdata))
            return
        if self.args.format == 'json':
            httpiecolor.console_response(
                httpapi.doapi(url, data=rawdata, method=method))
        else:
            httpiecolor.console_response(
                httpapi.doapi(url, data=rawdata, method=method))
Пример #11
0
 def api(self):
     """call arbitrary api
     """
     if not self.valid():
         return
     url = self._arg(0)
     if len(url) < 1:
         log.error(
             "Requires url arg:    lytics api account  [user,account,query,meta etc]"
         )
         return
     url = build_url(url)
     log.debug(url)
     httpiecolor.console_response(httpapi.doapi(url))