-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add possibility to create an empty workspace
Signed-off-by: Oleksii Orel <oorel@redhat.com>
- Loading branch information
Showing
19 changed files
with
216 additions
and
41 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
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
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,58 @@ | ||
/* | ||
* Copyright (c) 2018-2021 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
import fetch from 'node-fetch'; | ||
import { baseApiPath } from '../constants/config'; | ||
import { yamlResolverSchema, namespacedSchema } from '../constants/schemas'; | ||
import { getDevWorkspaceClient, getToken } from './helper'; | ||
import { restParams } from '../typings/models'; | ||
import { getSchema } from '../services/helpers'; | ||
import { helpers } from '@eclipse-che/common'; | ||
|
||
const tags = ['Yaml Resolver']; | ||
|
||
export function registerYamlResolverApi(server: FastifyInstance) { | ||
server.post( | ||
`${baseApiPath}/namespace/:namespace/yaml/resolver`, | ||
getSchema({ tags, params: namespacedSchema, body: yamlResolverSchema }), | ||
async function (request: FastifyRequest) { | ||
const { url } = request.body as restParams.IYamlResolverParam; | ||
const { namespace } = request.params as restParams.INamespacedParam; | ||
const token = getToken(request); | ||
const { dockerConfigApi } = await getDevWorkspaceClient(token); | ||
|
||
try { | ||
// check user permissions | ||
await dockerConfigApi.read(namespace); | ||
} catch (e) { | ||
throw new Error(`User permissions error. ${helpers.errors.getMessage(e)}`); | ||
} | ||
|
||
const response = await fetch(url); | ||
if (!response.ok || response.body === null) { | ||
throw new Error(`Unexpected response ${response.statusText}`); | ||
} | ||
|
||
let outputData = ''; | ||
try { | ||
for await (const chunk of response.body) { | ||
outputData += chunk.toString(); | ||
} | ||
} catch (err) { | ||
throw new Error(`Type error. ${helpers.errors.getMessage(err)}`); | ||
} | ||
|
||
return outputData; | ||
}, | ||
); | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
packages/dashboard-frontend/src/services/dashboard-backend-client/yamlResolverApi.ts
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,28 @@ | ||
/* | ||
* Copyright (c) 2018-2021 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import axios from 'axios'; | ||
import { helpers } from '@eclipse-che/common'; | ||
import { prefix } from './const'; | ||
|
||
export async function getYamlResolver(namespace: string, location: string): Promise<string> { | ||
try { | ||
const url = new URL(location); | ||
const response = | ||
url.origin === window.location.origin | ||
? await axios.get(url.href) | ||
: await axios.post(`${prefix}/namespace/${namespace}/yaml/resolver`, { url: url.href }); | ||
return response.data; | ||
} catch (e) { | ||
throw `Failed to fetch yaml resolver'. ${helpers.errors.getMessage(e)}`; | ||
} | ||
} |
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.