Skip to content

Commit

Permalink
Fall back to kudu's API for _master key if runtime API is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmelsayed committed May 10, 2017
1 parent 08547aa commit b83ea11
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions AzureFunctions.AngularClient/src/app/shared/function-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,31 @@ export class FunctionApp {
let authHeader = new Headers();
authHeader.append('Authorization', `Bearer ${token}`);
return this._http.get(`${this.mainSiteUrl}/admin/host/systemkeys/_master`, { headers: authHeader })
.retryWhen(error => error.scan((errorCount : number, err: FunctionsResponse) => {
.catch((error: FunctionsResponse) => {
if (error.status === 405) {
// If the result from calling the API above is 405, that means they are running on an older runtime.
// It should be safe to call kudu for the master key since they won't be using slots.
return this._http.get(`${this._scmUrl}/api/functions/admin/masterKey`, { headers: this.getScmSiteHeaders() });
} else {
throw error;
}
})
.retryWhen(error => error.scan((errorCount: number, err: FunctionsResponse) => {
if (err.isHandled || err.status < 500 || errorCount >= 10) {
throw err;
} else {
return errorCount + 1;
}
}, 0).delay(1000))
.do((r: Response) => {
let key: { name: string, value: string } = r.json();
this.masterKey = key.value;
})
// Since we fall back to kudu above, use a union of kudu and runtime types.
const key: { name: string, value: string } & { masterKey: string } = r.json();
if (key.masterKey) {
this.masterKey = key.masterKey;
} else {
this.masterKey = key.value;
}
});
}).do(() =>{
this._broadcastService.broadcast<string>(BroadcastEvent.ClearError, ErrorIds.unableToRetrieveRuntimeKeyFromScm);
},
Expand Down

0 comments on commit b83ea11

Please sign in to comment.