Skip to content
Permalink
Browse files
Small refactoring as per the GitHub conversations on the PR
  • Loading branch information
mo-tomcummins-roweit authored and nyalldawson committed Oct 22, 2021
1 parent c4d2512 commit 476b68fb21a459cc93e9ae0cb420ce33bc688757
@@ -66,22 +66,22 @@ bool QgsAuthApiHeaderMethod::updateNetworkRequest( QNetworkRequest &request, con
const QString &dataprovider )
{
Q_UNUSED( dataprovider )
const QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
if ( !mconfig.isValid() )
const QgsAuthMethodConfig config = getMethodConfig( authcfg );
if ( !config.isValid() )
{
QgsDebugMsg( QStringLiteral( "Update request config FAILED for authcfg: %1: config invalid" ).arg( authcfg ) );
return false;
}

QMapIterator<QString, QString> i( mconfig.configMap() );
QMapIterator<QString, QString> i( config.configMap() );
while ( i.hasNext() )
{
i.next();

const QString headerKey = i.key();
const QString headerValue = i.value();

QgsDebugMsg( QStringLiteral( "HTTP Header: %1=%2" ).arg( headerKey ).arg( headerValue ) );
QgsDebugMsgLevel( QStringLiteral( "HTTP Header: %1=%2" ).arg( headerKey ).arg( headerValue ), 2 );

if ( !headerKey.isEmpty() )
{
@@ -90,8 +90,7 @@ bool QgsAuthApiHeaderMethod::updateNetworkRequest( QNetworkRequest &request, con
}
else
{
const QString msg = "The header key was empty, we shouldn't have empty header keys at this point";
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Warning );
QgsDebugMsg( QStringLiteral( "The header key was empty, we shouldn't have empty header keys at this point" ) );
}
}

@@ -103,43 +102,43 @@ void QgsAuthApiHeaderMethod::clearCachedConfig( const QString &authcfg )
removeMethodConfig( authcfg );
}

void QgsAuthApiHeaderMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
void QgsAuthApiHeaderMethod::updateMethodConfig( QgsAuthMethodConfig &config )
{
Q_UNUSED( mconfig );
// NOTE: add updates as method version() increases due to config storage changes
Q_UNUSED( config );
// NOTE: add updates as method version() increases due to config storage changes
}

QgsAuthMethodConfig QgsAuthApiHeaderMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
{
const QMutexLocker locker( &mMutex );
QgsAuthMethodConfig mconfig;
QgsAuthMethodConfig config;

// check if it is cached
if ( sAuthConfigCache.contains( authcfg ) )
{
mconfig = sAuthConfigCache.value( authcfg );
QgsDebugMsg( QStringLiteral( "Retrieved config for authcfg: %1" ).arg( authcfg ) );
return mconfig;
config = sAuthConfigCache.value( authcfg );
QgsDebugMsgLevel( QStringLiteral( "Retrieved config for authcfg: %1" ).arg( authcfg ), 2 );
return config;
}

// else build basic bundle
if ( !QgsApplication::authManager()->loadAuthenticationConfig( authcfg, mconfig, fullconfig ) )
if ( !QgsApplication::authManager()->loadAuthenticationConfig( authcfg, config, fullconfig ) )
{
QgsDebugMsg( QStringLiteral( "Retrieve config FAILED for authcfg: %1" ).arg( authcfg ) );
return QgsAuthMethodConfig();
}

// cache bundle
putMethodConfig( authcfg, mconfig );
putMethodConfig( authcfg, config );

return mconfig;
return config;
}

void QgsAuthApiHeaderMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig )
void QgsAuthApiHeaderMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &config )
{
const QMutexLocker locker( &mMutex );
QgsDebugMsg( QStringLiteral( "Putting token config for authcfg: %1" ).arg( authcfg ) );
sAuthConfigCache.insert( authcfg, mconfig );
QgsDebugMsgLevel( QStringLiteral( "Putting token config for authcfg: %1" ).arg( authcfg ), 2 );
sAuthConfigCache.insert( authcfg, config );
}

