libqtaws  0.1.0
UnofficialAWSlibraryforQt-InternalDocumentation
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
AwsEndpoint Class Reference

Provides AWS endpoint information. More...

Collaboration diagram for AwsEndpoint:
Collaboration graph
[legend]

Public Types

enum  Transport { HTTP = 0x01, HTTPS = 0x02, SMTP = 0x04, AnyTransport = HTTP|HTTPS|SMTP }
 Network transport supported by one or more AWS endpoints.
 

Public Member Functions

 AwsEndpoint (const QByteArray &hostName)
 Constructs a new AwsEndpoint object. More...
 
 AwsEndpoint (const QString &hostName)
 Constructs a new AwsEndpoint object. More...
 
 ~AwsEndpoint ()
 AwsEndpoint destructor.
 
bool isSupported (const Transport transport) const
 Is the given transport supported by this endpoint? More...
 
bool isValid () const
 Is this endpoint valid? More...
 
QString fullServiceName () const
 Get this endpoint's full service name. More...
 
QString hostName () const
 Get the name of host represented by this endpoint. More...
 
QString regionName () const
 Get this endpoint's primary region name. More...
 
QString serviceName () const
 Get this endpoint's service name. More...
 
QStringList supportedRegions (const Transports transport=AnyTransport) const
 Get the full list of regions this endpoint supports. More...
 

Static Public Member Functions

static QUrl getEndpoint (const QString &regionName, const QString &serviceName, const Transports transport=AnyTransport)
 Get a QUrl for an AWS endpoint. More...
 
static bool isSupported (const QString &regionName, const QString &serviceName, const Transports transport=AnyTransport)
 Is a region / service / transport combination supported by Amazon? More...
 
static QString fullServiceName (const QString &serviceName)
 Get the full name for given service. More...
 
static QStringList supportedRegions (const QString &serviceName, const Transports transport=AnyTransport)
 Get a list of regions that supported for a given service. More...
 
static QStringList supportedServices (const QString &regionName, const Transports transport=AnyTransport)
 Get a list of services that support a given region. More...
 

Private Attributes

AwsEndpointPrivate *const d_ptr
 Internal d-pointer.
 

Friends

class TestAwsEndpoint
 

Detailed Description

Provides AWS endpoint information.

Note
This class provides fairly low-level access to AWS endpoint data. You should consider using the AwsRegion and/or various AwsService-derived classes in preference to using this class directly where possible.

This class parses the endpoint.xml data available at http://aws-sdk-configurations.amazonwebservices.com/endpoints.xml

The endpoint.xml file is embedded as a resource in the libqtaws library - not fetched remotely at runtime.

Example usage:

AwsEndpoint endpoint(QLatin1String("cloudformation.us-east-1.amazonaws.com"));
endpoint.hostName(); // "cloudformation.us-east-1.amazonaws.com"
endpoint.regionName(); // "us-east-1"
endpoint.serviceName(); // "cloudformation"
endpoint.supportedRegions(); // [ "us-east-1" ]
endpoint.isSupported(AwsEndpoint::HTTP); // false
endpoint.isSupported(AwsEndpoint::HTTPS); // true
QUrl ec2 = AwsEndpoint::getEndpoint("ap-southeast-2", "ec2");
QUrl iam = AwsEndpoint::getEndpoint("ap-southeast-2", "iam");
ec2.host(); // "ec2.ap-southeast-2.amazonaws.com"
iam.host(); // "iam.amazonaws.com"
See also
AwsRegion
AwsService

Definition at line 33 of file awsendpoint.h.

Constructor & Destructor Documentation

AwsEndpoint::AwsEndpoint ( const QByteArray &  hostName)

Constructs a new AwsEndpoint object.

Parameters
hostNameName of an AWS host, encoded as UTF-8.

Definition at line 74 of file awsendpoint.cpp.

References AwsEndpointPrivate::hosts, and AwsEndpointPrivate::mutex.

