51 $mparams = array_merge( [
54 parent::__construct( $mparams );
61 if ( !$this->authCreds ) {
64 if ( $this->authErrorTimestamp !==
null ) {
65 if ( ( time() - $this->authErrorTimestamp ) < 60 ) {
68 $this->authErrorTimestamp =
null;
72 return ( ( time() - $this->authSessionTimestamp ) > $this->params[
'swiftAuthTTL'] );
76 $this->authSessionTimestamp = 0;
77 [ $rcode, $rdesc, $rhdrs, , ] = $req[
'response'];
78 if ( $rcode >= 200 && $rcode <= 299 ) {
80 'auth_token' => $rhdrs[
'x-auth-token'],
81 'storage_url' => $rhdrs[
'x-storage-url']
83 $this->authSessionTimestamp = time();
85 } elseif ( $rcode === 403 ) {
86 $this->authCachedStatus = 401;
87 $this->authCachedReason =
'Authorization Required';
88 $this->authErrorTimestamp = time();
91 $this->authCachedStatus = $rcode;
92 $this->authCachedReason = $rdesc;
93 $this->authErrorTimestamp = time();
102 public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
104 $firstReq = reset( $reqs );
105 if ( $firstReq && count( $reqs ) == 1 && isset( $firstReq[
'isAuth'] ) ) {
111 if ( $needsAuth ===
true ) {
115 $idGeneratorFunc() => [
117 'url' => $this->params[
'swiftAuthUrl'] .
"/v1.0",
119 'x-auth-user' => $this->params[
'swiftUser'],
120 'x-auth-key' => $this->params[
'swiftKey'] ],
125 } elseif ( $needsAuth !==
false ) {
129 foreach ( $reqs as $key => $req ) {
137 $result[$key] = $req;
142 foreach ( $reqs as $key => $req ) {
146 $parts = array_map(
'rawurlencode', explode(
'/', $req[
'url'] ) );
147 $req[
'url'] = $this->authCreds[
'storage_url'] .
'/' . implode(
'/', $parts );
148 $req[
'headers'][
'x-auth-token'] = $this->authCreds[
'auth_token'];
149 $result[$key] = $req;
157 public function onResponses( array $reqs, Closure $idGeneratorFunc ) {
158 $firstReq = reset( $reqs );
159 if ( $firstReq && count( $reqs ) == 1 && isset( $firstReq[
'isAuth'] ) ) {
165 $result = $this->
onRequests( $firstReq[
'chain'], $idGeneratorFunc );
169 foreach ( $firstReq[
'chain'] as $key => $req ) {
177 $result[$key] = $req;
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Example virtual rest service for OpenStack Swift.
int null $authCachedStatus
string null $authCachedReason
onResponses(array $reqs, Closure $idGeneratorFunc)
Mangle or replace virtual HTTP(S) requests which have been responded to.
__construct(array $params)
int $authSessionTimestamp
UNIX timestamp.
onRequests(array $reqs, Closure $idGeneratorFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.This method should mangle any of th...
applyAuthResponse(array $req)
int null $authErrorTimestamp
UNIX timestamp.
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
array $params
Key/value map.