void QgsAuthApiHeaderMethod::removeMethodConfig( const QString &authcfg )
@@ -148,7 +147,7 @@ void QgsAuthApiHeaderMethod::removeMethodConfig( const QString &authcfg )
if ( sAuthConfigCache.contains( authcfg ) )
{
sAuthConfigCache.remove( authcfg );
QgsDebugMsg( QStringLiteral( "Removed token config for authcfg: %1" ).arg( authcfg ) );
QgsDebugMsgLevel( QStringLiteral( "Removed token config for authcfg: %1" ).arg( authcfg ), 2 );
}
}

@@ -48,7 +48,7 @@ class QgsAuthApiHeaderMethod : public QgsAuthMethod
const QString &dataprovider = QString() ) override;

void clearCachedConfig( const QString &authcfg ) override;
void updateMethodConfig( QgsAuthMethodConfig &mconfig ) override;
void updateMethodConfig( QgsAuthMethodConfig &config ) override;

#ifdef HAVE_GUI
QWidget *editWidget( QWidget *parent )const override;
@@ -57,7 +57,7 @@ class QgsAuthApiHeaderMethod : public QgsAuthMethod
private:
QgsAuthMethodConfig getMethodConfig( const QString &authcfg, bool fullconfig = true );

void putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig );
void putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &config );

void removeMethodConfig( const QString &authcfg );

@@ -136,7 +136,7 @@ void QgsAuthApiHeaderEdit::headerTableCellChanged( const int row, const int colu
bool QgsAuthApiHeaderEdit::emptyHeadersKeysPresent()
{
const int rowCount = tblwdgHeaderPairs->rowCount();
QgsDebugMsg( QStringLiteral( "Validate header table contains valid header keys for %1 rows" ).arg( rowCount ) );
QgsDebugMsgLevel( QStringLiteral( "Validate header table contains valid header keys for %1 rows" ).arg( rowCount ), 2 );

for ( int i = 0; i < rowCount; ++i )
{
@@ -152,19 +152,19 @@ bool QgsAuthApiHeaderEdit::emptyHeadersKeysPresent()

void QgsAuthApiHeaderEdit::addHeaderPairRow( const QString &key, const QString &val )
{
const int rowCnt = tblwdgHeaderPairs->rowCount();
tblwdgHeaderPairs->insertRow( rowCnt );
const int rowCount = tblwdgHeaderPairs->rowCount();
tblwdgHeaderPairs->insertRow( rowCount );

const Qt::ItemFlags itmFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable
| Qt::ItemIsEditable | Qt::ItemIsDropEnabled;
const Qt::ItemFlags itemFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable
| Qt::ItemIsEditable | Qt::ItemIsDropEnabled;

QTableWidgetItem *keyItm = new QTableWidgetItem( key );
keyItm->setFlags( itmFlags );
tblwdgHeaderPairs->setItem( rowCnt, 0, keyItm );
QTableWidgetItem *keyItem = new QTableWidgetItem( key );
keyItem->setFlags( itemFlags );
tblwdgHeaderPairs->setItem( rowCount, 0, keyItem );

QTableWidgetItem *valItm = new QTableWidgetItem( val );
keyItm->setFlags( itmFlags );
tblwdgHeaderPairs->setItem( rowCnt, 1, valItm );
QTableWidgetItem *valueItem = new QTableWidgetItem( val );
keyItem->setFlags( itemFlags );
tblwdgHeaderPairs->setItem( rowCount, 1, valueItem );

validateConfig();
}
@@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>538</width>
<height>498</height>
<width>532</width>
<height>492</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
@@ -139,15 +139,16 @@
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">+</string>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRemoveHeaderPair">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
@@ -161,8 +162,9 @@
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">–</string>
<property name="icon">
<iconset>
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property>
</widget>
</item>

0 comments on commit 476b68f

Please sign in to comment.