75  : d_ptr(new AwsEndpointPrivate(this))
76 {
77  Q_D(AwsEndpoint);
78  d->hostName = QString::fromUtf8(hostName);
79  QMutexLocker locker(&AwsEndpointPrivate::mutex);
80  if (AwsEndpointPrivate::hosts.contains(d->hostName)) {
81  if (!AwsEndpointPrivate::hosts[d->hostName].regionNames.empty()) {
82  d->regionName = AwsEndpointPrivate::hosts[d->hostName].regionNames.first();
83  }
84  d->serviceName = AwsEndpointPrivate::hosts[d->hostName].serviceName;
85  }
86 }
QString hostName() const
Get the name of host represented by this endpoint.
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
Provides AWS endpoint information.
Definition: awsendpoint.h:33
AwsEndpointPrivate *const d_ptr
Internal d-pointer.
Definition: awsendpoint.h:79
Private implementation for AwsEndpoint.
Definition: awsendpoint_p.h:37
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73
AwsEndpoint::AwsEndpoint ( const QString &  hostName)

Constructs a new AwsEndpoint object.

Parameters
hostNameName of an AWS host.

Definition at line 93 of file awsendpoint.cpp.

References hostName(), AwsEndpointPrivate::hosts, and AwsEndpointPrivate::mutex.

94  : d_ptr(new AwsEndpointPrivate(this))
95 {
96  Q_D(AwsEndpoint);
97  d->hostName = hostName;
98  QMutexLocker locker(&AwsEndpointPrivate::mutex);
99  if (AwsEndpointPrivate::hosts.contains(d->hostName)) {
100  if (!AwsEndpointPrivate::hosts[d->hostName].regionNames.empty()) {
101  d->regionName = AwsEndpointPrivate::hosts[d->hostName].regionNames.first();
102  }
103  d->serviceName = AwsEndpointPrivate::hosts[d->hostName].serviceName;
104  }
105 }
QString hostName() const
Get the name of host represented by this endpoint.
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
Provides AWS endpoint information.
Definition: awsendpoint.h:33
AwsEndpointPrivate *const d_ptr
Internal d-pointer.
Definition: awsendpoint.h:79
Private implementation for AwsEndpoint.
Definition: awsendpoint_p.h:37
static QHash< QString, HostInfo > hosts
Hash of hostnames to HostInfo.
Definition: awsendpoint_p.h:73

Member Function Documentation

QString AwsEndpoint::fullServiceName ( ) const

Get this endpoint's full service name.

The full service name is a human-readbale form. For example, the full name for the cloudsearch service is Amazon CloudSearch. Likewise, the full name for the rds service is Amazon Relational Database Service.

Returns
This endpoint's full service name.
See also
serviceName

Definition at line 262 of file awsendpoint.cpp.

References serviceName().

263 {
264  return fullServiceName(serviceName());
265 }
QString fullServiceName() const
Get this endpoint's full service name.
QString serviceName() const
Get this endpoint's service name.
QString AwsEndpoint::fullServiceName ( const QString &  serviceName)
static

Get the full name for given service.

The full service name is a human-readbale form. For example, the full name for the cloudsearch service is Amazon CloudSearch. Likewise, the full name for the rds service is Amazon Relational Database Service.

Parameters
serviceNameCanonical AWS service name to get the full name of.
Returns
This endpoint's full service name.
See also
serviceName

Definition at line 280 of file awsendpoint.cpp.

References AwsEndpointPrivate::loadEndpointData(), AwsEndpointPrivate::mutex, and AwsEndpointPrivate::services.

