-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support register to the new backend system
Signed-off-by: mingfu <[email protected]>
- Loading branch information
Showing
6 changed files
with
418 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './service/router'; | ||
export * from './processor'; | ||
export * from './plugin'; |
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,71 @@ | ||
import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; | ||
import request from 'supertest'; | ||
import { gitlabPlugin } from './plugin'; | ||
import { rest } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
|
||
describe('gitlabPlugin', () => { | ||
const mockServer = setupServer( | ||
rest.get( | ||
'https://non-existing-example.com/api/v4/projects/434', | ||
(req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
url: req.url.toString(), | ||
headers: req.headers.all(), | ||
}) | ||
); | ||
} | ||
) | ||
); | ||
|
||
beforeAll(async () => { | ||
mockServer.listen({ | ||
onUnhandledRequest: ({ headers }, print) => { | ||
if (headers.get('User-Agent') === 'supertest') { | ||
return; | ||
} | ||
print.error(); | ||
}, | ||
}); | ||
}); | ||
|
||
afterAll(() => mockServer.close()); | ||
|
||
it('can serve values from config', async () => { | ||
const fakeConfig = { | ||
integrations: { | ||
gitlab: [ | ||
{ | ||
host: 'non-existing-example.com', | ||
apiBaseUrl: 'https://non-existing-example.com/api/v4', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const { server } = await startTestBackend({ | ||
features: [ | ||
gitlabPlugin(), | ||
mockServices.rootConfig.factory({ data: fakeConfig }), | ||
], | ||
}); | ||
|
||
const agent = request.agent(server); | ||
agent.set('User-Agent', 'supertest'); | ||
const response = await agent.get( | ||
'/api/gitlab/rest/non-existing-example.com/projects/434' | ||
); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toEqual({ | ||
headers: { | ||
'accept-encoding': 'gzip, deflate', | ||
connection: 'close', | ||
host: 'non-existing-example.com', | ||
'user-agent': 'supertest', | ||
}, | ||
url: 'https://non-existing-example.com/api/v4/projects/434', | ||
}); | ||
}); | ||
}); |
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,47 @@ | ||
import { | ||
coreServices, | ||
createBackendModule, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; | ||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { GitlabFillerProcessor } from './processor'; | ||
import { createRouter } from './service/router'; | ||
|
||
export const catalogPluginGitlabFillerProcessorModule = createBackendModule({ | ||
pluginId: 'catalog', | ||
moduleId: 'gitlabFillerProcessor', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
config: coreServices.rootConfig, | ||
extensionPoint: catalogProcessingExtensionPoint, | ||
}, | ||
async init({ config, extensionPoint }) { | ||
extensionPoint.addProcessor(new GitlabFillerProcessor(config)); | ||
}, | ||
}); | ||
}, | ||
}); | ||
|
||
export const gitlabPlugin = createBackendPlugin({ | ||
pluginId: 'gitlab', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
http: coreServices.httpRouter, | ||
logger: coreServices.logger, | ||
config: coreServices.rootConfig, | ||
}, | ||
async init({ config, logger, http }) { | ||
const winstonLogger = loggerToWinstonLogger(logger); | ||
http.use( | ||
await createRouter({ | ||
logger: winstonLogger, | ||
config, | ||
}) | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.