Esempio n. 1
0
 def init_class(cls, job_supervisor_module):
     global job_supervisor
     job_supervisor = job_supervisor_module
     cls.cfg = pkconfig.init(
         agent_log_read_sleep=(
             5,
             int,
             'how long to wait before reading the agent log on start',
         ),
         agent_starting_secs=(
             cls._AGENT_STARTING_SECS_DEFAULT * 3,
             int,
             'how long to wait for agent start',
         ),
         cores=(None, int, 'dev cores config'),
         host=pkconfig.Required(str, 'host name for slum controller'),
         host_key=pkconfig.Required(str, 'host key'),
         run_slots=(1, int, 'number of concurrent OP_RUN for each user'),
         shifter_image=(None, str, 'needed if using Shifter'),
         sirepo_cmd=pkconfig.Required(str, 'how to run sirepo'),
         srdb_root=pkconfig.Required(
             _cfg_srdb_root,
             'where to run job_agent, must include {sbatch_user}'),
         supervisor_uri=job.DEFAULT_SUPERVISOR_URI_DECL,
     )
     cls._KNOWN_HOSTS = (
         cls.cfg.host_key if cls.cfg.host in cls.cfg.host_key else
         '{} {}'.format(cls.cfg.host, cls.cfg.host_key)).encode('ascii')
     return cls
Esempio n. 2
0
def init_apis(*args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        uid=pkconfig.Required(_cfg_uid,
                              'single user allowed to login with basic auth'),
        password=pkconfig.Required(str, 'password for uid'),
    )
Esempio n. 3
0
def start():
    #TODO(robnagler) commands need their own init hook like the server has
    job.init()
    global cfg

    cfg = pkconfig.init(
        agent_id=pkconfig.Required(str, 'id of this agent'),
        fastcgi_sock_dir=(
            pkio.py_path('/tmp'), pkio.py_path,
            'directory of fastcfgi socket, must be less than 50 chars'),
        start_delay=(0, pkconfig.parse_seconds,
                     'delay startup in internal_test mode'),
        supervisor_uri=pkconfig.Required(
            str,
            'how to connect to the supervisor',
        ),
    )
    pkdlog('{}', cfg)
    if pkconfig.channel_in_internal_test() and cfg.start_delay:
        pkdlog('start_delay={}', cfg.start_delay)
        time.sleep(cfg.start_delay)
    i = tornado.ioloop.IOLoop.current()
    d = _Dispatcher()

    def s(*args):
        return i.add_callback_from_signal(_terminate, d)

    signal.signal(signal.SIGTERM, s)
    signal.signal(signal.SIGINT, s)
    i.spawn_callback(d.loop)
    i.start()
Esempio n. 4
0
def init_apis(*args, **kwargs):
    def _init_model(base):
        """Creates User class bound to dynamic `db` variable"""
        global AuthGithubUser, UserModel

        class AuthGithubUser(base):
            __tablename__ = 'auth_github_user_t'
            oauth_id = sqlalchemy.Column(base.STRING_NAME, primary_key=True)
            user_name = sqlalchemy.Column(base.STRING_NAME,
                                          unique=True,
                                          nullable=False)
            uid = sqlalchemy.Column(base.STRING_ID, unique=True)

        UserModel = AuthGithubUser

    global cfg, AUTH_METHOD_VISIBLE
    cfg = pkconfig.init(
        callback_uri=(
            None, str,
            'Github callback URI (defaults to api_authGithubAuthorized)'),
        key=pkconfig.Required(str, 'Github key'),
        method_visible=(
            True,
            bool,
            'github auth method is visible to users when it is an enabled method',
        ),
        secret=pkconfig.Required(str, 'Github secret'),
    )
    AUTH_METHOD_VISIBLE = cfg.method_visible
    auth_db.init_model(_init_model)
Esempio n. 5
0
def init_apis(app, *args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        key=pkconfig.Required(str, 'Github key'),
        secret=pkconfig.Required(str, 'Github secret'),
        callback_uri=(None, str, 'Github callback URI (defaults to api_authGithubAuthorized)'),
    )
    app.session_interface = _FlaskSessionInterface()
    auth_db.init_model(app, _init_model)
