Пример #1
0
class Config:

    JSONSCHEMA_DIR = os.path.join(basedir, 'api_server', 'api', 'schemas')
    AWS_S3_BUCKET = get_secret('AWS_S3_BUCKET') or 'nysa-api-server'
    AWS_SQS_NOTIFICATION_QUEUE = get_secret(
        'NYSA_SCHEDULER_SQS_QUEUE') or 'nysa-scheduler-queue'
    SLACK_NOTIFICATIONS_WEBHOOK_URL = get_secret(
        'SLACK_NOTIFICATIONS_WEBHOOK_URL')

    #disable SSL
    SSl_DISABLE = True

    @staticmethod
    def init_app(app):
        pass
Пример #2
0
 def _get_secret(self):
     """
     This method is to get secret value from Secrets Manager
     """
     secret = json.loads(secret_manager.get_secret())
     self.github_personal_access_token = secret[
         "github_personal_access_token"]
 def get_secret(self):
     """
     This method is to get secret value from Secrets Manager
     """
     secret = json.loads(secret_manager.get_secret())
     self.github_user = secret["github_user"]
     self.github_oauth_token = secret["github_oauth_token"]
Пример #4
0
 def _get_secret(self):
     """
     This method is to get secret value from Secrets Manager
     """
     secret = json.loads(secret_manager.get_secret())
     self.github_user = secret["github_user"]
     self.github_oauth_token = secret["github_oauth_token"]
     self.webhook_secret = secret["webhook_secret"]
     self.bot_user = secret["bot_user"]
     self.bot_oauth_token = secret["bot_oauth_token"]
     self.prediction_url = secret["prediction_url"]
Пример #5
0
 def _get_secret(self):
     """
     This method is to get secret value from Secrets Manager
     """
     secret = json.loads(secret_manager.get_secret())
     self.github_user = secret["github_user"]
     self.github_personal_access_token = secret["github_personal_access_token"]
     self.webhook_secret = secret["webhook_secret"]
     self.bot_user = secret["bot_user"]
     self.bot_personal_access_token = secret["bot_personal_access_token"]
     self.jenkins_username = secret["jenkins_username"]
     self.jenkins_password = secret["jenkins_password"]
Пример #6
0
 def _get_secret(self):
     """
     This method is to get secret value from Secrets Manager
     """
     secret = json.loads(secret_manager.get_secret())
     self.webhook_secret = secret["webhook_secret"]
Пример #7
0
import rollbar
import sys
import boto3
from message_handlers import MessageScheduler
from secret_manager import get_secret
sqs = boto3.resource('sqs')
queue = sqs.get_queue_by_name(QueueName=get_secret('NYSA_SCHEDULER_SQS_QUEUE') or 'nysa-scheduler-queue')
rollbar.init(get_secret('ROLLBAR_KEY'))


while 1:
    try:
        messages = queue.receive_messages(WaitTimeSeconds=20)
        for message in messages:
            MessageScheduler(message).execute()

    except:
        rollbar.report_exc_info(sys.exc_info())
Пример #8
0
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from secret_manager import get_secret

POSTGRES_CONNECT_URL = 'postgresql://{user}:{password}@{host}:{port}/{database}'

# connect with backend
engine = create_engine(
    POSTGRES_CONNECT_URL.format(
        user=get_secret('asapgo-database').get('USER'),
        password=get_secret('asapgo-database').get('PASSWORD'),
        host=get_secret('asapgo-database').get('HOST'),
        port=get_secret('asapgo-database').get('PORT'),
        database=get_secret('asapgo-database').get('DATABASE'),
    )
)

# set automap
metadata = MetaData()
metadata.reflect(engine)

Base = automap_base(metadata=metadata)
Base.prepare(engine)

# tables
plan_place = Base.classes.plan_place

# sessions
session = Session(engine)
Пример #9
0
import json
import traceback

from tqdm import tqdm

from models.crawler import ChromeDriver
from secret_manager import get_secret

