npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fabz26/plugin-sonarqube-backend

v0.2.23

Published

Welcome to the sonarqube-backend backend plugin!

Downloads

104

Readme

sonarqube-backend

Welcome to the sonarqube-backend backend plugin!

New Backend System

The Sonarqube backend plugin has support for the new backend system, here's how you can set that up:

In your packages/backend/src/index.ts make the following changes:

  import { createBackend } from '@backstage/backend-defaults';
  const backend = createBackend();
  // ... other feature additions
+ backend.add(import('@backstage-community/plugin-sonarqube-backend'));
  backend.start();

Integrating into a backstage instance

This plugin needs to be added to an existing backstage instance.

# From your Backstage root directory
yarn --cwd packages/backend add @backstage-community/plugin-sonarqube-backend

Typically, this means creating a src/plugins/sonarqube.ts file and adding a reference to it to src/index.ts in the backend package.

sonarqube.ts

import {
  createRouter,
  DefaultSonarqubeInfoProvider,
} from '@backstage-community/plugin-sonarqube-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  return await createRouter({
    logger: env.logger,
    sonarqubeInfoProvider: DefaultSonarqubeInfoProvider.fromConfig(env.config),
  });
}

src/index.ts

diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts
index 1942c36ad1..7fdc48ba24 100644
--- a/packages/backend/src/index.ts
+++ b/packages/backend/src/index.ts
@@ -50,6 +50,7 @@ import scaffolder from './plugins/scaffolder';
 import proxy from './plugins/proxy';
 import search from './plugins/search';
 import techdocs from './plugins/techdocs';
+import sonarqube from './plugins/sonarqube';
 import techInsights from './plugins/techInsights';
 import todo from './plugins/todo';
 import graphql from './plugins/graphql';
@@ -133,6 +134,7 @@ async function main() {
     createEnv('tech-insights'),
   );
   const permissionEnv = useHotMemoize(module, () => createEnv('permission'));
+  const sonarqubeEnv = useHotMemoize(module, () => createEnv('sonarqube'));

   const apiRouter = Router();
   apiRouter.use('/catalog', await catalog(catalogEnv));
@@ -152,6 +154,7 @@ async function main() {
   apiRouter.use('/badges', await badges(badgesEnv));
   apiRouter.use('/jenkins', await jenkins(jenkinsEnv));
   apiRouter.use('/permission', await permission(permissionEnv));
+  apiRouter.use('/sonarqube', await sonarqube(sonarqubeEnv));
   apiRouter.use(notFoundHandler());

   const service = createServiceBuilder(module)

This plugin must be provided with a SonarqubeInfoProvider, this is a strategy object for finding Sonarqube instances in configuration and retrieving data from an instance.

There is a standard one provided (DefaultSonarqubeInfoProvider), but the Integrator is free to build their own.

DefaultSonarqubeInfoProvider

Allows configuration of either a single or multiple global Sonarqube instances and annotating entities with the instance name. This instance name in the entities is optional, if not provided the default instance in configuration will be used. That allow to keep configuration from before multiple instances capability to keep working without changes.

Example - Single global instance

Config
sonarqube:
  baseUrl: https://sonarqube.example.com
  apiKey: 123456789abcdef0123456789abcedf012
Catalog
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: backstage
  annotations:
    sonarqube.org/project-key: YOUR_INSTANCE_NAME/YOUR_PROJECT_KEY

Example - Multiple global instance

The following will look for findings at https://special-project-sonarqube.example.com for the project of key YOUR_PROJECT_KEY.

Config
sonarqube:
  instances:
    - name: default
      baseUrl: https://default-sonarqube.example.com
      apiKey: 123456789abcdef0123456789abcedf012
    - name: specialProject
      baseUrl: https://special-project-sonarqube.example.com
      apiKey: abcdef0123456789abcedf0123456789ab
Catalog
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: backstage
  annotations:
    sonarqube.org/project-key: specialProject/YOUR_PROJECT_KEY

If the specialProject/ part is omitted (or replaced with default/), the Sonarqube instance of name default will be used.

The following config is an equivalent (but less clear) version of the above:

sonarqube:
  baseUrl: https://default-sonarqube.example.com
  apiKey: 123456789abcdef0123456789abcedf012
  instances:
    - name: specialProject
      baseUrl: https://special-project-sonarqube.example.com
      apiKey: abcdef0123456789abcedf0123456789ab

Example - Different frontend and backend URLs

In some instances, you might want to use one URL for the backend and another for the frontend. This can be achieved by using the optional externalBaseUrl property in the config.

Single instance config
sonarqube:
  baseUrl: https://sonarqube-internal.example.com
  externalBaseUrl: https://sonarqube.example.com
  apiKey: 123456789abcdef0123456789abcedf012
Multiple instance config
sonarqube:
  instances:
    - name: default
      baseUrl: https://default-sonarqube-internal.example.com
      externalBaseUrl: https://default-sonarqube.example.com
      apiKey: 123456789abcdef0123456789abcedf012
    - name: specialProject
      baseUrl: https://special-project-sonarqube.example.com
      apiKey: abcdef0123456789abcedf0123456789ab

Links