#11938 Cloud Config: Show the full path to config file for cloud services

This commit is contained in:
Magne Sjaastad 2024-11-28 10:41:14 +01:00
parent bb19ba75a4
commit 041e2f2e13
7 changed files with 76 additions and 56 deletions

View File

@ -30,6 +30,7 @@
#include "RiaLogging.h"
#include "RiaPlotWindowRedrawScheduler.h"
#include "RiaPreferences.h"
#include "RiaPreferencesOsdu.h"
#include "RiaPreferencesSumo.h"
#include "RiaPreferencesSystem.h"
#include "RiaProjectModifier.h"
@ -1477,59 +1478,6 @@ cvf::Font* RiaApplication::defaultWellLabelFont()
return m_defaultWellLabelFont.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
auto readCloudConfigFiles = []( RiaPreferences* preferences )
{
if ( preferences == nullptr ) return;
// Check multiple locations for configuration files. The first valid configuration file is used. Currently, using Qt5 the ResInsight
// binary file is stored at the root of the installation folder. When moving to Qt6, we will probably use sub folders /bin /lib and
// others. Support both one and two search levels to support Qt6.
//
// home_folder/.resinsight/*_config.json
// location_of_resinsight_executable/../share/cloud_services/*_config.json
// location_of_resinsight_executable/../../share/cloud_services/*_config.json
//
{
QStringList osduFilePathCandidates;
osduFilePathCandidates << QDir::homePath() + "/.resinsight/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/osdu_config.json";
for ( const auto& osduFileCandidate : osduFilePathCandidates )
{
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduFileCandidate );
if ( !keyValuePairs.empty() )
{
preferences->osduPreferences()->setData( keyValuePairs );
preferences->osduPreferences()->setFieldsReadOnly();
break;
}
}
}
{
QStringList sumoFilePathCandidates;
sumoFilePathCandidates << QDir::homePath() + "/.resinsight/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/sumo_config.json";
for ( const auto& sumoFileCandidate : sumoFilePathCandidates )
{
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoFileCandidate );
if ( !keyValuePairs.empty() )
{
preferences->sumoPreferences()->setData( keyValuePairs );
preferences->sumoPreferences()->setFieldsReadOnly();
break;
}
}
}
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1548,8 +1496,6 @@ void RiaApplication::initialize()
caf::SelectionManager::instance()->setPdmRootObject( project() );
initializeDataLoadController();
readCloudConfigFiles( m_preferences.get() );
}
//--------------------------------------------------------------------------------------------------

View File

@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RiaConsoleApplication.h"
#include "Cloud/RiaConnectorTools.h"
#include "RiaArgumentParser.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
@ -109,6 +110,8 @@ void RiaConsoleApplication::initialize()
RiaLogging::appendLoggerInstance( std::move( logger ) );
m_socketServer = new RiaSocketServer( this );
RiaConnectorTools::readCloudConfigFiles( m_preferences.get() );
}
//--------------------------------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
#include "RiaGuiApplication.h"
#include "Cloud/RiaConnectorTools.h"
#include "RiaArgumentParser.h"
#include "RiaBaseDefs.h"
#include "RiaDefines.h"
@ -445,6 +446,8 @@ void RiaGuiApplication::initialize()
}
}
m_socketServer = new RiaSocketServer( this );
RiaConnectorTools::readCloudConfigFiles( m_preferences.get() );
}
//--------------------------------------------------------------------------------------------------

View File

@ -26,6 +26,7 @@
#include "RiaLogging.h"
#include "RiaPreferencesGeoMech.h"
#include "RiaPreferencesGrid.h"
#include "RiaPreferencesOsdu.h"
#include "RiaPreferencesSummary.h"
#include "RiaPreferencesSumo.h"
#include "RiaPreferencesSystem.h"

View File

@ -24,7 +24,6 @@
#include "RiaDateTimeDefines.h"
#include "RiaDefines.h"
#include "RiaFontCache.h"
#include "RiaPreferencesOsdu.h"
#include "cafAppEnum.h"
#include "cafPdmChildField.h"

View File

@ -18,6 +18,11 @@
#include "RiaConnectorTools.h"
#include "RiaLogging.h"
#include "RiaPreferences.h"
#include "RiaPreferencesOsdu.h"
#include "RiaPreferencesSumo.h"
#include <QDir>
#include <QFile>
#include <QFileInfo>
@ -26,6 +31,8 @@
#include <QTextStream>
#include <QtNetworkAuth/QOAuth2AuthorizationCodeFlow>
#include <QCoreApplication>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -121,3 +128,60 @@ std::map<QString, QString> RiaConnectorTools::readKeyValuePairs( const QString&
return keyValuePairs;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaConnectorTools::readCloudConfigFiles( RiaPreferences* preferences )
{
if ( preferences == nullptr ) return;
// Check multiple locations for configuration files. The first valid configuration file is used. Currently, using Qt5 the ResInsight
// binary file is stored at the root of the installation folder. When moving to Qt6, we will probably use sub folders /bin /lib and
// others. Support both one and two search levels to support Qt6.
//
// home_folder/.resinsight/*_config.json
// location_of_resinsight_executable/../share/cloud_services/*_config.json
// location_of_resinsight_executable/../../share/cloud_services/*_config.json
//
{
QStringList osduFilePathCandidates;
osduFilePathCandidates << QDir::homePath() + "/.resinsight/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/osdu_config.json";
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/osdu_config.json";
for ( const auto& osduFileCandidate : osduFilePathCandidates )
{
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduFileCandidate );
if ( !keyValuePairs.empty() )
{
RiaLogging::info( QString( "Imported OSDU configuration from : '%1'" ).arg( osduFileCandidate ) );
preferences->osduPreferences()->setData( keyValuePairs );
preferences->osduPreferences()->setFieldsReadOnly();
break;
}
}
}
{
QStringList sumoFilePathCandidates;
sumoFilePathCandidates << QDir::homePath() + "/.resinsight/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/sumo_config.json";
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/sumo_config.json";
for ( const auto& sumoFileCandidate : sumoFilePathCandidates )
{
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoFileCandidate );
if ( !keyValuePairs.empty() )
{
RiaLogging::info( QString( "Imported SUMO configuration from : '%1'" ).arg( sumoFileCandidate ) );
preferences->sumoPreferences()->setData( keyValuePairs );
preferences->sumoPreferences()->setFieldsReadOnly();
break;
}
}
}
}

View File

@ -22,6 +22,7 @@
#include <map>
class QOAuth2AuthorizationCodeFlow;
class RiaPreferences;
namespace RiaConnectorTools
{
@ -31,4 +32,7 @@ void writeTokenData( const QString& filePath, const QString& tokenDataJson );
QString readStringFromFile( const QString& filePath );
std::map<QString, QString> readKeyValuePairs( const QString& filePath );
void readCloudConfigFiles( RiaPreferences* preferences );
} // namespace RiaConnectorTools