def get_filename(*args): output_directory = conf.get("samples", "output_directory") if not os.path.isabs(output_directory): output_directory = os.path.join(os.getcwd(), output_directory) path = os.path.join(output_directory, *args) ensure_path_exists(path) return path
def listen(host, port, debug, webhook_url, only, exclude): """ricloud API event notification listener. Sets up a small Flask-based server listening on HOST (default: 0.0.0.0) and PORT (default: 8080). It is likely that you are using something like ngrok to expose the endpoint to the API. If that's the case, pass in the forwarding URL using the --webhook-url option. This will automatically setup a webhook config on the API and set it as active for your key (assuming it is valid). In most cases, you will likely set up a utility like ngrok to expose this endpoint to the internet. The default handler simply echos received event data to stdout. """ from ricloud import conf webhook_secret = conf.get("webhooks", "secret") webhook_delta = conf.getint("webhooks", "delta") if webhook_url: key = ricloud.Key.current() url = utils.join_url(webhook_url, "webhooks") webhook_config = ricloud.WebhookConfig.create(url=url) if key.webhook_config != webhook_config.id: key.update(webhook_config=webhook_config) message = "Using webhook config with ID {}".format(webhook_config.id) click.secho(message, fg="yellow") webhook_secret = webhook_config.secret from ricloud.webhooks import app app.config["WEBHOOK_SECRET"] = webhook_secret app.config["WEBHOOK_DELTA"] = webhook_delta app.config["EVENTS_ONLY"] = only app.config["EVENTS_EXCLUDE"] = exclude try: app.run(host=host, port=port, debug=debug) except KeyboardInterrupt: webhook_config.delete()
from __future__ import absolute_import __version__ = "3.2.0" from ricloud import conf token = conf.get("api", "token") url = conf.get("api", "url") from ricloud.resources import * # NOQA # Set default logging handler to avoid "No handler found" warnings. import logging # NOQA from logging import NullHandler # NOQA logging.getLogger(__name__).addHandler(NullHandler())
from __future__ import absolute_import, print_function from flask import Flask, request, abort from ricloud import conf from ricloud.signing import Signature from ricloud.utils import decode_json, encode_json app = Flask(__name__) RICLOUD_EVENTS_SECRET = conf.get("webhooks", "secret") RICLOUD_EVENTS_DELTA = conf.getint("webhooks", "delta") @app.route("/webhooks/<uuid:event_id>", methods=["post"]) def webhooks(event_id): if not request.json: abort(400) webhook_secret = app.config.get("WEBHOOK_SECRET", RICLOUD_EVENTS_SECRET) if webhook_secret and not verify_request(request, webhook_secret): abort(400) data = decode_json(request.json) only = app.config.get("EVENTS_ONLY") exclude = app.config.get("EVENTS_EXCLUDE") try: handle_event(data, only=only, exclude=exclude)
import uuid import base64 import decimal import hashlib import logging import datetime from collections import OrderedDict import ricloud from ricloud import compat from ricloud import conf logger = logging.getLogger("ricloud") log_level = logging.getLevelName(conf.get("logging", "log_level")) logger.setLevel(log_level) def log_debug(message, *args, **kwargs): logger.debug(message, *args, **kwargs) def log_info(message, *args, **kwargs): logger.info(message, *args, **kwargs) def generate_timestamp(): return int(time.time())
def __init__(self): self.session = requests.Session() self.max_retries = conf.getint("api", "max_retries") self.await_for = conf.get("api", "await_for")