-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: throw error if user uses the static site token (#147)
* storage: throw error if user uses the static site token * CR: rename method to validateStorageOrganizationType
- Loading branch information
Showing
14 changed files
with
233 additions
and
149 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import asyncLock from "async-lock"; | ||
import SpheronApi from "./spheron-api"; | ||
import { TokenScope } from "./spheron-api/interfaces"; | ||
import { AppTypeEnum } from "./spheron-api/enums"; | ||
|
||
abstract class ScopeExtractor { | ||
private readonly api: SpheronApi; | ||
private scope: TokenScope | null = null; | ||
private lock: asyncLock; | ||
|
||
constructor(spheronApi: SpheronApi) { | ||
this.api = spheronApi; | ||
this.lock = new asyncLock(); | ||
} | ||
|
||
protected async getScopeFromToken(): Promise<TokenScope> { | ||
if (!this.scope) { | ||
await this.lock.acquire("getScopeFromToken", async () => { | ||
if (!this.scope) { | ||
this.scope = await this.api.getTokenScope(); | ||
} | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return this.scope!; | ||
} | ||
|
||
protected async getOrganizationIdFromToken(): Promise<string> { | ||
const scope = await this.getScopeFromToken(); | ||
return scope.organizations[0].id; | ||
} | ||
|
||
protected async getOrganizationTypeFromToken(): Promise<AppTypeEnum> { | ||
const scope = await this.getScopeFromToken(); | ||
return scope.organizations[0].appType; | ||
} | ||
} | ||
|
||
export { ScopeExtractor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.