/**
  * Creates new media services settings instance.
  *
  * @param string $accountName      The user provided account name.
  * @param string $accessKey        The user provided primary access key
  * @param string $endpointUri      The service management endpoint uri.
  * @param string $oauthEndpointUri The OAuth service endpoint uri.
  */
 public function __construct($accountName, $accessKey, $endpointUri = null, $oauthEndpointUri = null)
 {
     Validate::notNullOrEmpty($accountName, 'accountName');
     Validate::notNullOrEmpty($accessKey, 'accountKey');
     Validate::isString($accountName, 'accountName');
     Validate::isString($accessKey, 'accountKey');
     if ($endpointUri != null) {
         Validate::isValidUri($endpointUri);
     } else {
         $endpointUri = Resources::MEDIA_SERVICES_URL;
     }
     if ($oauthEndpointUri != null) {
         Validate::isValidUri($oauthEndpointUri);
     } else {
         $oauthEndpointUri = Resources::MEDIA_SERVICES_OAUTH_URL;
     }
     $this->_accountName = $accountName;
     $this->_accessKey = $accessKey;
     $this->_endpointUri = $endpointUri;
     $this->_oauthEndpointUri = $oauthEndpointUri;
 }
 /**
  * Creates a topic with specified topic info.  
  *
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780728
  * 
  * @param TopicInfo $topicInfo The information of the topic. 
  *
  * @return TopicInfo
  */
 public function createTopic($topicInfo)
 {
     Validate::notNullOrEmpty($topicInfo, 'topicInfo');
     $httpCallContext = new HttpCallContext();
     $httpCallContext->setMethod(Resources::HTTP_PUT);
     $httpCallContext->setPath($topicInfo->getTitle());
     $httpCallContext->addHeader(Resources::CONTENT_TYPE, Resources::ATOM_ENTRY_CONTENT_TYPE);
     $httpCallContext->addStatusCode(Resources::STATUS_CREATED);
     $topicDescriptionXml = XmlSerializer::objectSerialize($topicInfo->getTopicDescription(), 'TopicDescription');
     $entry = new Entry();
     $content = new Content($topicDescriptionXml);
     $content->setType(Resources::XML_CONTENT_TYPE);
     $entry->setContent($content);
     $entry->setAttribute(Resources::XMLNS, Resources::SERVICE_BUS_NAMESPACE);
     $xmlWriter = new \XMLWriter();
     $xmlWriter->openMemory();
     $entry->writeXml($xmlWriter);
     $httpCallContext->setBody($xmlWriter->outputMemory());
     $response = $this->sendContext($httpCallContext);
     $topicInfo = new TopicInfo();
     $topicInfo->parseXml($response->getBody());
     return $topicInfo;
 }
 /**
  * Sets the affinityGroup.
  * 
  * @param string $affinityGroup The affinityGroup.
  * 
  * @return none
  */
 public function setAffinityGroup($affinityGroup)
 {
     Validate::isString($affinityGroup, 'affinityGroup');
     Validate::notNullOrEmpty($affinityGroup, 'affinityGroup');
     $this->_affinityGroup = $affinityGroup;
 }
 /**
  * Unregisters a connection string source.
  * 
  * @param string $name The source name.
  * 
  * @return callable
  */
 public static function unregisterSource($name)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     self::_init();
     $sourceCallback = Utilities::tryGetValue(self::$_sources, $name);
     if (!is_null($sourceCallback)) {
         unset(self::$_sources[$name]);
     }
     return $sourceCallback;
 }
