Skip to content
Permalink
Browse files

Merge pull request #38415 from pblottiere/lp_env

Landing page settings
  • Loading branch information
pblottiere committed Aug 27, 2020
2 parents af81515 + 353e593 commit 9f8e1ccfb6d62bcf47263a7813120bdcdc63c3a2
@@ -0,0 +1,3 @@
# The following has been generated automatically from src/server/qgsserversettings.h
QgsServerSettingsEnv.Source.baseClass = QgsServerSettingsEnv
QgsServerSettingsEnv.EnvVar.baseClass = QgsServerSettingsEnv
@@ -11,6 +11,50 @@



class QgsServerSettingsEnv : QObject
{
%Docstring
Provides some enum describing the environment currently supported for configuration.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsserversettings.h"
%End
public:
enum Source
{
DEFAULT_VALUE,
ENVIRONMENT_VARIABLE,
INI_FILE
};

enum EnvVar
{
QGIS_OPTIONS_PATH,
QGIS_SERVER_PARALLEL_RENDERING,
QGIS_SERVER_MAX_THREADS,
QGIS_SERVER_LOG_LEVEL,
QGIS_SERVER_LOG_FILE,
QGIS_SERVER_LOG_STDERR,
QGIS_PROJECT_FILE,
MAX_CACHE_LAYERS,
QGIS_SERVER_IGNORE_BAD_LAYERS,
QGIS_SERVER_CACHE_DIRECTORY,
QGIS_SERVER_CACHE_SIZE,
QGIS_SERVER_SHOW_GROUP_SEPARATOR,
QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE,
QGIS_SERVER_WMS_MAX_HEIGHT,
QGIS_SERVER_WMS_MAX_WIDTH,
QGIS_SERVER_API_RESOURCES_DIRECTORY,
QGIS_SERVER_API_WFS3_MAX_LIMIT,
QGIS_SERVER_TRUST_LAYER_METADATA,
QGIS_SERVER_DISABLE_GETPRINT,
QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES,
QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS
};
};

class QgsServerSettings
{
@@ -153,6 +197,24 @@ Returns the server-wide max width of a WMS GetMap request. The lower one of this
:return: the max width of a WMS GetMap request.

.. versionadded:: 3.6.2
%End

QString landingPageProjectsDirectories() const;
%Docstring
Returns the directories used by the landing page service to find .qgs
and .qgz projects. Multiple directories can be specified by separating
them with '||'.

.. versionadded:: 3.16
%End

QString landingPageProjectsPgConnections() const;
%Docstring
Returns the PostgreSQL connection strings used by the landing page
service to find projects. Multiple connections can be specified by
separating them with '||'.

.. versionadded:: 3.16
%End

QString apiResourcesDirectory() const;
@@ -204,6 +266,13 @@ reading flag DONT_LOAD_LAYOUTS is activated.
The default value is ``False``, this value can be changed by setting the environment
variable QGIS_SERVER_DISABLE_GETPRINT.

.. versionadded:: 3.16
%End

static QString name( QgsServerSettingsEnv::EnvVar env );
%Docstring
Returns the string representation of a setting.

.. versionadded:: 3.16
%End

@@ -120,7 +120,7 @@ class SERVER_EXPORT QgsServerOgcApi : public QgsServerApi
static const QMap<QgsServerOgcApi::ContentType, QStringList> contentTypeMimes() SIP_SKIP;

/**
* Returns contenType specializations (e.g. JSON => [GEOJSON, OPENAPI3], XML => [GML])
* Returns contentType specializations (e.g. JSON => [GEOJSON, OPENAPI3], XML => [GML])
* \note not available in Python bindings
*/
static const QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType> > contentTypeAliases() SIP_SKIP;
@@ -241,6 +241,30 @@ void QgsServerSettings::initSettings()
};

mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;

// projects directory for landing page service
const Setting sProjectsDirectories = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Directories used by the landing page service to find .qgs and .qgz projects" ),
QStringLiteral( "/qgis/server_projects_directories" ),
QVariant::String,
QVariant( "" ),
QVariant()
};

mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;

// postgresql connection string for landing page service
const Setting sProjectsPgConnections = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "PostgreSQL connection strings used by the landing page service to find projects" ),
QStringLiteral( "/qgis/server_projects_pg_connections" ),
QVariant::String,
QVariant( "" ),
QVariant()
};

