def test_005_check_boto_clients_are_available(self, mock_resource):
     self.app.config['BOTO3_SERVICES'] = ['s3', 'sqs']
     b = Boto3(self.app)
     with self.app.app_context():
         clients = b.clients
         assert len(clients) == len(self.app.config['BOTO3_SERVICES'])
         print(clients)
 def test_006_check_boto_resources_are_available(self, mock_resource):
     self.app.config['BOTO3_SERVICES'] = ['s3', 'sqs']
     b = Boto3(self.app)
     with self.app.app_context():
         resources = b.resources
         assert len(resources) == len(self.app.config['BOTO3_SERVICES'])
         print(resources)
 def test_001_populate_application_context(self, mock_resource):
     self.app.config['BOTO3_SERVICES'] = ['s3', 'sqs']
     b = Boto3(self.app)
     with self.app.app_context():
         assert isinstance(b.connections, dict)
         assert len(b.connections) == 2
         assert isinstance(stack.top.boto3_cns, dict)
         assert len(stack.top.boto3_cns) == 2
 def test_002_instantiate_connectors(self, mock_resource):
     self.app.config['BOTO3_SERVICES'] = ['s3', 'sqs', 'dynamodb']
     b = Boto3(self.app)
     with self.app.app_context():
         b.connections
         assert mock_resource.call_count == 3
         assert sorted([i[0][0] for i in mock_resource.call_args_list]) == \
                sorted(self.app.config['BOTO3_SERVICES'])
 def test_002_instantiate_connectors(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codebuild', 'codedeploy']
     b = Boto3(self.app)
     with self.app.app_context():
         b.connections
         assert mock_client.call_count == 2
         assert sorted([i[0][0] for i in mock_client.call_args_list]) == \
                sorted(self.app.config['BOTO3_SERVICES'])
 def test_001_populate_application_context(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codebuild', 'codedeploy']
     b = Boto3(self.app)
     with self.app.app_context():
         assert isinstance(b.connections, dict)
         assert len(b.connections) == 2
         assert isinstance(stack.top.boto3_cns, dict)
         assert len(stack.top.boto3_cns) == 2
 def test_003_pass_credentials_through_app_conf(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codepipeline']
     self.app.config['BOTO3_ACCESS_KEY'] = 'access'
     self.app.config['BOTO3_SECRET_KEY'] = 'secret'
     self.app.config['BOTO3_PROFILE'] = 'default'
     b = Boto3(self.app)
     with self.app.app_context():
         b.connections
         mock_client.assert_called_once_with('codepipeline',
                                             aws_access_key_id='access',
                                             aws_secret_access_key='secret',
                                             region_name='eu-west-1')
 def test_004_pass_optional_params_through_conf(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codepipeline']
     self.app.config['BOTO3_ACCESS_KEY'] = 'access'
     self.app.config['BOTO3_SECRET_KEY'] = 'secret'
     self.app.config['BOTO3_PROFILE'] = 'default'
     self.app.config['BOTO3_OPTIONAL_PARAMS'] = {
         'codepipeline': {
             'args': ('eu-west-1'),
             'kwargs': {
                 'fake_param': 'fake_value'
             }
         }
     }
     b = Boto3(self.app)
     with self.app.app_context():
         b.connections
         mock_client.assert_called_once_with('codepipeline',
                                             'eu-west-1',
                                             aws_access_key_id='access',
                                             aws_secret_access_key='secret',
                                             fake_param='fake_value')
示例#9
0
文件: models.py 项目: NextFloor/paste
import botocore
import random
import uuid

from datetime import datetime, timedelta
from passlib.hash import argon2
from pygments.lexers import guess_lexer
from sqlalchemy.sql import exists

from flask import abort
from flask import current_app as app
from flask_boto3 import Boto3
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
boto3 = Boto3()


class Paste(db.Model):
    __tablename__ = 'paste'
    slug = db.Column(db.String(4), primary_key=True)
    source = db.Column(db.Text, nullable=False)
    lexer = db.Column(db.String(32), nullable=False)
    title = db.Column(db.String(64))
    password = db.Column(db.String(128))
    is_resource = db.Column(db.Boolean, default=False)
    view_count = db.Column(db.Integer, nullable=False, default=0)
    created_at = db.Column(db.DateTime, default=datetime.now)
    expire_at = db.Column(db.DateTime)

    def __init__(self, source, highlight, expiration, title, password,
示例#10
0
 def test_006_check_boto_resources_are_available(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codedeploy', 'codebuild']
     b = Boto3(self.app)
     with self.app.app_context():
         resources = b.resources
         assert len(resources) == len(self.app.config['BOTO3_SERVICES'])
示例#11
0
 def test_005_check_boto_clients_are_available(self, mock_client):
     self.app.config['BOTO3_SERVICES'] = ['codedeploy', 'codebuild']
     b = Boto3(self.app)
     with self.app.app_context():
         clients = b.clients
         assert len(clients) == len(self.app.config['BOTO3_SERVICES'])
示例#12
0
from flask import Flask, jsonify

from flask_boto3 import Boto3


class Config:
    DEBUG = True
    BOTO3_SERVICES = ['S3', 's3']


app = Flask(__name__)
app.config.from_object(Config)
boto_flask = Boto3(app)


@app.route("/connections")
def connections():
    return jsonify({k: str(v) for k, v in boto_flask.connections.items()})


@app.route("/clients")
def clients():
    return jsonify({k: str(v) for k, v in boto_flask.clients.items()})


@app.route("/resources")
def resources():
    return jsonify({k: str(v) for k, v in boto_flask.resources.items()})


@app.route("/buckets")
示例#13
0
from flask import Blueprint
from flask_boto3 import Boto3

home = Blueprint(
    'home',
    __name__,
    template_folder='templates',
    static_folder='static'
)

boto = Boto3()


@home.record_once
def on_load(state):
    boto.init_app(state.app)

from . import views  # noqa
示例#14
0
from flask_boto3 import Boto3
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_restplus import Api
from flask_sqlalchemy import SQLAlchemy

from config import DefaultConfig
from app.base_space import BaseSpace
from app.seven_bridges import SevenBridges

DB = SQLAlchemy()
MIGRATE = Migrate()

API = Api()
BASESPACE = BaseSpace()
BOTO3 = Boto3()
LOGINMANAGER = LoginManager()
SEVENBRIDGES = SevenBridges()


def mask(exposed_str):
    ''' Mask a string '''
    if exposed_str:
        masked_str = '*' * (len(exposed_str) - 5)
        masked_str += exposed_str[-5:]
        return masked_str
    return exposed_str


def create_app(config_class=DefaultConfig):
    '''