281 {
283  QMutexLocker locker(&AwsEndpointPrivate::mutex);
284  const QHash<QString, AwsEndpointPrivate::ServiceInfo>::const_iterator
285  service = AwsEndpointPrivate::services.constFind(serviceName);
286  return (service == AwsEndpointPrivate::services.constEnd()) ? QString() : service.value().fullName;
287 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
QString serviceName() const
Get this endpoint's service name.
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
static QHash< QString, ServiceInfo > services
Hash of service names to ServiceInfo.
Definition: awsendpoint_p.h:75
QUrl AwsEndpoint::getEndpoint ( const QString &  regionName,
const QString &  serviceName,
const Transports  transport = AnyTransport 
)
static

Get a QUrl for an AWS endpoint.

This function will return a QUrl object for accessing an AWS service. The region and service names must match those used by Amazon.

If the specified region and/or service are not known to be valid for AWS, or the service is not supported in the specified region, then an invalid QUrl will be returned.

Note
An invalid QUrl is one for which QUrl::isValid returns false.

The transport parameter may be used to specify one or more transports to consider. If the specified AWS endpoint exists, but does not support //any// of the given transports, then an invalid QUrl is returned.

Where it makes sense to do so, the resulting QUrl's scheme will be set according to the requested transport. For example, if the selected transport is AwsEndpoint::HTTPS, then the resulting QUrl's schems will be set to "https".

If transport includes both AwsEndpoint::HTTP //and// AwsEndpoint::HTTPS, and both are supported by the AWS endpoint, then "https" will be chosed in preference to "http".

Note
It is possible for the returned QUrl to specify a host that is not located in, nor dedicated to the specified region. For examepl, if requesting an endpoint for the iam service in ap-southeast-2, the return endpoint is for a host (iam.amazonaws.com) which provides the ami services for all regions, not just ap-southeast-2. Services known to behave like this include: cloudfront, iam, importexport, route53, and sts.

Example usage:

QUrl ec2 = AwsEndpoint::getEndpoint("ap-southeast-2", "ec2");
QUrl iam = AwsEndpoint::getEndpoint("ap-southeast-2", "iam");
ec2.host(); // "ec2.ap-southeast-2.amazonaws.com"
iam.host(); // "iam.amazonaws.com"
Parameters
regionNameEndpoint's region name.
serviceNameEndpoint's service name.
transportOptional network transport(s) for the endpoint.
Returns
A QUrl representing the AWS endpoint, or an invalid QUrl if there is no such known AWS endpoint.
Todo:
Handle SMTP here?

Definition at line 163 of file awsendpoint.cpp.

References AwsEndpointPrivate::RegionEndpointInfo::hostName, AwsEndpointPrivate::loadEndpointData(), AwsEndpointPrivate::mutex, regionName(), AwsEndpointPrivate::regions, serviceName(), and AwsEndpointPrivate::RegionEndpointInfo::transports.

Referenced by AwsRegion::hostName().

165 {
167  QMutexLocker locker(&AwsEndpointPrivate::mutex);
168  if ((!AwsEndpointPrivate::regions.contains(regionName)) ||
169  (!AwsEndpointPrivate::regions[regionName].services.contains(serviceName))) {
170  return QUrl();
171  }
172  const AwsEndpointPrivate::RegionEndpointInfo &endpointInfo =
174  if (!(endpointInfo.transports & transport)) {
175  return QUrl();
176  }
177 
178  QUrl url;
179  url.setHost(endpointInfo.hostName);
180  if ((endpointInfo.transports & HTTPS) && (transport & HTTPS))
181  url.setScheme(QLatin1String("https"));
182  else if ((endpointInfo.transports & HTTP) && (transport & HTTP))
183  url.setScheme(QLatin1String("http"));
184  /// @todo Handle SMTP here?
185  return url;
186 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
QString serviceName() const
Get this endpoint's service name.
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
QString regionName() const
Get this endpoint's primary region name.
AwsEndpoint::Transports transports
Transports supported by this AWS endpoint.
Definition: awsendpoint_p.h:56
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
QString hostName
AWS endpoint's hostname.
Definition: awsendpoint_p.h:55
The per-region endpoint-specific information to load from the endpoints.xml file. ...
Definition: awsendpoint_p.h:54
QString AwsEndpoint::hostName ( ) const

Get the name of host represented by this endpoint.

Returns
Name of host represented by this endpoint.

Definition at line 193 of file awsendpoint.cpp.

Referenced by AwsEndpoint(), and isValid().

194 {
195  Q_D(const AwsEndpoint);
196  return d->hostName;
197 }
Provides AWS endpoint information.
Definition: awsendpoint.h:33
bool AwsEndpoint::isSupported ( const QString &  regionName,
const QString &  serviceName,
const Transports  transport = AnyTransport 
)
static

Is a region / service / transport combination supported by Amazon?

Parameters
regionNameAWS region name to check support for.
serviceNameAWS service name to check support for.
transportOptional transport to check support for.
Returns
true if the service is supported in the regionName region for at least one of the specified transports, false otherwise.

Definition at line 209 of file awsendpoint.cpp.

References AwsEndpointPrivate::loadEndpointData(), AwsEndpointPrivate::mutex, and AwsEndpointPrivate::regions.

Referenced by isSupported(), and AwsRegion::isSupported().

210 {
212  QMutexLocker locker(&AwsEndpointPrivate::mutex);
213  return ((AwsEndpointPrivate::regions.contains(regionName)) &&
214  (AwsEndpointPrivate::regions[regionName].services.contains(serviceName)) &&
215  (AwsEndpointPrivate::regions[regionName].services[serviceName].transports & transport));
216 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
QString serviceName() const
Get this endpoint's service name.
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
QString regionName() const
Get this endpoint's primary region name.
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
bool AwsEndpoint::isSupported ( const Transport  transport) const

Is the given transport supported by this endpoint?

Parameters
transportTransport to check for support for.
Returns
true if the transport is supported by this endpoint, false otherwise.

Definition at line 225 of file awsendpoint.cpp.

References isSupported(), regionName(), and serviceName().

226 {
227  return isSupported(regionName(), serviceName(), AwsEndpoint::Transports(transport));
228 }
QString serviceName() const
Get this endpoint's service name.
QString regionName() const
Get this endpoint's primary region name.
static bool isSupported(const QString &regionName, const QString &serviceName, const Transports transport=AnyTransport)
Is a region / service / transport combination supported by Amazon?
bool AwsEndpoint::isValid ( ) const

Is this endpoint valid?

An endpoint is considered valid if the host specified during construction is a known AWS host, and thus we know what region and service(s) it supports.

For example:

AwsEndpoint good(QLatin1String("cloudformation.us-east-1.amazonaws.com"));
AwsEndpoint bad(QLatin1String("example.com"));
Q_ASSERT(good.isValid()); // good is valid.
Q_ASSERT(!bad.isValid()); // bad is not.
Returns
true if this endpoint is valid, false otherwise.

Definition at line 246 of file awsendpoint.cpp.

References hostName(), regionName(), and serviceName().

247 {
248  return ((!hostName().isEmpty()) && (!regionName().isEmpty()) && (!serviceName().isEmpty()));
249 }
QString hostName() const
Get the name of host represented by this endpoint.
QString serviceName() const
Get this endpoint's service name.
QString regionName() const
Get this endpoint's primary region name.
QString AwsEndpoint::regionName ( ) const

Get this endpoint's primary region name.

It is possible for a single endpiont to support multuple regions, such as iam.amazonaws.com, which provides the ami servive for all (non-government) regions.

In these cases, this function returns the primary region in which the service is located. The AwsEndpoint::supportedRegions function may be used to fetch the full list of regions this endpoint supports.

Returns
This endpoint's region name.
See also
supportedRegions

Definition at line 304 of file awsendpoint.cpp.

Referenced by getEndpoint(), isSupported(), isValid(), supportedRegions(), and supportedServices().

305 {
306  Q_D(const AwsEndpoint);
307  return d->regionName;
308 }
Provides AWS endpoint information.
Definition: awsendpoint.h:33
QString AwsEndpoint::serviceName ( ) const

Get this endpoint's service name.

Returns
This endpoint's service name.
See also
fullServiceName

Definition at line 317 of file awsendpoint.cpp.

Referenced by fullServiceName(), getEndpoint(), isSupported(), isValid(), and supportedRegions().

318 {
319  Q_D(const AwsEndpoint);
320  return d->serviceName;
321 }
Provides AWS endpoint information.
Definition: awsendpoint.h:33
QStringList AwsEndpoint::supportedRegions ( const Transports  transport = AnyTransport) const

Get the full list of regions this endpoint supports.

Alternatvely, AwsEndpoint::regionName may be used to get this endpoint's primary region.

Parameters
transportOptional transport to check for support.
Returns
A list of all regions this endpoint supports for //at least one// of the specified transports.
See also
regionName

Definition at line 336 of file awsendpoint.cpp.

References serviceName().

337 {
338  return supportedRegions(serviceName(), transport);
339 }
QString serviceName() const
Get this endpoint's service name.
QStringList supportedRegions(const Transports transport=AnyTransport) const
Get the full list of regions this endpoint supports.
QStringList AwsEndpoint::supportedRegions ( const QString &  serviceName,
const Transports  transport = AnyTransport 
)
static

Get a list of regions that supported for a given service.

Parameters
serviceNameAWS service to get the supported regions for.
transportOptional transport(s) to check for support.
Returns
A list of AWS regions supported for the given service, for at least one of the specified transports.

Definition at line 350 of file awsendpoint.cpp.

References AwsEndpointPrivate::loadEndpointData(), AwsEndpointPrivate::mutex, regionName(), AwsEndpointPrivate::regions, serviceName(), and AwsEndpointPrivate::services.

351 {
353  QMutexLocker locker(&AwsEndpointPrivate::mutex);
354 
355  if (transport == AnyTransport) {
356  return AwsEndpointPrivate::services[serviceName].regionNames;
357  }
358 
359  QStringList regions;
360  foreach (const QString &regionName, AwsEndpointPrivate::services[serviceName].regionNames) {
361  if (AwsEndpointPrivate::regions[regionName].services[serviceName].transports & transport)
362  regions.append(regionName);
363  }
364  return regions;
365 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
QString serviceName() const
Get this endpoint's service name.
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
QString regionName() const
Get this endpoint's primary region name.
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.
static QHash< QString, ServiceInfo > services
Hash of service names to ServiceInfo.
Definition: awsendpoint_p.h:75
QStringList AwsEndpoint::supportedServices ( const QString &  regionName,
const Transports  transport = AnyTransport 
)
static

Get a list of services that support a given region.

Parameters
regionNameAWS region to get the supported services for.
transportOptional transport(s) to check for support.
Returns
A list of AWS services supported for the given region, for at least one of the specified transports.

Definition at line 376 of file awsendpoint.cpp.

References AwsEndpointPrivate::loadEndpointData(), AwsEndpointPrivate::mutex, regionName(), and AwsEndpointPrivate::regions.

Referenced by AwsRegion::supportedServices().

377 {
379  QMutexLocker locker(&AwsEndpointPrivate::mutex);
380 
381  if (transport == AnyTransport) {
382  return AwsEndpointPrivate::regions[regionName].services.keys();
383  }
384 
385  QStringList serviceNames;
387  for (AwsEndpointPrivate::RegionServices::const_iterator iter = services.constBegin(); iter != services.constEnd(); ++iter) {
388  if (iter.value().transports & transport)
389  serviceNames.append(iter.key());
390  }
391  return serviceNames;
392 }
static QMutex mutex
Mutex for protecting access to static members.
Definition: awsendpoint_p.h:77
QHash< QString, RegionEndpointInfo > RegionServices
Hash of service names to RegionEndpointInfo.
Definition: awsendpoint_p.h:60
static QHash< QString, RegionInfo > regions
Hash of region names to RegionInfo.
Definition: awsendpoint_p.h:74
QString regionName() const
Get this endpoint's primary region name.
static void loadEndpointData(const QString &fileName=QLatin1String(":/aws/endpoints.xml"))
Load endpoint data.

The documentation for this class was generated from the following files: