コード例 #1
0
    def __init__(self):
        self.dynamodb = boto3.resource('dynamodb', region_name="us-east-1")

        secrets_manager = SecretsManager()
        db_credentials = secrets_manager.get_value(SECRET_NAME_DATABASE)
        table_name = db_credentials.get(SECRET_STRING_DATABASE_NAME)

        self.table = self.dynamodb.Table(table_name)
コード例 #2
0
    def connect(self):
        try:
            secrets_manager = SecretsManager()
            db_credentials = secrets_manager.get_value(SECRET_NAME_DATABASE)
            host = db_credentials.get(SECRET_STRING_DATABASE_HOST)
            name = db_credentials.get(SECRET_STRING_DATABASE_NAME)
            username = db_credentials.get(SECRET_STRING_DATABASE_USERNAME)
            password = db_credentials.get(SECRET_STRING_DATABASE_PASSWORD)

            self.connection = psycopg2.connect(
                f'host={host} dbname={name} user={username} password={password}'
            )
            self.cursor = self.connection.cursor(
                cursor_factory=psycopg2.extras.DictCursor)
        except (Exception, Error) as error:
            print('Error while connecting to PostgreSQL', error)
            self.connection = None
            self.cursor = None
コード例 #3
0
    def test_get_value(self):
        conn = boto3.client("secretsmanager", region_name="us-east-2")

        conn.create_secret(Name="secret-name",
                           SecretString='{"key": "secret-password"}')

        secrets_manager = SecretsManager()
        secret = secrets_manager.get_value('secret-name')

        assert secret.get('key') == 'secret-password'

        secrets_manager = SecretsManager()
        secret = secrets_manager.get_value('non-exist')

        assert secret is None
コード例 #4
0
import json
import ssl
import urllib
from functools import wraps
from urllib.request import urlopen

from jose import jwt
from flask import request

from app.utils.secrets_manager import SecretsManager, SECRET_NAME_AUTH0, SECRET_STRING_AUTH0_CLIENT_ID, \
    SECRET_STRING_AUTH0_CLIENT_SECRET, SECRET_STRING_AUTH0_API_BASE_URL

ALGORITHMS = ["RS256"]

secrets_manager = SecretsManager()
auth0_secrets = secrets_manager.get_value(SECRET_NAME_AUTH0)
auth_client_id = auth0_secrets.get(SECRET_STRING_AUTH0_CLIENT_ID)
auth_client_secret = auth0_secrets.get(SECRET_STRING_AUTH0_CLIENT_SECRET)
auth_client_api_base_url = auth0_secrets.get(SECRET_STRING_AUTH0_API_BASE_URL)


# Error handler
class AuthError(Exception):
    def __init__(self, error, status_code):
        self.error = error
        self.status_code = status_code


def get_authorization_header():
    return request.headers.get("Authorization", None)
コード例 #5
0
from flask import Flask
from flask_restful import Api
from flask_cors import CORS
from app.views.robot_view import RobotView
from app.utils.secrets_manager import SECRET_STRING_FLASK_SECRET_KEY, SecretsManager, SECRET_NAME_FLASK

secrets_manager = SecretsManager()
flask_secrets = secrets_manager.get_value(SECRET_NAME_FLASK)

# Setup Flask application
app = Flask(__name__)
app.secret_key = flask_secrets.get(SECRET_STRING_FLASK_SECRET_KEY)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
api = Api(app)

SUCCESS_RESPONSE_TEMPLATE = {'success': True}
FAILURE_RESPONSE_TEMPLATE = {'success': False}


@app.route('/')
def index():
    return {'healthy': True}


@app.route('/test')
def test():
    return {'healthy': True}


# [GET] Place the robot on the board
@app.route('/place')