forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added types for notebookimage and status (opendatahub-io#147)
Updated with REST api notebook image endpoints and new notebook image types.
- Loading branch information
Showing
4 changed files
with
190 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; | ||
import { | ||
addNotebook, | ||
deleteNotebook, | ||
getNotebook, | ||
getNotebooks, | ||
updateNotebook, | ||
} from './notebooksUtils'; | ||
|
||
export default async (fastify: FastifyInstance): Promise<void> => { | ||
fastify.get('/', async (request: FastifyRequest, reply: FastifyReply) => { | ||
return getNotebooks(fastify) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
reply.send(res); | ||
}); | ||
}); | ||
|
||
fastify.get('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => { | ||
return getNotebook(fastify, request) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
reply.send(res); | ||
}); | ||
}); | ||
|
||
fastify.delete('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => { | ||
return deleteNotebook(fastify, request) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
reply.send(res); | ||
}); | ||
}); | ||
|
||
fastify.put('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => { | ||
return updateNotebook(fastify, request) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
reply.send(res); | ||
}); | ||
}); | ||
|
||
fastify.post('/', async (request: FastifyRequest, reply: FastifyReply) => { | ||
return addNotebook(fastify, request) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((res) => { | ||
reply.send(res); | ||
}); | ||
}); | ||
}; |
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,86 @@ | ||
import { FastifyRequest } from 'fastify'; | ||
import { KubeFastifyInstance, Notebook } from '../../../types'; | ||
|
||
export const getNotebooks = async ( | ||
fastify: KubeFastifyInstance, | ||
): Promise<{ notebooks: Notebook[]; error: string }> => { | ||
const notebooks: Notebook[] = []; | ||
// const coreV1Api = fastify.kube.coreV1Api; | ||
// const namespace = fastify.kube.namespace; | ||
try { | ||
return { notebooks: notebooks, error: null }; | ||
} catch (e) { | ||
if (e.response?.statusCode !== 404) { | ||
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString()); | ||
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message }; | ||
} | ||
} | ||
}; | ||
|
||
export const getNotebook = async ( | ||
fastify: KubeFastifyInstance, | ||
request: FastifyRequest, | ||
): Promise<{ notebooks: Notebook; error: string }> => { | ||
const notebook: Notebook = { | ||
name: '', | ||
repo: '', | ||
}; | ||
// const coreV1Api = fastify.kube.coreV1Api; | ||
// const namespace = fastify.kube.namespace; | ||
try { | ||
return { notebooks: notebook, error: null }; | ||
} catch (e) { | ||
if (e.response?.statusCode !== 404) { | ||
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString()); | ||
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message }; | ||
} | ||
} | ||
}; | ||
|
||
export const addNotebook = async ( | ||
fastify: KubeFastifyInstance, | ||
request: FastifyRequest, | ||
): Promise<{ success: boolean; error: string }> => { | ||
// const coreV1Api = fastify.kube.coreV1Api; | ||
// const namespace = fastify.kube.namespace; | ||
try { | ||
return { success: true, error: null }; | ||
} catch (e) { | ||
if (e.response?.statusCode !== 404) { | ||
fastify.log.error('Unable to add notebook image: ' + e.toString()); | ||
return { success: false, error: 'Unable to add notebook image: ' + e.message }; | ||
} | ||
} | ||
}; | ||
|
||
export const deleteNotebook = async ( | ||
fastify: KubeFastifyInstance, | ||
request: FastifyRequest, | ||
): Promise<{ success: boolean; error: string }> => { | ||
// const coreV1Api = fastify.kube.coreV1Api; | ||
// const namespace = fastify.kube.namespace; | ||
try { | ||
return { success: true, error: null }; | ||
} catch (e) { | ||
if (e.response?.statusCode !== 404) { | ||
fastify.log.error('Unable to update notebook image: ' + e.toString()); | ||
return { success: false, error: 'Unable to update notebook image: ' + e.message }; | ||
} | ||
} | ||
}; | ||
|
||
export const updateNotebook = async ( | ||
fastify: KubeFastifyInstance, | ||
request: FastifyRequest, | ||
): Promise<{ success: boolean; error: string }> => { | ||
// const coreV1Api = fastify.kube.coreV1Api; | ||
// const namespace = fastify.kube.namespace; | ||
try { | ||
return { success: true, error: null }; | ||
} catch (e) { | ||
if (e.response?.statusCode !== 404) { | ||
fastify.log.error('Unable to update notebook image: ' + e.toString()); | ||
return { success: false, error: 'Unable to update notebook image: ' + e.message }; | ||
} | ||
} | ||
}; |
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