Beispiel #5
0
 /**
  * Creates a WRAP token manager with specified parameters. 
  *
  * @param string $wrapUri       The URI of the WRAP service.
  * @param string $wrapName      The user name of the WRAP service.
  * @param string $wrapPassword  The password of the WRAP service.
  * @param IWrap  $wrapRestProxy The WRAP service REST proxy.
  */
 public function __construct($wrapUri, $wrapName, $wrapPassword, $wrapRestProxy)
 {
     Validate::isString($wrapUri, 'wrapUri');
     Validate::isString($wrapName, 'wrapName');
     Validate::isString($wrapPassword, 'wrapPassword');
     Validate::notNullOrEmpty($wrapRestProxy, 'wrapRestProxy');
     $this->_wrapUri = $wrapUri;
     $this->_wrapName = $wrapName;
     $this->_wrapPassword = $wrapPassword;
     $this->_wrapRestProxy = $wrapRestProxy;
     $this->_activeTokens = array();
 }
 /**
  * Sets the deployment name.
  * 
  * @param string $deploymentName The deployment name.
  * 
  * @return none
  */
 public function setDeploymentName($deploymentName)
 {
     Validate::isString($deploymentName, 'deploymentName');
     Validate::notNullOrEmpty($deploymentName, 'deploymentName');
     $this->_deploymentName = $deploymentName;
 }
Beispiel #7
0
 /**
  * Creates a snapshot of a blob.
  * 
  * @param string                           $container The name of the container.
  * @param string                           $blob      The name of the blob.
  * @param Models\CreateBlobSnapshotOptions $options   The optional parameters.
  * 
  * @return Models\CreateBlobSnapshotResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx
  */
 public function createBlobSnapshot($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $expectedStatusCode = Resources::STATUS_CREATED;
     if (is_null($options)) {
         $options = new CreateBlobSnapshotOptions();
     }
     $queryParams[Resources::QP_COMP] = 'snapshot';
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->addMetadataHeaders($headers, $options->getMetadata());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $expectedStatusCode);
     return CreateBlobSnapshotResult::create($response->getHeader());
 }
 /**
  * Creates or updates the content of an existing file.
  *
  * Note that the default content type is application/octet-stream.
  *
  * @param string                   $share         The name of the share.
  * @param string                   $directoryPath The path of the directory.
  * @param string                   $file          The name of the file.
  * @param string|resource          $content       The content of the file.
  * @param Models\CreateFileOptions $options       The optional parameters.
  *
  * @return Models\CreateFileRangeResult|null
  *
  */
 public function createFileContents($share, $directoryPath, $file, $content, $options = null)
 {
     Validate::isString($share, 'share');
     Validate::isString($directoryPath, 'directoryPath');
     Validate::notNullOrEmpty($directoryPath, 'directoryPath');
     Validate::isString($file, 'file');
     Validate::isTrue(is_string($content) || is_resource($content), sprintf(Resources::INVALID_PARAM_MSG, 'content', 'string|resource'));
     $response = null;
     if (is_null($options)) {
         $options = new CreateFileOptions();
     }
     // This is for large or failsafe upload
     $end = 0;
     $offset = 0;
     // if threshold is lower than 4mb, honor threshold, else use 4mb
     $blockSize = 4194304;
     while (!$end) {
         if (is_resource($content)) {
             $body = fread($content, $blockSize);
             if (feof($content)) {
                 $end = 1;
             }
         } else {
             if (strlen($content) <= $blockSize) {
                 $body = $content;
                 $end = 1;
             } else {
                 $body = substr($content, 0, $blockSize);
                 $content = substr_replace($content, '', 0, $blockSize);
             }
         }
         $range = new FileRange($offset, $offset + strlen($body) - 1);
         $offset += $range->getLength();
         $response = $this->createFileRange($share, $directoryPath, $file, $range, $body, $options);
     }
     return $response;
 }
 /**
  * Cancels an in progress configuration change (update) or upgrade and returns
  * the deployment to its state before the upgrade or configuration change was
  * started.
  *
  * Note that you can rollback update or upgrade either by specifying the
  * deployment environment (staging or production), or by specifying the
  * deployment's unique name.
  *
  * @param string               $name    The hosted service name.
  * @param string               $mode    Specifies whether the rollback
  * should proceed automatically or not. Auto, The rollback proceeds without
  * further user input. Manual, You must call the walkUpgradeDomain API to apply
  * the rollback to each upgrade domain.
  * @param boolean              $force   Specifies whether the rollback
  * should proceed even when it will cause local data to be lost from some role
  * instances. True if the rollback should proceed; otherwise false if the
  * rollback should fail.
  * @param GetDeploymentOptions $options The optional parameters.
  *
  * @return none
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh403977.aspx
  */
 public function rollbackUpdateOrUpgrade($name, $mode, $force, $options)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     Validate::isString($mode, 'mode');
     Validate::isTrue(Mode::isValid($mode), Resources::INVALID_CHANGE_MODE_MSG);
     Validate::isBoolean($force, 'force');
     Validate::notNullOrEmpty($force, 'force');
     Validate::notNullOrEmpty($options, 'options');
     $xmlElements = array(Resources::XTAG_MODE => $mode, Resources::XTAG_FORCE => Utilities::booleanToString($force));
     $body = $this->_createRequestXml($xmlElements, Resources::XTAG_ROLLBACK_UPDATE_OR_UPGRADE);
     $context = new HttpCallContext();
     $context->setMethod(Resources::HTTP_POST);
     $context->setPath($this->_getDeploymentPath($name, $options) . '/');
     $context->addStatusCode(Resources::STATUS_ACCEPTED);
     $context->addQueryParameter(Resources::QP_COMP, Resources::QPV_ROLLBACK);
     $context->setBody($body);
     $context->addHeader(Resources::CONTENT_TYPE, Resources::XML_CONTENT_TYPE);
     assert(Utilities::endsWith($context->getPath(), '/'));
     $response = $this->sendContext($context);
     return AsynchronousOperationResult::create($response->getHeader());
 }
 /**
  * Adds insertOrMergeEntity operation.
  * 
  * @param string $table  The table name.
  * @param Entity $entity The entity instance.
  * 
  * @return none
  */
 public function addInsertOrMergeEntity($table, $entity)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($entity, 'entity');
     $operation = new BatchOperation();
     $type = BatchOperationType::INSERT_MERGE_ENTITY_OPERATION;
     $operation->setType($type);
     $operation->addParameter(BatchOperationParameterName::BP_TABLE, $table);
     $operation->addParameter(BatchOperationParameterName::BP_ENTITY, $entity);
     $this->addOperation($operation);
 }