Esempio n. 6
0
def init_apis(*args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        key=pkconfig.Required(str, 'Github key'),
        secret=pkconfig.Required(str, 'Github secret'),
        callback_uri=(
            None, str,
            'Github callback URI (defaults to api_authGithubAuthorized)'),
    )
    auth_db.init_model(_init_model)
Esempio n. 7
0
def init_apis(*args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        #TODO(robnagler) validate email
        from_email=pkconfig.Required(str, 'From email address'),
        from_name=pkconfig.Required(str, 'From display name'),
        smtp_password=pkconfig.Required(str, 'SMTP auth password'),
        smtp_server=pkconfig.Required(str, 'SMTP TLS server'),
        smtp_user=pkconfig.Required(str, 'SMTP auth user'),
    )
    auth_db.init_model(_init_model)
Esempio n. 8
0
def init_apis(*args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        secret=pkconfig.Required(
            str,
            'Shared secret between Sirepo and BlueSky server',
        ),
    )
Esempio n. 9
0
def init_class():
    global cfg, _KNOWN_HOSTS

    cfg = pkconfig.init(
        cores=(None, int, 'dev cores config'),
        host=pkconfig.Required(str, 'host name for slum controller'),
        host_key=pkconfig.Required(str, 'host key'),
        shifter_image=(None, str, 'needed if using Shifter'),
        sirepo_cmd=pkconfig.Required(str, 'how to run sirepo'),
        srdb_root=pkconfig.Required(
            _cfg_srdb_root,
            'where to run job_agent, must include {sbatch_user}'),
        supervisor_uri=job.DEFAULT_SUPERVISOR_URI_DECL,
    )
    _KNOWN_HOSTS = (cfg.host_key if cfg.host in cfg.host_key else
                    '{} {}'.format(cfg.host, cfg.host_key)).encode('ascii')
    return SbatchDriver.init_class()
Esempio n. 10
0
def start():
#TODO(robnagler) commands need their own init hook like the server has
    job.init()
    global cfg

    cfg = pkconfig.init(
        agent_id=pkconfig.Required(str, 'id of this agent'),
        supervisor_uri=pkconfig.Required(
            str,
            'how to connect to the supervisor',
        ),
    )
    pkdlog('{}', cfg)
    i = tornado.ioloop.IOLoop.current()
    d = _Dispatcher()
    def s(*args):
        return i.add_callback_from_signal(_terminate, d)
    signal.signal(signal.SIGTERM, s)
    signal.signal(signal.SIGINT, s)
    i.spawn_callback(d.loop)
    i.start()
Esempio n. 11
0
def init_apis(*args, **kwargs):

    def _init_model(base):
        """Creates User class bound to dynamic `db` variable"""
        global AuthGithubUser, UserModel

        class AuthGithubUser(base):
            __tablename__ = 'auth_github_user_t'
            oauth_id = sqlalchemy.Column(sqlalchemy.String(100), primary_key=True)
            user_name = sqlalchemy.Column(sqlalchemy.String(100), unique=True, nullable=False)
            uid = sqlalchemy.Column(sqlalchemy.String(8), unique=True)

        UserModel = AuthGithubUser

    global cfg
    cfg = pkconfig.init(
        key=pkconfig.Required(str, 'Github key'),
        secret=pkconfig.Required(str, 'Github secret'),
        callback_uri=(None, str, 'Github callback URI (defaults to api_authGithubAuthorized)'),
    )
    auth_db.init_model(_init_model)
