app: move api factories out to plugins

This commit is contained in:
Patrik Oldsberg
2020-09-04 17:09:41 +02:00
parent db291ab323
commit aa235dd154
12 changed files with 134 additions and 87 deletions
+14 -1
View File
@@ -14,8 +14,21 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import {
createPlugin,
createApiFactory,
discoveryApiRef,
} from '@backstage/core';
import { catalogApiRef } from './api/types';
import { CatalogClient } from './api/CatalogClient';
export const plugin = createPlugin({
id: 'catalog',
apis: [
createApiFactory({
implements: catalogApiRef,
deps: { discoveryApi: discoveryApiRef },
factory: ({ discoveryApi }) => new CatalogClient({ discoveryApi }),
}),
],
});
+12 -1
View File
@@ -13,13 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import { createPlugin, createApiFactory, configApiRef } from '@backstage/core';
import { circleCIRouteRef, circleCIBuildRouteRef } from './route-refs';
import BuildsPage from './pages/BuildsPage/BuildsPage';
import BuildWithStepsPage from './pages/BuildWithStepsPage/BuildWithStepsPage';
import { circleCIApiRef, CircleCIApi } from './api';
export const plugin = createPlugin({
id: 'circleci',
apis: [
createApiFactory({
implements: circleCIApiRef,
deps: { configApi: configApiRef },
factory: ({ configApi }) =>
new CircleCIApi(
`${configApi.getString('backend.baseUrl')}/proxy/circleci/api`,
),
}),
],
register({ router }) {
router.addRoute(circleCIRouteRef, BuildsPage);
router.addRoute(circleCIBuildRouteRef, BuildWithStepsPage);
+7 -1
View File
@@ -14,10 +14,15 @@
* limitations under the License.
*/
import { createPlugin, createRouteRef } from '@backstage/core';
import {
createPlugin,
createRouteRef,
createApiFactory,
} from '@backstage/core';
import { ProjectListPage } from './components/ProjectListPage';
import { ProjectDetailsPage } from './components/ProjectDetailsPage';
import { NewProjectPage } from './components/NewProjectPage';
import { GCPApiRef, GCPClient } from './api';
export const rootRouteRef = createRouteRef({
path: '/gcp-projects',
@@ -34,6 +39,7 @@ export const NewProjectRouteRef = createRouteRef({
export const plugin = createPlugin({
id: 'gcp-projects',
apis: [createApiFactory(GCPApiRef, new GCPClient())],
register({ router }) {
router.addRoute(rootRouteRef, ProjectListPage);
router.addRoute(ProjectRouteRef, ProjectDetailsPage);
+7 -1
View File
@@ -14,7 +14,12 @@
* limitations under the License.
*/
import { createPlugin, createRouteRef } from '@backstage/core';
import {
createPlugin,
createRouteRef,
createApiFactory,
} from '@backstage/core';
import { githubActionsApiRef, GithubActionsClient } from './api';
// TODO(freben): This is just a demo route for now
export const rootRouteRef = createRouteRef({
@@ -29,4 +34,5 @@ export const buildRouteRef = createRouteRef({
export const plugin = createPlugin({
id: 'github-actions',
apis: [createApiFactory(githubActionsApiRef, new GithubActionsClient())],
});
+5 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import { createPlugin, createApiFactory } from '@backstage/core';
import ProfileCatalog from './components/ProfileCatalog';
import ClusterPage from './components/ClusterPage';
import ClusterList from './components/ClusterList';
@@ -23,9 +23,13 @@ import {
gitOpsClusterDetailsRoute,
gitOpsClusterCreateRoute,
} from './routes';
import { gitOpsApiRef, GitOpsRestApi } from './api';
export const plugin = createPlugin({
id: 'gitops-profiles',
apis: [
createApiFactory(gitOpsApiRef, new GitOpsRestApi('http://localhost:3008')),
],
register({ router }) {
router.addRoute(gitOpsClusterListRoute, ClusterList);
router.addRoute(gitOpsClusterDetailsRoute, ClusterPage);
+15 -1
View File
@@ -14,8 +14,22 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import { createPlugin, createApiFactory } from '@backstage/core';
import { graphQlBrowseApiRef, GraphQLEndpoints } from './lib/api';
export const plugin = createPlugin({
id: 'graphiql',
apis: [
// GitLab is used as an example endpoint, but most plug
createApiFactory(
graphQlBrowseApiRef,
GraphQLEndpoints.from([
GraphQLEndpoints.create({
id: 'gitlab',
title: 'GitLab',
url: 'https://gitlab.com/api/graphql',
}),
]),
),
],
});
+17 -1
View File
@@ -14,8 +14,14 @@
* limitations under the License.
*/
import { createPlugin, createRouteRef } from '@backstage/core';
import {
createPlugin,
createRouteRef,
createApiFactory,
configApiRef,
} from '@backstage/core';
import { DetailedViewPage } from './pages/BuildWithStepsPage';
import { jenkinsApiRef, JenkinsApi } from './api';
export const buildRouteRef = createRouteRef({
path: '/jenkins/job',
@@ -24,6 +30,16 @@ export const buildRouteRef = createRouteRef({
export const plugin = createPlugin({
id: 'jenkins',
apis: [
createApiFactory({
implements: jenkinsApiRef,
deps: { configApi: configApiRef },
factory: ({ configApi }) =>
new JenkinsApi(
`${configApi.getString('backend.baseUrl')}/proxy/jenkins/api`,
),
}),
],
register({ router }) {
router.addRoute(buildRouteRef, DetailedViewPage);
},
+9 -1
View File
@@ -14,13 +14,21 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import { createPlugin, createApiFactory, configApiRef } from '@backstage/core';
import AuditList from './components/AuditList';
import AuditView from './components/AuditView';
import CreateAudit from './components/CreateAudit';
import { lighthouseApiRef, LighthouseRestApi } from './api';
export const plugin = createPlugin({
id: 'lighthouse',
apis: [
createApiFactory({
implements: lighthouseApiRef,
deps: { configApi: configApiRef },
factory: ({ configApi }) => LighthouseRestApi.fromConfig(configApi),
}),
],
register({ router }) {
router.registerRoute('/lighthouse', AuditList);
router.registerRoute('/lighthouse/audit/:id', AuditView);
+14 -1
View File
@@ -14,13 +14,26 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import {
createPlugin,
createApiFactory,
discoveryApiRef,
} from '@backstage/core';
import { rootRouteRef, entityRouteRef } from './routes';
import { RollbarHome } from './components/RollbarHome/RollbarHome';
import { RollbarProjectPage } from './components/RollbarProjectPage/RollbarProjectPage';
import { rollbarApiRef } from './api/RollbarApi';
import { RollbarClient } from './api/RollbarClient';
export const plugin = createPlugin({
id: 'rollbar',
apis: [
createApiFactory({
implements: rollbarApiRef,
deps: { discoveryApi: discoveryApiRef },
factory: ({ discoveryApi }) => new RollbarClient({ discoveryApi }),
}),
],
register({ router }) {
router.addRoute(rootRouteRef, RollbarHome);
router.addRoute(entityRouteRef, RollbarProjectPage);
+13 -1
View File
@@ -14,13 +14,25 @@
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import {
createPlugin,
createApiFactory,
discoveryApiRef,
} from '@backstage/core';
import { ScaffolderPage } from './components/ScaffolderPage';
import { TemplatePage } from './components/TemplatePage';
import { rootRoute, templateRoute } from './routes';
import { scaffolderApiRef, ScaffolderApi } from './api';
export const plugin = createPlugin({
id: 'scaffolder',
apis: [
createApiFactory({
implements: scaffolderApiRef,
deps: { discoveryApi: discoveryApiRef },
factory: ({ discoveryApi }) => new ScaffolderApi({ discoveryApi }),
}),
],
register({ router }) {
router.addRoute(rootRoute, ScaffolderPage);
router.addRoute(templateRoute, TemplatePage);
+17 -1
View File
@@ -29,7 +29,13 @@
* limitations under the License.
*/
import { createPlugin, createRouteRef } from '@backstage/core';
import {
createPlugin,
createRouteRef,
createApiFactory,
configApiRef,
} from '@backstage/core';
import { techdocsStorageApiRef, TechDocsStorageApi } from './api';
export const rootRouteRef = createRouteRef({
path: '',
@@ -48,4 +54,14 @@ export const rootCatalogDocsRouteRef = createRouteRef({
export const plugin = createPlugin({
id: 'techdocs',
apis: [
createApiFactory({
implements: techdocsStorageApiRef,
deps: { configApi: configApiRef },
factory: ({ configApi }) =>
new TechDocsStorageApi({
apiOrigin: configApi.getString('techdocs.storageUrl'),
}),
}),
],
});