Beispiel #11
0
 /**
  * Updates the visibility timeout of a message and/or the message contents.
  * 
  * @param string              $queueName                  The queue name.
  * @param string              $messageId                  The id of the message.
  * @param string              $popReceipt                 The valid pop receipt 
  * value returned from an earlier call to the Get Messages or Update Message
  * operation.
  * @param string              $messageText                The message contents.
  * @param int                 $visibilityTimeoutInSeconds Specifies the new 
  * visibility timeout value, in seconds, relative to server time. 
  * The new value must be larger than or equal to 0, and cannot be larger 
  * than 7 days. The visibility timeout of a message cannot be set to a value 
  * later than the expiry time. A message can be updated until it has been 
  * deleted or has expired.
  * @param QueueServiceOptions $options                    The optional 
  * parameters.
  * 
  * @return WindowsAzure\Common\Models\UpdateMessageResult
  */
 public function updateMessage($queueName, $messageId, $popReceipt, $messageText, $visibilityTimeoutInSeconds, $options = null)
 {
     Validate::isString($queueName, 'queueName');
     Validate::notNullOrEmpty($queueName, 'queueName');
     Validate::isString($messageId, 'messageId');
     Validate::notNullOrEmpty($messageId, 'messageId');
     Validate::isString($popReceipt, 'popReceipt');
     Validate::notNullOrEmpty($popReceipt, 'popReceipt');
     Validate::isString($messageText, 'messageText');
     Validate::isInteger($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     Validate::notNull($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $queueName . '/messages' . '/' . $messageId;
     $body = Resources::EMPTY_STRING;
     $statusCode = Resources::STATUS_NO_CONTENT;
     if (is_null($options)) {
         $options = new QueueServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibilityTimeoutInSeconds);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_POPRECEIPT, $popReceipt);
     if (!empty($messageText)) {
         $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE);
         $message = new QueueMessage();
         $message->setMessageText($messageText);
         $body = $message->toXml($this->dataSerializer);
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     $popReceipt = $response->getHeader(Resources::X_MS_POPRECEIPT);
     $timeNextVisible = $response->getHeader(Resources::X_MS_TIME_NEXT_VISIBLE);
     $date = Utilities::rfc1123ToDateTime($timeNextVisible);
     $result = new UpdateMessageResult();
     $result->setPopReceipt($popReceipt);
     $result->setTimeNextVisible($date);
     return $result;
 }
 private static function generateTestTokenJWT($template, $verificationKey, $contentKeyUUID, $tokenExpiration, $notBefore)
 {
     $token = array();
     foreach ($template->getRequiredClaims() as $claim) {
         $claimValue = $claim->getClaimValue();
         if ($claim->getClaimType() == TokenClaim::CONTENT_KEY_ID_CLAIM_TYPE) {
             Validate::notNullOrEmpty($contentKeyUUID, 'contentKeyUUID');
             $claimValue = $contentKeyUUID;
         }
         $token[$claim->getClaimType()] = $claimValue;
     }
     $token["iss"] = $template->getIssuer();
     $token["aud"] = $template->getAudience();
     $token["exp"] = $tokenExpiration;
     if (!empty($notBefore)) {
         $token["nbf"] = $notBefore;
     }
     return JWT::encode($token, $verificationKey->getKeyValue());
 }
 /**
  * Sets the role to upgrade name.
  * 
  * @param string $roleToUpgrade The role to upgrade name.
  * 
  * @return none
  */
 public function setRoleToUpgrade($roleToUpgrade)
 {
     Validate::isString($roleToUpgrade, 'roleToUpgrade');
     Validate::notNullOrEmpty($roleToUpgrade, 'roleToUpgrade');
     $this->_roleToUpgrade = $roleToUpgrade;
 }
 /**
  * @covers WindowsAzure\Common\Internal\Validate::notNull
  */
 public function testNotNullWithNull()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     Validate::notNullOrEmpty(null, 'variable');
 }
 /**
  * Returns the system properties associated with the specified affinity group.
  * 
  * @param string $name The affinity group name.
  * 
  * @return Models\GetAffinityGroupPropertiesResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee460789.aspx
  */
 public function getAffinityGroupProperties($name)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     $context = new HttpCallContext();
     $context->setMethod(Resources::HTTP_GET);
     $context->setPath($this->_getAffinityGroupPath($name));
     $context->addStatusCode(Resources::STATUS_OK);
     $response = $this->sendContext($context);
     $parsed = $this->dataSerializer->unserialize($response->getBody());
     return GetAffinityGroupPropertiesResult::create($parsed);
 }
 /**
  * Removes header from the HTTP request headers.
  * 
  * @param string $name The HTTP header name.
  * 
  * @return none
  */
 public function removeHeader($name)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     unset($this->_headers[$name]);
 }
 /**
  * Does batch of operations on the table service.
  * 
  * @param Models\BatchOperations     $batchOperations The operations to apply.
  * @param Models\TableServiceOptions $options         The optional parameters.
  * 
  * @return Models\BatchResult
  */
 public function batch($batchOperations, $options = null)
 {
     Validate::notNullOrEmpty($batchOperations, 'batchOperations');
     $method = Resources::HTTP_POST;
     $operations = $batchOperations->getOperations();
     $contexts = $this->_createOperationsContexts($operations);
     $mime = $this->_createBatchRequestBody($operations, $contexts);
     $body = $mime['body'];
     $headers = $mime['headers'];
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_ACCEPTED;
     $path = '$batch';
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     return BatchResult::create($response->getBody(), $operations, $contexts, $this->_atomSerializer, $this->_mimeSerializer);
 }