-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'switch-httpClient-to-esri-library' of https://github.co…
…m/ngageoint/mage-server into switch-httpClient-to-esri-library
- Loading branch information
Showing
10 changed files
with
992 additions
and
1,225 deletions.
There are no files selected for viewing
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
119 changes: 0 additions & 119 deletions
119
plugins/arcgis/service/src/ArcGISIdentityManagerFactory.ts
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request' | ||
import { FeatureServiceConfig } from './ArcGISConfig' | ||
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api' | ||
|
||
export interface ArcGISIdentityService { | ||
getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> | ||
updateIndentityManagers(): Promise<void> | ||
} | ||
|
||
export function createArcGISIdentityService( | ||
stateRepo: PluginStateRepository<any> | ||
): ArcGISIdentityService { | ||
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map() | ||
|
||
return { | ||
async getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> { | ||
let cached = await identityManagerCache.get(featureService.url) | ||
if (!cached) { | ||
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager) | ||
const promise = identityManager.getUser().then(() => identityManager) | ||
identityManagerCache.set(featureService.url, promise) | ||
return promise | ||
} else { | ||
return cached | ||
} | ||
}, | ||
async updateIndentityManagers() { | ||
const config = await stateRepo.get() | ||
for (let [url, persistedIdentityManagerPromise] of identityManagerCache) { | ||
const persistedIdentityManager = await persistedIdentityManagerPromise | ||
const featureService: FeatureServiceConfig | undefined = config.featureServices.find((service: FeatureServiceConfig) => service.url === url) | ||
if (featureService) { | ||
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager) | ||
if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) { | ||
featureService.identityManager = persistedIdentityManager.serialize() | ||
await stateRepo.put(config) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function getPortalUrl(featureService: FeatureServiceConfig | string): string { | ||
const url = getFeatureServiceUrl(featureService) | ||
return `https://${url.hostname}/arcgis/sharing/rest` | ||
} | ||
|
||
export function getServerUrl(featureService: FeatureServiceConfig | string): string { | ||
const url = getFeatureServiceUrl(featureService) | ||
return `https://${url.hostname}/arcgis` | ||
} | ||
|
||
export function getFeatureServiceUrl(featureService: FeatureServiceConfig | string): URL { | ||
const url = typeof featureService === 'string' ? featureService : featureService.url | ||
return new URL(url) | ||
} |
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
Oops, something went wrong.