USERNAME = get_secret('instagram').get('USERNAME')
PASSWORD = get_secret('instagram').get('PASSWORD')

driver = ChromeDriver()
driver.login_insta(USERNAME, PASSWORD)
areas = driver.get_location_areas()
areas = [area for area in areas if area.name == "Seoul"]
fail_area = []
fail_location = []
for area in tqdm(areas):
    results = []
    locations = driver.get_locations(area)
    if locations is None:
        fail_area.append(area)
    for i, location in enumerate(tqdm(locations)):
        try:
            results.append(driver.get_location_detail(location))
        except:
            traceback.print_exc()
            fail_location.append(location.name)
        if i % 100 == 0 and i != 0:
            with open(f'result/{area.name}{i // 100}', 'w') as f:
                f.write(json.dumps(results))
Пример #10
0
 def _get_job_trigger_token(self, name):
     secret = json.loads(secret_manager.get_secret())
     return secret[name.replace('-', '_') + '_token']
Пример #11
0
def get_secret():
    """
    This method is to get secret value from Secrets Manager
    """
    secret = json.loads(secret_manager.get_secret())
    return secret
Пример #12
0
def handle_ecs_bot_cmd(command_param, cluster_param, service_list_param):

    result = {}
    base_url = get_secret(u'NYSA_API_BASEURL')

    if command_param == "deploy" and cluster_param is not None and service_list_param is not None:

        if len(service_list_param
               ) == 1 and service_list_param[0]["service"].lower() != "all":
            url = "{}/v1/clusters/{}/services/{}/tags".format(
                base_url, cluster_param, service_list_param[0]["service"])
            rs = requests.get(url)
            if rs.status_code != 200:
                result["text"] = rs.json.get('message')
                return result

            tags = rs.json().get(u'content')
            if service_list_param[0]["tag"] is None:
                result[
                    "text"] = "Sure...this is a list of the tags available for deploy"
                result["attachments"] = [{
                    "text":
                    "{}:{} created:{}".format(
                        service_list_param[0]["service"], img[u'tag'],
                        timeago.format(parser.parse(img[u'pushed_at']),
                                       datetime.now(pytz.utc)))
                } for img in tags[:10] if img.get(u'tag') is not None]
            else:
                found = next((img for img in tags
                              if img[u'tag'] == service_list_param[0]["tag"]),
                             None)
                if not found:
                    result["text"] = "Tag not found..."
                else:
                    data = {"image_tag": service_list_param[0]["tag"]}
                    url = "{}/v1/clusters/{}/services/{}".format(
                        base_url, cluster_param,
                        service_list_param[0]["service"])
                    rs = requests.put(url, json=data)
                    if rs.status_code == 202:
                        result["text"] = rs.json().get('message')
                        return result
        else:
            url = "{}/v1/clusters/{}/config".format(base_url, cluster_param)
            rs = requests.get(url)
            if rs.status_code == 200:
                cluster_config = rs.json()

                if service_list_param[0]["service"] != "all":
                    for service in service_list_param:
                        svc = next((x for x in cluster_config.get('services')
                                    if x.keys()[0] == service["service"]),
                                   None)
                        if svc is not None:
                            svc = svc[svc.keys()[0]]
                            if service["tag"]:
                                svc[u'image'] = "{}:{}".format(
                                    svc[u'image'].rsplit(u':', 1)[0],
                                    service["tag"])

                if service_list_param[0]["service"] == "all":
                    for svc in cluster_config.get('services'):
                        svc = svc[svc.keys()[0]]
                        if service_list_param[0]["tag"]:
                            svc[u'image'] = "{}:{}".format(
                                svc[u'image'].rsplit(u':', 1)[0],
                                service_list_param[0]["tag"])

                url = "{}/v1/clusters/{}/config".format(
                    base_url, cluster_param)
                rs = requests.put(url, json=cluster_config)
                if rs.status_code == 202:
                    result["text"] = rs.json().get('message')
                    return result

    return result