Skip to content

Commit

Permalink
Make sure importing credentials updates default HTTP X-Auth-Token hea…
Browse files Browse the repository at this point in the history
…der; fixes #236
  • Loading branch information
jamiehannaford committed Dec 6, 2013
1 parent 3a0ab64 commit bc7c0eb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/OpenCloud/OpenStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ public function authenticate()
$this->setExpiration(strtotime($body->access->token->expires));
$this->setCatalog($body->access->serviceCatalog);

// Add to default headers for future reference
$this->setDefaultOption('headers/X-Auth-Token', (string) $this->getToken());
// Set X-Auth-Token HTTP request header
$this->updateTokenHeader();

/**
* In some cases, the tenant name/id is not returned
Expand Down Expand Up @@ -340,6 +340,7 @@ public function importCredentials(array $values)
{
if (!empty($values['token'])) {
$this->setToken($values['token']);
$this->updateTokenHeader();
}
if (!empty($values['expiration'])) {
$this->setExpiration($values['expiration']);
Expand All @@ -352,6 +353,18 @@ public function importCredentials(array $values)
}
}

/**
* Sets the X-Auth-Token header. If no value is explicitly passed in, the current token is used.
*
* @param string $token Optional value of token.
* @return void
*/
private function updateTokenHeader($token = null)
{
$token = $token ?: $this->getToken();
$this->setDefaultOption('headers/X-Auth-Token', (string) $token);
}

/**
* Creates a new ObjectStore object (Swift/Cloud Files)
*
Expand Down Expand Up @@ -421,4 +434,4 @@ public function volumeService($name = null, $region = null, $urltype = null)
));
}

}
}

0 comments on commit bc7c0eb

Please sign in to comment.