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 snsreq(event, context): """This is the entry point for the SNS chaim handler :param event: the AWS lambda event that triggered this :param context: the AWS lambda context for this """ log.info("context: {}".format(context)) ep = EnvParam() environment = ep.getParam("environment", True) apiid = ep.getParam("APIID", True) with open("version", "r") as vfn: version = vfn.read() body = event['Records'][0]['Sns']['Message'] rbody = chaim.begin(body, environment, "slack", apiid) verstr = "chaim-snsreq-" + environment + " " + version log.info(verstr + " entered.") log.debug("sns req: {}".format(rbody)) doSnsReq(rbody, context, verstr, ep, environment)
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: 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)
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_readKeyInit(): b = chaim.begin(testbody + testextra, **context) pms = Permissions(os.environ["SECRETPATH"], True) cp = CommandParse(b, pms.roleAliasDict()) xs = chaim.readKeyInit(cp.requestDict(), pms) assert xs[0:24] == "Chaim Credentials Expire"
def test_begin_fully(): tb = chaim.bodyParams(testbody) td = chaim.bodyParams(chaim.begin(testbody, **context)) assert ("useragent" not in tb) and (td["useragent"] == "chaimtest")
def test_begin(): b = chaim.begin(testbody, **context) assert b == contextbody