Skip to content

Commit

Permalink
Merge pull request #5 from ogail/dev
Browse files Browse the repository at this point in the history
Add configuration for service bus using connection strings
  • Loading branch information
Abdelrahman Elogeel authored and Abdelrahman Elogeel committed Jun 29, 2012
2 parents 7990077 + f8d51fb commit 606ba27
Show file tree
Hide file tree
Showing 25 changed files with 692 additions and 495 deletions.
17 changes: 8 additions & 9 deletions WindowsAzure/Common/Internal/Filters/WrapFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,22 @@ class WrapFilter implements IServiceFilter
/**
* Creates a WrapFilter with specified WRAP parameters.
*
* @param string $wrapUri The URI of the WRAP service.
* @param string $wrapUsername The user name of the WRAP account.
* @param string $wrapPassword The password of the WRAP account.
*
* @return
* WindowsAzure\Common\Internal\Filter\WrapFilter
*
* @param string $wrapUri The URI of the WRAP service.
* @param string $wrapUsername The user name of the WRAP account.
* @param string $wrapPassword The password of the WRAP account.
* @param IWrap $wrapRestProxy The WRAP service REST proxy.
*/
public function __construct(
$wrapUri,
$wrapUsername,
$wrapPassword
$wrapPassword,
$wrapRestProxy
) {
$this->_wrapTokenManager = new WrapTokenManager(
$wrapUri,
$wrapUsername,
$wrapPassword
$wrapPassword,
$wrapRestProxy
);
}

Expand Down
9 changes: 0 additions & 9 deletions WindowsAzure/Common/Internal/IServicesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ public function createServiceManagementService($config);
* @return WindowsAzure\ServiceBus\ServiceBusRestProxy
*/
public function createServiceBusService($config);

/**
* Creates a WrapRestProxy using the passed configuration.
*
* @param WindowsAzure\Common\Configuration $config The configuration object.
*
* @return WindowsAzure\Wrap\WrapRestProxy
*/
public function createWrapService($config);
}

?>
6 changes: 4 additions & 2 deletions WindowsAzure/Common/Internal/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Resources
const SUBSCRIPTION_ID_NAME = 'SubscriptionID';
const CERTIFICATE_PATH_NAME = 'CertificatePath';
const SERVICE_MANAGEMENT_ENDPOINT_NAME = 'ServiceManagementEndpoint';
const SERVICE_BUS_ENDPOINT_NAME = 'Endpoint';
const SHARED_SECRET_ISSUER_NAME = 'SharedSecretIssuer';
const SHARED_SECRET_VALUE_NAME = 'SharedSecretValue';

// Messages
const INVALID_TYPE_MSG = 'The provided variable should be of type: ';
Expand Down Expand Up @@ -90,8 +93,6 @@ class Resources
const INVALID_BUILDER_MSG = 'Builder object must implement IServicesBuilder';
const INVALID_ACH_MSG = 'The provided access condition header is invalid';
const INVALID_RECEIVE_MODE_MSG = 'The receive message option is in neither RECEIVE_AND_DELETE nor PEEK_LOCK mode.';
const MISSING_CONFIG_SETTING_KEY_MSG = "Missing configuration setting %s which is required to create %sRestProxy.";
const MISSING_CONFIG_SETTING_VALUE_MSG = "The value of configuration setting %s can't be null or empty.";
const INVALID_CONFIG_URI = "The provided URI '%s' is invalid. It has to pass the check 'filter_var(<user_uri>, FILTER_VALIDATE_URL)'.";
const INVALID_CONFIG_VALUE = "The provided config value '%s' does not belong to the valid values subset:\n%s";
const INVALID_ACCOUNT_KEY_FORMAT = "The provided account key '%s' is not a valid base64 string. It has to pass the check 'base64_decode(<user_account_key>, true)'.";
Expand Down Expand Up @@ -206,6 +207,7 @@ class Resources
const SETTING_CONSTRAINT = 'SettingConstraint';
const DEV_STORE_URI = 'http://127.0.0.1';
const SERVICE_URI_FORMAT = "%s://%s.%s";
const WRAP_ENDPOINT_URI_FORMAT = "https://%s-sb.accesscontrol.windows.net/WRAPv0.9";

// Xml Namespaces
const WA_XML_NAMESPACE = 'http://schemas.microsoft.com/windowsazure';
Expand Down
240 changes: 240 additions & 0 deletions WindowsAzure/Common/Internal/ServiceBusSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<?php

/**
* LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
* @package WindowsAzure\Common\Internal
* @author Azure PHP SDK <azurephpsdk@microsoft.com>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://github.com/windowsazure/azure-sdk-for-php
*/

namespace WindowsAzure\Common\Internal;
use WindowsAzure\Common\Internal\Resources;