Esempio n. 12
0
def init_apis(app, *args, **kwargs):
    global cfg
    cfg = pkconfig.init(
        #TODO(robnagler) validate email
        from_email=pkconfig.Required(str, 'From email address'),
        from_name=pkconfig.Required(str, 'From display name'),
        smtp_password=pkconfig.Required(str, 'SMTP auth password'),
        smtp_server=pkconfig.Required(str, 'SMTP TLS server'),
        smtp_user=pkconfig.Required(str, 'SMTP auth user'),
    )
    auth_db.init_model(app, _init_model)
    if pkconfig.channel_in('dev') and cfg.smtp_server == _DEV_SMTP_SERVER:
        return
    app.config.update(
        MAIL_USE_TLS=True,
        MAIL_PORT=587,
        MAIL_SERVER=cfg.smtp_server,
        MAIL_USERNAME=cfg.smtp_user,
        MAIL_PASSWORD=cfg.smtp_password,
    )
    global _smtp
    _smtp = flask_mail.Mail(app)
Esempio n. 13
0
        util.raise_unauthorized(
            '{}: hash mismatch expected={} nonce={}',
            req.authHash,
            res,
            req.authNonce,
        )
    t = req.authNonce.split(_AUTH_NONCE_SEPARATOR)[0]
    try:
        t = int(t)
    except ValueError as e:
        util.raise_unauthorized(
            '{}: auth_nonce prefix not an int: nonce={}',
            t,
            req.authNonce,
        )
    delta = now - t
    if abs(delta) > _AUTH_NONCE_REPLAY_SECS:
        util.raise_unauthorized(
            '{}: auth_nonce time outside replay window={} now={} nonce={}',
            t,
            _AUTH_NONCE_REPLAY_SECS,
            now,
            req.authNonce,
        )


cfg = pkconfig.init(secret=pkconfig.Required(
    str,
    'Shared secret between Sirepo and BlueSky server',
), )
Esempio n. 14
0
def init_apis(*args, **kwargs):
    global cfg
    cfg = pkconfig.init(mail_recipient_email=pkconfig.Required(
        str, 'Email to receive registration messages'), )
Esempio n. 15
0
    if v is None:
        return 999
    return int(v)


cfg = pkconfig.init(
    dict1=({
        'd1': 'default1',
        'd2': 'default2',
    }, dict, 'first param is dict'),
    list2=(['second1'], list, 'second param is list'),
    p3=(1313, int, 'third param is int'),
    p4=(None, int, 'fourth param is 10x p3'),
    p6=(None, _custom_p6, 'sixth param is a custom parser'),
    list7=(['default7'], list, 'seventh param is a list '),
    req8=pkconfig.Required(int, 'an eighth required parameter'),
    sub_params9=dict(
        sub9_1=(None, int, 'sub param is first of ninth group'),
        sub9_2=dict(sub9_2_1=(44, int, 'sub 9.2.1')),
    ),
    req10=pkconfig.RequiredUnlessDev(('dev-host', ), tuple,
                                     'a dev default-only param'),
    dynamic_default10=(None, _some_key, 'sub dynamic default by parsing None'),
    bool1=(False, bool, 'a False boolean'),
    bool2=(True, bool, 'a True boolean'),
    bool3=(True, bool, 'a True boolean will be overriden'),
    bool4=(False, bool, 'a False boolean will be overriden'),
    tuple1=((), tuple, 'an empty tuple'),
    tuple2=((1, ), tuple, 'a single value tuple'),
    tuple3=((2, ), tuple, '(2,) will be overrriden'),
    tuple4=((3, ), tuple, '(3,) will be overriden'),
Esempio n. 16
0

def _cfg_exclude_re(anything):
    if isinstance(anything, _RE_TYPE):
        return anything
    return re.compile(anything, flags=re.IGNORECASE)


def _cfg_keep_days(anything):
    if isinstance(anything, datetime.timedelta):
        return anything
    return datetime.timedelta(days=int(anything))


def _shell(cmd):
    subprocess.check_output(cmd, stderr=subprocess.STDOUT)


cfg = pkconfig.init(
    api_pause_seconds=(30, int, 'pauses between backups'),
    exclude_re=(None, _cfg_exclude_re, 'regular expression to exclude a repo'),
    keep_days=(
        _cfg_keep_days(2),
        _cfg_keep_days,
        'how many days of backups to keep',
    ),
    password=pkconfig.Required(str, 'github passsword'),
    test_mode=(False, pkconfig.parse_bool, 'only backup this repo'),
    user=pkconfig.Required(str, 'github user'),
)