mSettings[ sProjectsPgConnections.envVar ] = sProjectsPgConnections;
}

void QgsServerSettings::load()
@@ -288,8 +312,16 @@ QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
return env;
}

QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar ) const
QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
{
if ( actual )
{
const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );

if ( ! envValue.isEmpty() )
return envValue;
}

if ( mSettings[ envVar ].src == QgsServerSettingsEnv::DEFAULT_VALUE )
{
return mSettings[ envVar ].defaultVal;
@@ -349,16 +381,21 @@ void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QSt
}
}

QString QgsServerSettings::name( QgsServerSettingsEnv::EnvVar env )
{
const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
return metaEnumEnv.valueToKey( env );
}

void QgsServerSettings::logSummary() const
{
const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );

QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::Info );
for ( Setting s : mSettings )
{
const QString src = metaEnumSrc.valueToKey( s.src );
const QString var = metaEnumEnv.valueToKey( s.envVar );
const QString var = name( s.envVar );

const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
QgsMessageLog::logMessage( msg, "Server", Qgis::Info );
@@ -442,6 +479,16 @@ int QgsServerSettings::wmsMaxWidth() const
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH ).toInt();
}

QString QgsServerSettings::landingPageProjectsDirectories() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES, true ).toString();
}

QString QgsServerSettings::landingPageProjectsPgConnections() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS, true ).toString();
}

QString QgsServerSettings::apiResourcesDirectory() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_API_RESOURCES_DIRECTORY ).toString();
@@ -33,7 +33,6 @@
* \brief Provides some enum describing the environment currently supported for configuration.
* \since QGIS 3.0
*/
#ifndef SIP_RUN
class SERVER_EXPORT QgsServerSettingsEnv : public QObject
{
Q_OBJECT
@@ -69,11 +68,12 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
QGIS_SERVER_API_RESOURCES_DIRECTORY, //!< Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for (since QGIS 3.10).
QGIS_SERVER_API_WFS3_MAX_LIMIT, //!< Maximum value for "limit" in a features request, defaults to 10000 (since QGIS 3.10).
QGIS_SERVER_TRUST_LAYER_METADATA, //!< Trust layer metadata. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_DISABLE_GETPRINT //!< Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_DISABLE_GETPRINT, //!< Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES, //!< Directories used by the landing page service to find .qgs and .qgz projects (since QGIS 3.16)
QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS //!< PostgreSQL connection strings used by the landing page service to find projects (since QGIS 3.16)
};
Q_ENUM( EnvVar )
};
#endif

/**
* \ingroup server
@@ -205,6 +205,22 @@ class SERVER_EXPORT QgsServerSettings
*/
int wmsMaxWidth() const;

/**
* Returns the directories used by the landing page service to find .qgs
* and .qgz projects. Multiple directories can be specified by separating
* them with '||'.
* \since QGIS 3.16
*/
QString landingPageProjectsDirectories() const;

/**
* Returns the PostgreSQL connection strings used by the landing page
* service to find projects. Multiple connections can be specified by
* separating them with '||'.
* \since QGIS 3.16
*/
QString landingPageProjectsPgConnections() const;

/**
* Returns the server-wide base directory where HTML templates and static assets (e.g. images, js and css files) are searched for.
*
@@ -257,9 +273,15 @@ class SERVER_EXPORT QgsServerSettings
*/
bool getPrintDisabled() const;

/**
* Returns the string representation of a setting.
* \since QGIS 3.16
*/
static QString name( QgsServerSettingsEnv::EnvVar env );