/**
* Represents the settings used to sign and access a request against the service
* bus.
*
* @category Microsoft
* @package WindowsAzure\Common\Internal
* @author Azure PHP SDK <azurephpsdk@microsoft.com>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @version Release: @package_version@
* @link https://github.com/windowsazure/azure-sdk-for-php
*/
class ServiceBusSettings extends ServiceSettings
{
/**
* @var string
*/
private $_serviceBusEndpointUri;

/**
* @var string
*/
private $_wrapEndpointUri;

/**
* @var string
*/
private $_wrapName;

/**
* @var string
*/
private $_wrapPassword;

/**
* @var string
*/
private $_namespace;

/**
* Validator for the SharedSecretValue setting. It has to be provided.
*
* @var array
*/
private static $_wrapPasswordSetting;

/**
* Validator for the SharedSecretIssuer setting. It has to be provided.
*
* @var array
*/
private static $_wrapNameSetting;

/**
* Validator for the Endpoint setting. Must be a valid Uri.
*
* @var array
*/
private static $_serviceBusEndpointSetting;

/**
* @var boolean
*/
protected static $isInitialized = false;

/**
* Holds the expected setting keys.
*
* @var array
*/
protected static $validSettingKeys = array();

/**
* Initializes static members of the class.
*
* @return none
*/
protected static function init()
{
self::$_serviceBusEndpointSetting = self::settingWithFunc(
Resources::SERVICE_BUS_ENDPOINT_NAME,
Validate::getIsValidUri()
);

self::$_wrapNameSetting = self::setting(
Resources::SHARED_SECRET_ISSUER_NAME
);

self::$_wrapPasswordSetting = self::setting(
Resources::SHARED_SECRET_VALUE_NAME
);

self::$validSettingKeys[] = Resources::SERVICE_BUS_ENDPOINT_NAME;
self::$validSettingKeys[] = Resources::SHARED_SECRET_ISSUER_NAME;
self::$validSettingKeys[] = Resources::SHARED_SECRET_VALUE_NAME;
}

/**
* Creates new service bus settings instance.
*
* @param string $serviceBusEndpoint The service bus endpoint uri.
* @param string $namespace The service namespace.
* @param string $wrapName The wrap name.
* @param string $wrapPassword The wrap password.
*/
public function __construct(
$serviceBusEndpoint,
$namespace,
$wrapName,
$wrapPassword
) {
$this->_namespace = $namespace;
$this->_serviceBusEndpointUri = $serviceBusEndpoint;
$this->_wrapEndpointUri = sprintf(
Resources::WRAP_ENDPOINT_URI_FORMAT,
$namespace
);
$this->_wrapName = $wrapName;
$this->_wrapPassword = $wrapPassword;
}

/**
* Creates a ServiceBusSettings object from the given connection string.
*
* @param string $connectionString The storage settings connection string.
*
* @return ServiceBusSettings
*/
public static function createFromConnectionString($connectionString)
{
$tokenizedSettings = self::parseAndValidateKeys($connectionString);

$matchedSpecs = self::matchedSpecification(
$tokenizedSettings,
self::allRequired(
self::$_serviceBusEndpointSetting,
self::$_wrapNameSetting,
self::$_wrapPasswordSetting
)
);
if ($matchedSpecs) {
// Parse the namespace part from the URI
$namespace = explode(
'.',
parse_url(
$tokenizedSettings[Resources::SERVICE_BUS_ENDPOINT_NAME],
PHP_URL_HOST
)
);
$namespace = $namespace[0];
return new ServiceBusSettings(
$tokenizedSettings[Resources::SERVICE_BUS_ENDPOINT_NAME],
$namespace,
$tokenizedSettings[Resources::SHARED_SECRET_ISSUER_NAME],
$tokenizedSettings[Resources::SHARED_SECRET_VALUE_NAME]
);
}

self::noMatch($connectionString);
}

/**
* Gets the service bus endpoint uri.
*
* @return string
*/
public function getServiceBusEndpointUri()
{
return $this->_serviceBusEndpointUri;
}

/**
* Gets the wrap endpoint uri.
*
* @return string
*/
public function getWrapEndpointUri()
{
return $this->_wrapEndpointUri;
}

/**
* Gets the wrap name.
*
* @return string
*/
public function getWrapName()
{
return $this->_wrapName;
}

/**
* Gets the wrap password.
*
* @return string
*/
public function getWrapPassword()
{
return $this->_wrapPassword;
}

/**
* Gets the namespace name.
*
* @return string
*/
public function getNamespace()
{
return $this->_namespace;
}
}

?>
17 changes: 13 additions & 4 deletions WindowsAzure/Common/Internal/ServiceManagementSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

namespace WindowsAzure\Common\Internal;
use WindowsAzure\Common\Internal\ConnectionStringParser;
use WindowsAzure\Common\Internal\Resources;

/**
Expand Down Expand Up @@ -77,6 +76,18 @@ class ServiceManagementSettings extends ServiceSettings
*/
private static $_subscriptionIdSetting;

/**
* @var boolean
*/
protected static $isInitialized = false;

/**
* Holds the expected setting keys.
*
* @var array
*/
protected static $validSettingKeys = array();

/**
* Initializes static members of the class.
*
Expand Down Expand Up @@ -153,9 +164,7 @@ public static function createFromConnectionString($connectionString)
);
}

throw new \RuntimeException(
sprintf(Resources::MISSING_CONNECTION_STRING_SETTINGS, $connectionString)
);
self::noMatch($connectionString);
}

/**
Expand Down
Loading

0 comments on commit 606ba27

Please sign in to comment.