forked from PhaedrusTheGreek/transform_vis
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version avec acces es par routes server
- Loading branch information
Showing
7 changed files
with
290 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { PluginInitializerContext } from '../../../src/core/server'; | ||
import { TransformPlugin } from './plugin'; | ||
|
||
// This exports static code and TypeScript types, | ||
// as well as, Kibana Platform `plugin()` initializer. | ||
|
||
export function plugin(initializerContext: PluginInitializerContext) { | ||
return new TransformPlugin(initializerContext); | ||
} | ||
|
||
export { TransformPluginSetup, TransformPluginStart } from './types'; |
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,38 @@ | ||
import { | ||
PluginInitializerContext, | ||
CoreSetup, | ||
CoreStart, | ||
Plugin, | ||
Logger, | ||
} from '../../../src/core/server'; | ||
|
||
import { TransformPluginSetup, TransformPluginStart } from './types'; | ||
import { defineRoutes } from './routes'; | ||
import { Server } from 'http'; | ||
|
||
export class TransformPlugin | ||
implements Plugin<TransformPluginSetup, TransformPluginStart> { | ||
private readonly logger: Logger; | ||
|
||
constructor(initializerContext: PluginInitializerContext) { | ||
this.logger = initializerContext.logger.get(); | ||
} | ||
|
||
public setup(core: CoreSetup) { | ||
this.logger.debug('transform-vis: Setup'); | ||
console.log('transform-vis: Setup'); | ||
const router = core.http.createRouter(); | ||
// Register server side APIs | ||
defineRoutes(router); | ||
|
||
return {}; | ||
} | ||
|
||
public start(core: CoreStart) { | ||
console.log('transform-vis: Start'); | ||
this.logger.debug('transform-vis: Started'); | ||
return {}; | ||
} | ||
|
||
public stop() {} | ||
} |
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,211 @@ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { IRouter} from '../../../../src/core/server'; | ||
|
||
export function defineRoutes(router: IRouter) { | ||
router.get( | ||
{ | ||
path: '/api/transform_vis/example', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
return response.ok({ | ||
body: { | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} | ||
); | ||
router.get( | ||
{ | ||
path: '/api/transform_vis/cluster/_health', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
const data = await context.core.elasticsearch.legacy.client.callAsCurrentUser('cluster.health') | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
time: Object.keys(data.status) | ||
}, | ||
}); | ||
} | ||
); | ||
router.get( | ||
{ | ||
path: '/api/transform_vis/cat/indices', | ||
validate: false, | ||
}, | ||
async (context, request, response) => { | ||
const data = await context.core.elasticsearch.legacy.client.callAsCurrentUser('cat.indices') | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
data: data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} | ||
); | ||
|
||
//Create a mapping for a selected index | ||
router.post( | ||
{ | ||
path: '/api/transform_vis/{index}/_search', | ||
validate: { | ||
body: schema.any(), | ||
params: schema.any(), | ||
//query: schema.any() | ||
} | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
//console.log("bjacomy*************** ",request.params.index); | ||
//console.log("bjacomy*************** ",request.body); | ||
const data = await await context.core.elasticsearch.legacy.client.callAsCurrentUser('search', { | ||
index: request.params.index, | ||
body: request.body.body | ||
}); | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} catch (error) { | ||
console.log('****************** ', error); | ||
return response.ok({ | ||
body: { | ||
message: error | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
router.post( | ||
{ | ||
path: '/api/transform_vis/create/indice/{index}', | ||
//validate: false | ||
validate: { | ||
//body: schema.any(), | ||
params: schema.any() | ||
} | ||
}, | ||
|
||
|
||
async (context, request, response) => { | ||
try { | ||
//console.log('****************** create indice',request); | ||
const data = await context.core.elasticsearch.legacy.client.callAsCurrentUser('indices.create',{index: request.params.index}); | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
data: data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} catch (error) { | ||
//console.log('****************** ', error); | ||
return response.ok({ | ||
body: { | ||
message: error, | ||
} | ||
}); | ||
} | ||
} | ||
); | ||
|
||
//Create a mapping for a selected index | ||
router.post( | ||
{ | ||
path: '/api/transform_vis/{index}/_mapping', | ||
validate: { | ||
body: schema.any(), | ||
params: schema.any() | ||
} | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
//console.log('****************** create indice mapping',request); | ||
const data = await context.core.elasticsearch.legacy.client.callAsCurrentUser('indices.putMapping',{index: request.params.index, body: {"properties":request.body.body}}); | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} catch (error) { | ||
//console.log('****************** ', error); | ||
return response.ok({ | ||
body: { | ||
message: "error", | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
//Create a mapping for a selected index | ||
router.post( | ||
{ | ||
path: '/api/transform_vis/{index}/_bulk', | ||
validate: { | ||
body: schema.any(), | ||
params: schema.any(), | ||
query: schema.any() | ||
} | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
//console.log('****************** bulk indice',request); | ||
const pipeline = request.query.pipeline || false; | ||
const data = await await context.core.elasticsearch.legacy.client.callAsCurrentUser('bulk', { | ||
...(pipeline && { pipeline }), | ||
body: request.body | ||
}); | ||
//console.log('****************** ', data) | ||
return response.ok({ | ||
body: { | ||
data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} catch (error) { | ||
//console.log('****************** ', error); | ||
return response.ok({ | ||
body: { | ||
message: error | ||
} | ||
}); | ||
} | ||
|
||
}); | ||
|
||
//checking index | ||
router.post( | ||
{ | ||
path: '/api/transform_vis/{index}/_exists', | ||
validate: { | ||
params: schema.any(), | ||
} | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
const data = await context.core.elasticsearch.legacy.client.callAsCurrentUser('indices.get',{index: request.params.index}); | ||
return response.ok({ | ||
body: { | ||
data: data, | ||
time: new Date().toISOString(), | ||
}, | ||
}); | ||
} catch (error) { | ||
//console.log('****************** ', error); | ||
return response.ok({ | ||
body: { | ||
message: error, | ||
} | ||
}); | ||
} | ||
}); | ||
} |
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,4 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface TransformPluginSetup {} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface TransformPluginStart {} |