Exemplo n.º 1
0
def git_commit(working_directory, message):
    try:
        user_email = read_configuration('GIT_USER_EMAIL',
                                        '/var/secrets/autobump', None)
        if not user_email:
            return
        subprocess.call(['git', 'config', 'user.email', user_email],
                        cwd=working_directory)

        user_name = read_configuration('GIT_USER_NAME',
                                       '/var/secrets/autobump', None)
        if not user_name:
            return
        subprocess.call(['git', 'config', 'user.name', user_name],
                        cwd=working_directory)

        subprocess.call(['git', 'add', '.'], cwd=working_directory)
        subprocess.call([
            'git', 'commit', '-m',
            '%s\n\nVersion bumped using https://github.com/rycus86/autobump' %
            message
        ],
                        cwd=working_directory)

        return True
    except subprocess.CalledProcessError as ex:
        print('Failed to commit the change in',
              working_directory,
              ':',
              ex,
              file=sys.stderr)
Exemplo n.º 2
0
def read_configuration(key, path, default=None):
    value = docker_helper.read_configuration(key, path)

    if value or path == default_config_path:
        return value or default

    return docker_helper.read_configuration(key,
                                            default_config_path,
                                            default=default)
Exemplo n.º 3
0
def send_message(message):
    webhook_url = read_configuration('SLACK_WEBHOOK', '/var/secrets/autobump', None)
    if not webhook_url:
        return

    icon_url = read_configuration('SLACK_ICON', '/var/secrets/autobump', None)

    requests.post(
        webhook_url,
        json=dict(channel='monitoring', text=message, username='******', icon_url=icon_url)
    )
Exemplo n.º 4
0
def git_push(working_directory, owner, branch_name):
    try:
        subprocess.call(
            ['git', 'config', 'credential.https://github.com.username', owner],
            cwd=working_directory)

        push_env = os.environ.copy()
        push_env['GIT_ASKPASS'] = os.path.normpath(
            os.path.join(os.path.dirname(__file__), '../util/git_askpass.sh'))
        push_env['GIT_PASSWORD'] = read_configuration('GIT_USER_PASSWORD',
                                                      '/var/secrets/autobump',
                                                      None)

        subprocess.call(['git', 'push', '-u', 'origin', branch_name],
                        cwd=working_directory,
                        env=push_env)

        return True
    except subprocess.CalledProcessError as ex:
        print('Failed to push to origin /',
              branch_name,
              'from',
              working_directory,
              ':',
              ex,
              file=sys.stderr)
Exemplo n.º 5
0
def check_auth_header():
    if request.path.startswith('/metrics'):
        return

    auth_key = read_configuration('AUTH_TOKEN', '/var/secrets/autobump', None)
    if not auth_key:
        return

    if request.headers.get('Webhook-Auth-Token') != auth_key:
        return abort(
            Response('Missing or invalid Webhook-Auth-Token header\n',
                     status=401))
Exemplo n.º 6
0
import os
import signal
import logging

from flask import Flask, g, request, redirect, render_template, flash
from flask_httpauth import HTTPBasicAuth
from prometheus_flask_exporter import PrometheusMetrics
from docker_helper import read_configuration

from config import configure, add_rule, delete_rule

app = Flask(__name__)
app.config['SECRET_KEY'] = read_configuration('SECRET_KEY',
                                              '/var/secrets/flask', 'InSecure')

auth = HTTPBasicAuth()
metrics = PrometheusMetrics(app)

metrics.info('flask_app_info',
             'Application info',
             version=os.environ.get('GIT_COMMIT') or 'unknown')

metrics.info('flask_app_built_at', 'Application build timestamp').set(
    float(os.environ.get('BUILD_TIMESTAMP') or '0'))

logging.basicConfig(
    format='%(asctime)s [%(levelname)s] %(module)s.%(funcName)s - %(message)s')
logger = logging.getLogger('redirect-service')
logger.setLevel(logging.INFO)

_rules = {'simple': {}, 'regex': [], 'admin': None}
Exemplo n.º 7
0
from __future__ import print_function

import json
import time
import sqlite3
import threading
import traceback

import requests

import docker_helper


_database_path = docker_helper.read_configuration(
    'REPLAY_DATABASE', '/var/config/webhooks/replay', 'webhooks-replay.db'
)

_schedule_condition = threading.Condition()
_shutdown = [False]


def initialize():
    _initialize_schema()

    thread = threading.Thread(target=_schedule)
    thread.setDaemon(True)
    thread.start()


def shutdown():
    _shutdown[:] = [True]
Exemplo n.º 8
0
from scraper import Scraper

app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
metrics = PrometheusMetrics(app)

metrics.info('flask_app_info',
             'Application info',
             version=os.environ.get('GIT_COMMIT') or 'unknown')

metrics.info('flask_app_built_at', 'Application build timestamp').set(
    float(os.environ.get('BUILD_TIMESTAMP') or '0'))

CORS(app,
     origins=read_configuration('CORS_ORIGINS',
                                '/var/secrets/secrets.env',
                                default='http://localhost:?.*').split(','),
     methods='GET')

logging.basicConfig(
    format='%(asctime)s [%(levelname)s] %(module)s.%(funcName)s - %(message)s')
logger = logging.getLogger('googleplay-proxy')
logger.setLevel(logging.INFO)

_api_type = read_configuration('API_TYPE',
                               '/var/secrets/secrets.env',
                               default='api')

if _api_type == 'api':
    api = ApiClient(android_id=read_configuration('ANDROID_ID',
                                                  '/var/secrets/secrets.env'),
Exemplo n.º 9
0
from api import DockerHub

app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
metrics = PrometheusMetrics(app)

metrics.info('flask_app_info',
             'Application info',
             version=os.environ.get('GIT_COMMIT') or 'unknown')

metrics.info('flask_app_built_at', 'Application build timestamp').set(
    float(os.environ.get('BUILD_TIMESTAMP') or '0'))

CORS(app,
     origins=read_configuration('CORS_ORIGINS',
                                '/var/secrets/secrets.env',
                                default='http://localhost:?.*').split(','),
     methods='GET')

api = DockerHub(username=read_configuration('DOCKERHUB_USERNAME',
                                            '/var/secrets/secrets.env'),
                password=read_configuration('DOCKERHUB_PASSWORD',
                                            '/var/secrets/secrets.env'),
                token=read_configuration('DOCKERHUB_TOKEN',
                                         '/var/secrets/secrets.env'))

logging.basicConfig(
    format='%(asctime)s [%(levelname)s] %(module)s.%(funcName)s - %(message)s')
logger = logging.getLogger('docker-proxy')
logger.setLevel(logging.INFO)
Exemplo n.º 10
0
def is_dry_run(key):
    if read_configuration('DRY_RUN', '/var/secrets/autobump', None):
        return True

    if read_configuration('DRY_RUN_%s' % key, '/var/secrets/autobump', None):
        return True
Exemplo n.º 11
0
from __future__ import print_function

import json
import sqlite3
import threading
import time
import traceback

import docker_helper
import requests

_database_path = docker_helper.read_configuration(
    "REPLAY_DATABASE", "/var/config/webhooks/replay", "webhooks-replay.db"
)

_schedule_condition = threading.Condition()
_shutdown = [False]


def initialize():
    _initialize_schema()

    thread = threading.Thread(target=_schedule)
    thread.setDaemon(True)
    thread.start()


def shutdown():
    _shutdown[:] = [True]

    with _schedule_condition: