Esempio n. 1
0
    def test_load(self):
        with self.assertRaises(IOError):
            sc = ServiceConfig("Does/not/exist")


        template = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "invalid") )
        with self.assertRaises(ValueError):
            sc = ServiceConfig(template)

        template = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "../share/friskby.service") )
        sc = ServiceConfig( template , config_file = "/tmp/friskby.service")

        exe = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "exe") )
        content = sc.save(exe)
Esempio n. 2
0
def get_service_config(args):
    '''
  Get service config, without any dependencies.

  @param  args       the command line arguments object parsed by argparse
  '''
    service_config.get_short_user_name(args)
    if not getattr(args, args.service + "_config", None):
        setattr(args, args.service + "_config", ServiceConfig(args))
    return getattr(args, args.service + "_config")
Esempio n. 3
0
    def test_load(self):
        with self.assertRaises(IOError):
            sc = ServiceConfig("Does/not/exist")


        template = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "invalid") )
        with self.assertRaises(ValueError):
            sc = ServiceConfig(template)

        template = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "../share/friskby") )
        sc = ServiceConfig( template )

        exe = os.path.abspath( os.path.join( os.path.dirname( __file__ ) , "exe") )
        content = sc.render(exe , "FriskBY")
Esempio n. 4
0
 def test_is_systemd(self):
     self.assertEqual( os.path.isdir( "/etc/systemd/system") , ServiceConfig.systemd())
Esempio n. 5
0
 def test_is_systemd(self):
     self.assertEqual(os.path.isdir("/etc/systemd/system"),
                      ServiceConfig.systemd())
    def __init__(self, config, logger):
        """Constructor

        :param obj config: ConfigGenerator config
        :param Logger logger: Logger
        """
        self.logger = logger

        self.config = config
        generator_config = config.get('config', {})
        self.config_path = generator_config.get('config_path', '/tmp/')
        self.default_qgis_server_url = generator_config.get(
            'default_qgis_server_url', 'http://localhost:8001/ows/')

        try:
            # load ORM models for ConfigDB
            config_db_url = generator_config.get(
                'config_db_url', 'postgresql:///?service=soconfig_services')
            db_engine = DatabaseEngine()
            config_db_engine = db_engine.db_engine(config_db_url)
            self.config_models = ConfigModels(config_db_engine)
        except Exception as e:
            msg = ("Could not load ConfigModels for ConfigDB at '%s':\n%s" %
                   (config_db_url, e))
            self.logger.error(msg)
            raise Exception(msg)

        # load metadata for layers
        metadata_reader = MetadataReader(self.config.get('metadata', {}),
                                         self.logger)
        metadata_reader.load_metadata()

        # create service config handlers
        self.config_handler = {
            'ogc':
            OGCServiceConfig(self.config_models, db_engine, self.logger),
            'featureInfo':
            FeatureInfoServiceConfig(self.config_models, self.logger),
            'legend':
            LegendServiceConfig(self.config_models, generator_config,
                                self.logger),
            'mapViewer':
            MapViewerConfig(self.config_models, metadata_reader, self.logger),
            'dataproduct':
            DataproductServiceConfig(self.config_models, metadata_reader,
                                     self.logger),
            'print':
            PrintServiceConfig(self.config_models, self.logger),
            'search':
            SearchServiceConfig(self.config_models, self.logger),
            'data':
            DataServiceConfig(self.config_models, self.logger),
            'document':
            DocumentServiceConfig(self.config_models, self.logger),
            # config-only services
            'agdi':
            ServiceConfig(
                'agdi',
                'https://github.com/qwc-services/sogis-agdi/raw/master/schemas/sogis-agdi.json',
                self.logger),
            'saml-auth':
            ServiceConfig(
                'samlAuth',
                'https://github.com/qwc-services/sogis-config-generator/raw/master/schemas/qwc-saml-auth.json',
                self.logger, 'saml-auth'),
            'ccc':
            ServiceConfig(
                'ccc', 'https://github.com/qwc-services/'
                'sogis-ccc-config/raw/master/schemas/sogis-ccc-config.json',
                self.logger),
            'elevation':
            ServiceConfig(
                'elevation', 'https://github.com/qwc-services/'
                'qwc-elevation-service/raw/master/schemas/qwc-elevation-service.json',
                self.logger),
            'landreg':
            ServiceConfig(
                'landreg', 'https://github.com/qwc-services/'
                'sogis-landreg-service/raw/master/schemas/sogis-landreg-service.json',
                self.logger),
            'mapinfo':
            ServiceConfig(
                'mapinfo', 'https://github.com/qwc-services/'
                'qwc-mapinfo-service/raw/master/schemas/qwc-mapinfo-service.json',
                self.logger),
            'permalink':
            ServiceConfig(
                'permalink', 'https://github.com/qwc-services/'
                'qwc-permalink-service/raw/master/schemas/qwc-permalink-service.json',
                self.logger),
            'plotinfo':
            ServiceConfig(
                'plotinfo', 'https://github.com/qwc-services/'
                'sogis-plotinfo-service/raw/master/schemas/sogis-plotinfo-service.json',
                self.logger)
        }

        try:
            # check tenant dir
            tenant_path = os.path.join(self.config_path, 'default')
            if not os.path.isdir(tenant_path):
                # create default tenant dir
                self.logger.info("Creating default tenant dir %s" %
                                 tenant_path)
                os.mkdir(tenant_path)
        except Exception as e:
            self.logger.error("Could not create default tenant dir:\n%s" % e)

        # create QGIS writer
        self.qgs_writer = QGSWriter(self.config.get('qgs_writer', {}),
                                    self.config_models, db_engine, self.logger)