def identify(): """ the entry point to display the users identity from slack """ try: log.debug("identify entry") with open("version", "r") as vfn: version = vfn.read() config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") config["useragent"] = "slack" config["apiid"] = app.current_request.context["apiId"] log.debug("identify: config: {}".format(config)) params = chaim.paramsToDict(app.current_request.raw_body.decode()) # rbody = chaim.begin(app.current_request.raw_body.decode(), **config) op = "```\n" op += "Name: {}\n".format(params["user_name"]) op += "Slack Id: {}\n".format(params["user_id"]) op += "Workspace Id: {}\n".format(params["team_id"]) op += "```\n" # rbody = glue.addToReqBody(rbody, "identify", "true") # log.debug("publishing req body: {}".format(rbody)) # chaim.snsPublish(ep.getParam("SNSTOPIC"), rbody) verstr = "chaim-slack-" + config["environment"] + " " + version log.debug("identify: {}".format(op)) return chaim.output(None, "{}\n\n{}".format(verstr, op)) except Exception as e: msg = "An identify error occurred: {}: {}".format(type(e).__name__, e) log.error(msg) return chaim.output(msg)
def slackreq(): """ This is the entry point for Slack """ try: log.debug("slackreq entry") with open("version", "r") as vfn: version = vfn.read() config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") config["useragent"] = "slack" config["apiid"] = app.current_request.context["apiId"] rbody = chaim.begin(app.current_request.raw_body.decode(), **config) chaim.snsPublish(ep.getParam("SNSTOPIC"), rbody) verstr = "chaim-slack" if config["environment"] == "prod": verstr += " " + version else: verstr += "-" + config["environment"] + " " + version return chaim.output(None, "{}\n\nPlease wait".format(verstr)) except Exception as e: emsg = "slackreq: {}: {}".format(type(e).__name__, e) log.error(emsg) return chaim.output(emsg)
def startgui(): """ The entry point for the CLI to obtain a gui url """ try: config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") rbody = chaim.begin(app.current_request.raw_body.decode(), **config) with open("version", "r") as vfn: version = vfn.read() emsg, msg = doStartGui(rbody, app.lambda_context, config["environment"], version) return chaim.output(emsg, msg) except Exception as e: emsg = "cligui start: {}: {}".format(type(e).__name__, e) log.error(emsg) return chaim.output(emsg)
def keyinit(): """ the entry point to request a user key (from slack /initchaim) """ try: log.debug("keyinit entry") with open("version", "r") as vfn: version = vfn.read() config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") config["useragent"] = "slack" config["apiid"] = app.current_request.context["apiId"] rbody = chaim.begin(app.current_request.raw_body.decode(), **config) rbody = glue.addToReqBody(rbody, "keyinit", "true") chaim.snsPublish(ep.getParam("SNSTOPIC"), rbody) verstr = "chaim-slack-" + config["environment"] + " " + version return chaim.output(None, "{}\n\nPlease wait".format(verstr)) except Exception as e: msg = "A keyinit error occurred: {}: {}".format(type(e).__name__, e) log.error(msg) return chaim.output(msg)
def newchaimuser(): """ the entry point to create a new chaim user """ try: log.debug("newchaimuser entry") with open("version", "r") as vfn: version = vfn.read() config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") config["useragent"] = "slack" config["apiid"] = app.current_request.context["apiId"] log.debug("newchaimuser: config: {}".format(config)) # params = chaim.paramsToDict(app.current_request.raw_body.decode()) rbody = chaim.begin(app.current_request.raw_body.decode(), **config) rbody = glue.addToReqBody(rbody, "newchaimuser", "true") chaim.snsPublish(ep.getParam("SNSTOPIC"), rbody) verstr = "chaim-slack-" + config["environment"] + " " + version return chaim.output(None, "{}\n\nPlease wait".format(verstr)) except Exception as e: msg = "An identify error occurred: {}: {}".format(type(e).__name__, e) log.error(msg) return chaim.output(msg)
def test_output(): err = None out = "some message" att = "This is attached" title = None xd = chaim.output(err, out, att) ed = { 'response_type': 'ephemeral', 'statusCode': '200', 'text': 'some message' } ed["headers"] = {'Content-Type': 'application/json'} ed["attachments"] = [{ "title": title, "title_link": att, "mrkdwn_in": ["text", "pretext"] }] assert xd == ed
def keyinit(): """ the entry point to request a user key (from slack /initchaim) """ try: with open("version", "r") as vfn: version = vfn.read() config = {} ep = EnvParam() config["environment"] = ep.getParam("environment") config["useragent"] = "slack" config["apiid"] = app.current_request.context["apiId"] rbody = chaim.begin(app.current_request.raw_body.decode(), **config) rbody = glue.addToReqBody(rbody, "keyinit", "true") chaim.snsPublish(ep.getParam("SNSTOPIC"), rbody) verstr = "chaim-slack-" + config["environment"] + " " + version return chaim.output(None, "{}\n\nPlease wait".format(verstr)) # reqbody = app.current_request.raw_body.decode() # reqbody += "&stage=" # stage = app.current_request.context["stage"] # apiid = app.current_request.context["apiId"] # useragent = "slack" # if stage == "dev": # log.setLevel(logging.DEBUG) # reqbody += stage # reqbody += "&apiid={}&keyinit=true".format(apiid) # reqbody += "&useragent={}".format(useragent) # log.debug("keyinit starting: {}".format(reqbody)) # log.debug("sending to sns: {}".format(reqbody)) # epm = EnvParam() # snstopicarn = epm.getParam("SNSTOPIC", decode=True) # snsc = boto3.client('sns') # snsc.publish(TopicArn=snstopicarn, Message=reqbody) # extrav = "-{}".format(stage) if stage in ["beta", "dev"] else "" # return output(None, "{}\n\nPlease wait".format(verstr + extrav)) except Exception as e: msg = "A keyinit error occurred: {}: {}".format(type(e).__name__, e) log.error(msg) return output(msg)