diff --git a/src/rest/remote-api.ts b/src/rest/remote-api.ts index 9718203..631d65c 100644 --- a/src/rest/remote-api.ts +++ b/src/rest/remote-api.ts @@ -157,6 +157,11 @@ export interface IRemoteAPI { * Returns a factory resolver. */ getFactoryResolver(url: string, overrideParams?: { [params: string]: string }): Promise; + + /** + * Check the factory related OAuth token and set (update) git-credentials. + */ + refreshFactoryOauthToken(url: string): Promise; generateSshKey(service: string, name: string): Promise; createSshKey(sshKeyPair: che.ssh.SshPair): Promise; getSshKey(service: string, name: string): Promise; @@ -374,6 +379,16 @@ export class RemoteAPI implements IRemoteAPI { }); } + refreshFactoryOauthToken(url: string): Promise { + return new Promise((resolve, reject) => { + this.remoteAPI.refreshFactoryOauthToken(url) + .then(() => resolve()) + .catch((error: AxiosError) => { + reject(new RequestError(error)); + }); + }); + } + public generateSshKey(service: string, name: string): Promise { return new Promise((resolve, reject) => { this.remoteAPI.generateSshKey(service, name) diff --git a/src/rest/resources.ts b/src/rest/resources.ts index d3fd15b..43e687f 100644 --- a/src/rest/resources.ts +++ b/src/rest/resources.ts @@ -70,6 +70,7 @@ export interface IResources { stop(workspaceId: string): AxiosPromise; getSettings(): AxiosPromise; getFactoryResolver(url: string, overrideParams?: { [params: string]: string }): AxiosPromise; + refreshFactoryOauthToken(url: string): AxiosPromise; generateSshKey(service: string, name: string): AxiosPromise; createSshKey(sshKeyPair: che.ssh.SshPair): AxiosPromise; getSshKey(service: string, name: string): AxiosPromise; @@ -204,6 +205,14 @@ export class Resources implements IResources { }); } + public refreshFactoryOauthToken(url: string): AxiosPromise { + return this.axios.request({ + method: 'POST', + baseURL: this.baseUrl, + url: `${this.factoryUrl}/token/refresh?url=${url}` + }); + } + public generateSshKey(service: string, name: string): AxiosPromise { return this.axios.request({ method: 'POST', diff --git a/test/client.spec.ts b/test/client.spec.ts index e23e48a..be48d7a 100644 --- a/test/client.spec.ts +++ b/test/client.spec.ts @@ -230,4 +230,16 @@ describe('RestAPI >', () => { }); }); + it('should call refresh factory token', async () => { + axios.request.mockImplementationOnce(() => Promise.resolve({status: 200})); + await restApi.refreshFactoryOauthToken('http://test-location'); + + expect(axios.request).toHaveBeenCalledTimes(1); + expect(axios.request).toHaveBeenCalledWith({ + 'baseURL': '/api', + 'method': 'POST', + 'url': '/factory/token/refresh/' + }); + }); + });