def __get_api_token(config_path=None): if config_path is None: config_path = default_config_path() try: with open(config_path, 'rb') as C: return json.loads(C.read())['slack']['api_token'] except Exception as e: logging.error("Could not get API token from config: [%s, %s]" % (type(e), e)) return None
def init_slack(config, config_path=None): if config_path is None: config_path = default_config_path() from fabric.operations import prompt if 'slack' not in config.keys(): config['slack'] = {} for credential in ['api_token']: if credential not in config['slack'].keys(): config['slack'][credential] = prompt("Slack %s" % credential) try: with open(config_path, 'wb+') as C: C.write(json.dumps(config)) return True except Exception as e: logging.error("Could not save config: [%s, %s]" % (type(e), e)) return False