private:
void initSettings();
QVariant value( QgsServerSettingsEnv::EnvVar envVar ) const;
QVariant value( QgsServerSettingsEnv::EnvVar envVar, bool actual = false ) const;
QMap<QgsServerSettingsEnv::EnvVar, QString> getEnv() const;
void loadQSettings( const QString &envOptPath ) const;
void prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env );
@@ -77,7 +77,7 @@ class QgsProjectLoaderFilter: public QgsServerFilter
const auto handler { serverInterface()->requestHandler() };
if ( handler->path().startsWith( QStringLiteral( "/project/" ) ) )
{
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( handler->url() ) };
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( handler->url(), *serverInterface()->serverSettings() ) };
if ( ! projectPath.isEmpty() )
{
qputenv( "QGIS_PROJECT_FILE", projectPath.toUtf8() );
@@ -109,8 +109,8 @@ class QgsLandingPageModule: public QgsServiceModule
};
// Register handlers
landingPageApi->registerHandler<QgsServerStaticHandler>( QStringLiteral( "/(?<staticFilePath>((css|js)/.*)|favicon.ico)$" ), QStringLiteral( "landingpage" ) );
landingPageApi->registerHandler<QgsLandingPageHandler>();
landingPageApi->registerHandler<QgsLandingPageMapHandler>();
landingPageApi->registerHandler<QgsLandingPageHandler>( serverIface->serverSettings() );
landingPageApi->registerHandler<QgsLandingPageMapHandler>( serverIface->serverSettings() );

// Register API
registry.registerApi( landingPageApi );
@@ -28,7 +28,8 @@
#include <QDir>
#include <QCryptographicHash>

QgsLandingPageHandler::QgsLandingPageHandler()
QgsLandingPageHandler::QgsLandingPageHandler( const QgsServerSettings *settings )
: mSettings( settings )
{
setContentTypes( { QgsServerOgcApi::ContentType::JSON, QgsServerOgcApi::ContentType::HTML } );
}
@@ -65,7 +66,7 @@ const QString QgsLandingPageHandler::templatePath( const QgsServerApiContext &co
json QgsLandingPageHandler::projectsData() const
{
json j = json::array();
const auto availableProjects { QgsLandingPageUtils::projects( ) };
const auto availableProjects { QgsLandingPageUtils::projects( *mSettings ) };
const auto constProjectKeys { availableProjects.keys() };
for ( const auto &p : constProjectKeys )
{
@@ -75,7 +76,8 @@ json QgsLandingPageHandler::projectsData() const
}


QgsLandingPageMapHandler::QgsLandingPageMapHandler()
QgsLandingPageMapHandler::QgsLandingPageMapHandler( const QgsServerSettings *settings )
: mSettings( settings )
{
setContentTypes( { QgsServerOgcApi::ContentType::JSON } );
}
@@ -84,7 +86,7 @@ void QgsLandingPageMapHandler::handleRequest( const QgsServerApiContext &context
{
json data;
data[ "links" ] = json::array();
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( context.request()->url().path() ) };
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( context.request()->url().path(), *mSettings ) };
if ( projectPath.isEmpty() )
{
throw QgsServerApiNotFoundError( QStringLiteral( "Requested project hash not found!" ) );
@@ -18,6 +18,7 @@
#ifndef QGS_LANDINGPAGE_HANDLERS_H
#define QGS_LANDINGPAGE_HANDLERS_H

#include "qgsserversettings.h"
#include "qgsserverogcapihandler.h"
#include "qgsfields.h"

@@ -32,7 +33,7 @@ class QgsLandingPageHandler: public QgsServerOgcApiHandler
{
public:

QgsLandingPageHandler( );
QgsLandingPageHandler( const QgsServerSettings *settings );

void handleRequest( const QgsServerApiContext &context ) const override;

@@ -57,7 +58,7 @@ class QgsLandingPageHandler: public QgsServerOgcApiHandler

json projectsData() const;


const QgsServerSettings *mSettings = nullptr;
};


@@ -68,7 +69,7 @@ class QgsLandingPageMapHandler: public QgsServerOgcApiHandler
{
public:

QgsLandingPageMapHandler( );
QgsLandingPageMapHandler( const QgsServerSettings *settings );

void handleRequest( const QgsServerApiContext &context ) const override;

@@ -86,6 +87,10 @@ class QgsLandingPageMapHandler: public QgsServerOgcApiHandler
}
std::string linkTitle() const override { return "Map Viewer"; }
QgsServerOgcApi::Rel linkType() const override { return QgsServerOgcApi::Rel::self; }

private:

const QgsServerSettings *mSettings = nullptr;
};

#endif // QGS_LANDINGPAGE_HANDLERS_H

0 comments on commit 9f8e1cc

Please sign in to comment.
You can’t perform that action at this time.