LCOV - code coverage report
Current view: top level - core - awsabstractcredentials.cpp (source / functions) Hit Total Coverage
Test: libqtaws 0.1.0 Lines: 18 18 100.0 %
Date: 2015-06-16 07:50:35 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :     Copyright 2013-2015 Paul Colby
       3             : 
       4             :     This file is part of libqtaws.
       5             : 
       6             :     Libqtaws is free software: you can redistribute it and/or modify
       7             :     it under the terms of the GNU Lesser General Public License as published by
       8             :     the Free Software Foundation, either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     Libqtaws is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :     GNU Lesser General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU Lesser General Public License
      17             :     along with libqtaws.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "awsabstractcredentials.h"
      21             : 
      22             : #include <QDebug>
      23             : 
      24             : QTAWS_BEGIN_NAMESPACE
      25             : 
      26             : /**
      27             :  * @class  AwsAbstractCredentials
      28             :  *
      29             :  * @brief  Interface class for providing AWS credentials.
      30             :  */
      31             : 
      32             : /**
      33             :  * @brief    Construct an AwsAbstractCredentials.
      34             :  * @param parent
      35             :  */
      36         140 : AwsAbstractCredentials::AwsAbstractCredentials(QObject * const parent) : QObject(parent) { }
      37             : 
      38             : /**
      39             :  * @fn       QString AwsAbstractCredentials::accessKeyId() const
      40             :  *
      41             :  * @brief    AWS access key ID for this credentials object.
      42             :  *
      43             :  * @returns  The AWS access key ID for this credentials object.
      44             :  */
      45             : 
      46             : /**
      47             :  * @fn       QString AwsAbstractCredentials::secretKey() const
      48             :  *
      49             :  * @brief    AWS secret access key for this credentials object.
      50             :  *
      51             :  * @returns  The AWS secret access key for this credentials object.
      52             :  */
      53             : 
      54             : /**
      55             :  * @fn       QString AwsAbstractCredentials::token() const
      56             :  *
      57             :  * @brief    AWS security token for this credentials object.
      58             :  *
      59             :  * @returns  The AWS security token for this credentials object.
      60             :  */
      61             : 
      62             : /**
      63             :  * @brief    DateTime at which the credentials will expire.
      64             :  *
      65             :  * This method should not be invoked unless the object is known to be refreshable
      66             :  * (ie isRefreshable() returns \c true).  As the base implementation of isRefreshable()
      67             :  * always returns \c false, this implementation of expiration() should not be invoked.
      68             :  *
      69             :  * Derived classes that return \c true from isRefreshable() must also override this
      70             :  * function to provide the appropriate expiration timestamp (which may a null QDateTime
      71             :  * if the credentials never expire).
      72             :  *
      73             :  * @returns  The DateTime at whcih the credentials will expire.
      74             :  *
      75             :  * @see  isExpired()
      76             :  * @see  isRefreshable()
      77             :  * @see  refresh()
      78             :  */
      79           5 : QDateTime AwsAbstractCredentials::expiration() const
      80             : {
      81           5 :     if (isRefreshable()) {
      82           2 :         qWarning() << "AwsAbstractCredentials: expiration must be implemented by refreshable derived classes";
      83             :     } else {
      84           3 :         qWarning() << "AwsAbstractCredentials: expiration should not be invoked on non-refreshable objects";
      85             :     }
      86           5 :     return QDateTime(); // A null QDateTime.
      87             : }
      88             : 
      89             : /**
      90             :  * @brief    Is this credentials object currently expired.
      91             :  *
      92             :  * In this base implementation, non-refreshable credentials (ie those for which
      93             :  * isRefreshable() returns \c false) are assumed to never expire, whereas refreshable
      94             :  * credentials are assume to be expired only if expiration() returns a valid QDateTime
      95             :  * representing a time in the past (ie earlier than QDateTime::currentDateTimeUtc()).
      96             :  *
      97             :  * Derived classes may override this method to implement custom expiration logic.
      98             :  *
      99             :  * @returns  \c true if this credentials object is expired, \c false otherwise.
     100             :  *
     101             :  * @see  expiration()
     102             :  * @see  isRefreshable()
     103             :  * @see  refresh()
     104             :  */
     105           4 : bool AwsAbstractCredentials::isExpired() const
     106             : {
     107           4 :     if (isRefreshable()) {
     108           1 :         const QDateTime expiration = this->expiration();
     109           1 :         return ((expiration.isValid()) && (expiration < QDateTime::currentDateTimeUtc()));
     110             :     }
     111           3 :     return false; // Non-refreshable credentials do not expire, by default.
     112             : }
     113             : 
     114             : /**
     115             :  * @brief    Is this credentials object refreshable.
     116             :  *
     117             :  * This base implementation always returns \c false - ie credentials are not refreshable
     118             :  * by default.  However, dervived classes may override this method as appropriate.
     119             :  *
     120             :  * Derived classes that override this method must also override the expiration() method
     121             :  * (merely returning a null QDateTime is the credentials do not expire), and may wish to
     122             :  * override isExpired() also.
     123             :  *
     124             :  * @returns  \c true if this credentials object is expired, \c false otherwise.
     125             :  *
     126             :  * @see  expiration()
     127             :  * @see  isExpired()
     128             :  * @see  refresh()
     129             :  */
     130          12 : bool AwsAbstractCredentials::isRefreshable() const
     131             : {
     132          12 :     return false;
     133             : }
     134             : 
     135             : /**
     136             :  * @brief  Refresh this object's credentials.
     137             :  *
     138             :  * This slot begins an asynchronous refresh transaction, and should be followed by a
     139             :  * change() signal when the credentials have been refreshed.
     140             :  *
     141             :  * @todo  A signal for errors?
     142             :  *
     143             :  * This method should not be invoked unless the object is known to be refreshable
     144             :  * (ie isRefreshable() returns \c true).  As the base implementation of isRefreshable()
     145             :  * always returns \c false, this implementation of expiration() should not be invoked.
     146             :  *
     147             :  * Derived classes that return \c true from isRefreshable() must also override this
     148             :  * function to provide the appropriate refresh behaviour.
     149             :  *
     150             :  * @returns  \c true if the refresh transaction has begun successfully, \c false otherwise.
     151             :  *
     152             :  * @see  isRefreshable()
     153             :  * @see  changed()
     154             :  */
     155           4 : bool AwsAbstractCredentials::refresh()
     156             : {
     157           4 :     if (isRefreshable()) {
     158           1 :         qWarning() << "AwsAbstractCredentials: refresh must be implemented by refreshable derived classes";
     159             :     } else {
     160           3 :         qWarning() << "AwsAbstractCredentials: refresh should not be invoked on non-refreshable objects";
     161             :     }
     162           4 :     return false;
     163             : }
     164             : 
     165             : /**
     166             :  * @fn     void AwsAbstractCredentials::changed()
     167             :  *
     168             :  * @brief  Signal emitted when this object's credentials have been updated.
     169             :  *
     170             :  * @see    refresh()
     171             :  */
     172             : 
     173             : QTAWS_END_NAMESPACE

Generated by: LCOV version 1.11