diff --git a/.changeset/angry-jobs-serve.md b/.changeset/angry-jobs-serve.md new file mode 100644 index 0000000000..ec2976dccd --- /dev/null +++ b/.changeset/angry-jobs-serve.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-cost-insights': patch +--- + +In the README, a old path of the `sidebar` was updated to the current path. diff --git a/.changeset/early-hats-rest.md b/.changeset/early-hats-rest.md new file mode 100644 index 0000000000..dfe685ea77 --- /dev/null +++ b/.changeset/early-hats-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-user-settings': patch +--- + +Added new `` to show the result of the `identityApi.getBackstageIdentity()` call to help debug ownership issues. The new card has been added to the user settings page. diff --git a/.changeset/gorgeous-trees-sparkle.md b/.changeset/gorgeous-trees-sparkle.md new file mode 100644 index 0000000000..962cc22021 --- /dev/null +++ b/.changeset/gorgeous-trees-sparkle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +Table component no longer has drag and drop columns by default diff --git a/.changeset/many-yaks-occur.md b/.changeset/many-yaks-occur.md new file mode 100644 index 0000000000..d8f617bf11 --- /dev/null +++ b/.changeset/many-yaks-occur.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-dynatrace': minor +--- + +Adds Dynatrace plugin diff --git a/.changeset/search-pull-rank.md b/.changeset/search-pull-rank.md new file mode 100644 index 0000000000..995225698e --- /dev/null +++ b/.changeset/search-pull-rank.md @@ -0,0 +1,50 @@ +--- +'@backstage/create-app': patch +--- + +It's now possible to pass result item components a `rank`, which is captured by the analytics API when a user clicks on a search result. To apply this change, update your `/packages/app/src/components/search/SearchPage.tsx` in the following way: + +```diff +// ... + + {({ results }) => ( + +- {results.map(({ type, document, highlight }) => { ++ {results.map(({ type, document, highlight, rank }) => { + switch (type) { + case 'software-catalog': + return ( + + ); + case 'techdocs': + return ( + + ); + default: + return ( + + ); + } + })} + + )} + +// ... +``` + +If you have implemented a custom Search Modal or other custom search experience, you will want to make similar changes in those components. diff --git a/.changeset/search-rank-and-file.md b/.changeset/search-rank-and-file.md new file mode 100644 index 0000000000..bfad6a63ad --- /dev/null +++ b/.changeset/search-rank-and-file.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search-common': patch +--- + +Added an optional `rank` attribute to the `Result` type. This represents the result rank (starting at 1) for a given result in a result set for a given search. diff --git a/.changeset/search-rank-choice-voting.md b/.changeset/search-rank-choice-voting.md new file mode 100644 index 0000000000..2754d149e7 --- /dev/null +++ b/.changeset/search-rank-choice-voting.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-search-backend': patch +'@backstage/plugin-search-backend-module-elasticsearch': patch +'@backstage/plugin-search-backend-module-pg': patch +'@backstage/plugin-search-backend-node': patch +--- + +The provided search engine now adds a pagination-aware `rank` value to all results. diff --git a/.changeset/search-rankly-my-dear.md b/.changeset/search-rankly-my-dear.md new file mode 100644 index 0000000000..c528c567b1 --- /dev/null +++ b/.changeset/search-rankly-my-dear.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-catalog': patch +'@backstage/plugin-search': patch +'@backstage/plugin-techdocs': patch +--- + +In order to simplify analytics on top of the search experience in Backstage, the provided `<*ResultListItem />` component now captures a `discover` analytics event instead of a `click` event. This event includes the result rank as its `value` and, like a click, the URL/path clicked to as its `to` attribute. diff --git a/.changeset/twenty-avocados-refuse.md b/.changeset/twenty-avocados-refuse.md new file mode 100644 index 0000000000..dab68d5a10 --- /dev/null +++ b/.changeset/twenty-avocados-refuse.md @@ -0,0 +1,5 @@ +--- +'@backstage/create-app': patch +--- + +Updated the auth backend setup in the template to include a guest sign-in resolver in order to make it quicker to get up and running with a basic sign-in setup. There is no need to update existing apps to match this change, but in case you want to use the guest sign-in resolver you can find it at https://backstage.io/docs/auth/identity-resolver#guest-sign-in-resolver diff --git a/.changeset/warm-lions-retire.md b/.changeset/warm-lions-retire.md new file mode 100644 index 0000000000..23cbf9d78b --- /dev/null +++ b/.changeset/warm-lions-retire.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch +--- + +Introduce additional JsonValue types to be storable as facts. This enables the possibility to store more complex objects for fact checking purposes. The rules engine supports walking keyed object values directly to create rules and checks + +Modify facts database table to have a more restricted timestamp precision for cases where the postgres server isn't configured to contain such value. This fixes the issue where in some cases `maxItems` lifecycle condition didn't work as expected. diff --git a/.github/vale/Vocab/Backstage/accept.txt b/.github/vale/Vocab/Backstage/accept.txt index 198a16e566..8428dc2d0e 100644 --- a/.github/vale/Vocab/Backstage/accept.txt +++ b/.github/vale/Vocab/Backstage/accept.txt @@ -85,6 +85,8 @@ dockerfiles Dockerize dockerode Docusaurus +dynatrace +Dynatrace ecco env Env @@ -302,6 +304,7 @@ superfences Superfences superset supertype +storable talkdesk Talkdesk tasklist diff --git a/ADOPTERS.md b/ADOPTERS.md index 011d06981b..4e5785b8d5 100644 --- a/ADOPTERS.md +++ b/ADOPTERS.md @@ -159,4 +159,5 @@ _If you're using Backstage in your organization, please try to add your company | [Doctolib](https://doctolib.engineering/) | [@djiit](https://github.com/djiit) | Rails modularization effort awareness, tech organization discoverability. Improving the daily workflows and collaboration processes of our engineers. | | [Twilio](https://www.twilio.com) | [Kyle Smith](https://github.com/knksmith57) | Developer portal, universal software catalog, and centralized taxonomy platform. | | [OVHcloud](https://www.ovhcloud.com/fr/) | [Jean-Philippe Blary](https://github.com/blaryjp), [Arnaud Bauer](mailto:arnaud.bauer@ovhcloud.com), [Flavien Chantelot](https://github.com/Dorn-) | We're providing Backstage to our collaborators to ease their daily jobs, and let them extends it using plugins. | +| [Procter & Gamble](https://us.pg.com/) | [Binita Nayak](https://github.com/binitan), [Josh Rose](https://github.com/joshuarose), [RJ Winkler](https://github.com/rjwink) | P&G leverages Backstage to build internal developer portal to ensure developers' happiness. This developer portal shall act as single source of information needed by development teams to seamlessly create, find and maintain their software components/resources/documentation. | | [SANS Institute](https://www.sans.org) | [Christopher Klewin](mailto:cklewin@sans.org) | Developer portal for centralized visibility, reporting, and tooling across multiple organizations. | diff --git a/app-config.yaml b/app-config.yaml index eb51c59847..5919deb1ee 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -115,6 +115,11 @@ proxy: headers: Authorization: Basic ${GOCD_AUTH_CREDENTIALS} + '/dynatrace': + target: https://your.dynatrace.instance.com/api/v2 + headers: + Authorization: 'Api-Token ${DYNATRACE_ACCESS_TOKEN}' + organization: name: My Company @@ -131,6 +136,9 @@ techdocs: publisher: type: 'local' # Alternatives - 'googleGcs' or 'awsS3' or 'azureBlobStorage' or 'openStackSwift'. Read documentation for using alternatives. +dynatrace: + baseUrl: https://your.dynatrace.instance.com + sentry: organization: my-company diff --git a/docs/auth/add-auth-provider.md b/docs/auth/add-auth-provider.md index bd2bcd1694..eb8973bec1 100644 --- a/docs/auth/add-auth-provider.md +++ b/docs/auth/add-auth-provider.md @@ -1,9 +1,113 @@ --- id: add-auth-provider -title: Adding authentication providers -description: Documentation on Adding authentication providers +title: Contributing New Providers +description: Documentation on adding new authentication providers --- +> NOTE: The primary audience for this documentation are contributors to the main +> Backstage project that want to add support for new authentication providers. +> While you can follow it to implement your own custom providers it is much +> more advanced than using our built-in providers. + +## How Does Authentication Work? + +The Backstage application can use various external authentication providers for +authentication. An external provider is wrapped using an +`AuthProviderRouteHandlers` interface for handling authentication. This +interface consists of four methods. Each of these methods is hosted at an +endpoint (by default) `/api/auth/[provider]/method`, where `method` performs a +certain operation as follows: + +``` + /auth/[provider]/start -> Initiate a login from the web page + /auth/[provider]/handler/frame -> Handle a finished authentication operation + /auth/[provider]/refresh -> Refresh the validity of a login + /auth/[provider]/logout -> Log out a logged-in user +``` + +The flow is as follows: + +1. A user attempts to sign in. +2. A popup window is opened, pointing to the `auth` endpoint. That endpoint does + initial preparations and then re-directs the user to an external + authenticator, still inside the popup. +3. The authenticator validates the user and returns the result of the validation + (success OR failure), to the wrapper's endpoint (`handler/frame`). +4. The `handler/frame` rendered webpage will issue the appropriate response to + the webpage that opened the popup window, and the popup is closed. +5. The user signs out by clicking on a UI interface and the webpage makes a + request to logout the user. + +## Implementing Your Own Auth Wrapper + +The core interface of any auth wrapper is the `AuthProviderRouteHandlers` +interface. This interface has four methods corresponding to the API described in +the initial section. Any auth wrapper will have to implement this interface. + +When initiating a login, a pop-up window is created by the frontend, to allow +the user to initiate a login. This login request is done to the `/start` +endpoint which is handled by the `start` method. + +The `start` method re-directs to the external auth provider who authenticates +the request and re-directs the request to the `/frame/handler` endpoint, which +is handled by the `frameHandler` method. + +The `frameHandler` returns an HTML response, containing a script that does a +`postMessage` to the frontend window, containing the result of the request. +The `WebMessageResponse` type is the message sent by the `postMessage` to the +frontend. + +A `postMessageResponse` utility function wraps the logic of generating a +`postMessage` response that ensures that CORS is successfully handled. This +function takes an `express.Response`, a `WebMessageResponse` and the URL of the +frontend (`appOrigin`) as parameters and return an HTML page with the script and +the message. + +There is a helper class for [OAuth2](https://oauth.net/2/) based authentication providers, [OAuthAdapter](../reference/plugin-auth-backend.oauthadapter.md). This class implements the `AuthProviderRouteHandlers` interface +for you, and instead requires you to implement [OAuthHandlers](../reference/plugin-auth-backend.oauthhandlers.md), which +is significantly easier. + +### Auth Environment Separation + +The concept of an `env` is core to the way the auth backend works. It uses an +`env` query parameter to identify the environment in which the application is +running (`development`, `staging`, `production`, etc). Each runtime can +simultaneously support multiple environments at the same time and the right +handler for each request is identified and dispatched to, based on the `env` +parameter. + +`OAuthEnvironmentHandler` is a utility wrapper for an `OAuthHandlers` that +implements the `AuthProviderRouteHandlers` interface while supporting multiple +`env`s. + +To instantiate OAuth providers (the same but for different environments), use +`OAuthEnvironmentHandler.mapConfig`. It's a helper to iterate over a +configuration object that is a map of environments to configurations. See one of +the existing OAuth providers for an example of how it is used. + +Given the following configuration: + +```yaml +development: + clientId: abc + clientSecret: secret +production: + clientId: xyz + clientSecret: supersecret +``` + +The `OAuthEnvironmentHandler.mapConfig(config, envConfig => ...)` call will +split the config by the top level `development` and `production` keys, and pass +on each block as `envConfig`. + +For convenience, the `AuthProviderFactory` is a factory function that has to be +implemented which can then generate a `AuthProviderRouteHandlers` for a given +provider. + +All of the supported providers provide an `AuthProviderFactory` that returns an +`OAuthEnvironmentHandler`, capable of handling authentication for multiple +environments. + ## Passport We chose [Passport](http://www.passportjs.org/) as our authentication platform @@ -46,13 +150,13 @@ plugins/auth-backend/src/providers/providerA **`plugins/auth-backend/src/providers/providerA/provider.ts`** defines the provider class which implements a handler for the chosen framework. -#### Adding an OAuth based provider +### Adding an OAuth based provider If we're adding an `OAuth` based provider we would implement the -[OAuthProviderHandlers](#OAuthProviderHandlers) interface. By implementing this +`OAuthHandlers` interface. By implementing this interface we can use the `OAuthProvider` class provided by `lib/oauth`, meaning we don't need to implement the full -[AuthProviderRouteHandlers](#AuthProviderRouteHandlers) interface that providers +`AuthProviderRouteHandlers` interface that providers otherwise need to implement. The provider class takes the provider's options as a class parameter. It also @@ -65,7 +169,7 @@ export type ProviderAProviderOptions = OAuthProviderOptions & { // extra options here } -export class ProviderAAuthProvider implements OAuthProviderHandlers { +export class ProviderAAuthProvider implements OAuthHandlers { private readonly _strategy: ProviderAStrategy; constructor(options: ProviderAProviderOptions) { @@ -87,13 +191,10 @@ export class ProviderAAuthProvider implements OAuthProviderHandlers { } ``` -#### Adding an non-OAuth based provider - -_**Note**: We have prioritized OAuth-based providers and non-OAuth providers -should be considered experimental._ +### Adding an non-OAuth based provider An non-`OAuth` based provider could implement -[AuthProviderRouteHandlers](#AuthProviderRouteHandlers) instead. +`AuthProviderRouteHandlers` instead. ```ts type ProviderAOptions = { @@ -119,13 +220,19 @@ export class ProviderAAuthProvider implements AuthProviderRouteHandlers { } ``` -#### Factory function +#### Integration Wrapper -Each provider exports a factory function that instantiates the provider. The -factory should implement [AuthProviderFactory](#AuthProviderFactory), which +Each provider exports an object that provides a way to create new instances +of the provider, along with related utilities like predefined sign-in resolvers. + +The object is created using `createAuthProviderIntegration`, with the most +important part being the `create` method that acts as the factory function +for our provider. + +The factory should return an implementation of `AuthProviderFactory`, which passes in a object with utilities for configuration, logging, token issuing, etc. The factory should return an implementation of -[AuthProviderRouteHandlers](#AuthProviderRouteHandlers). +`AuthProviderRouteHandlers`. The factory is what decides the mapping from [static configuration](../conf/index.md) to the creation of auth providers. For @@ -133,48 +240,70 @@ example, OAuth providers use `OAuthEnvironmentHandler` to allow for multiple different configurations, one for each environment, which looks like this; ```ts -export const createOktaProvider: AuthProviderFactory = ({ - globalConfig, - config, - tokenIssuer, -}) => - OAuthEnvironmentHandler.mapConfig(config, envConfig => { - // read options from config - const clientId = envConfig.getString('clientId'); - const clientSecret = envConfig.getString('clientSecret'); +export const okta = createAuthProviderIntegration({ + create(options?: { + /** + * The profile transformation function used to verify and convert the auth response + * into the profile that will be presented to the user. + */ + authHandler?: AuthHandler; - // instantiate our OAuthProviderHandlers implementation - const provider = new OktaAuthProvider({ - audience, - clientId, - clientSecret, - callbackUrl, - }); + /** + * Configure sign-in for this provider, without it the provider can not be used to sign users in. + */ + signIn?: { + /** + * Maps an auth result to a Backstage identity for the user. + */ + resolver: SignInResolver; + }; + }) { + return ({ providerId, globalConfig, config, resolverContext }) => + OAuthEnvironmentHandler.mapConfig(config, envConfig => { + // read options from config + const clientId = envConfig.getString('clientId'); + const clientSecret = envConfig.getString('clientSecret'); - // Wrap the OAuthProviderHandlers with OAuthProvider, which implements AuthProviderRouteHandlers - return OAuthProvider.fromConfig(globalConfig, provider, { - providerId, - tokenIssuer, - }); - }); + // Use provided auth handler, or create a default one + const authHandler: AuthHandler = options?.authHandler + ? options.authHandler + : async ({ fullProfile, params }) => ({ + profile: makeProfileInfo(fullProfile, params.id_token), + }); + + // instantiate our OAuthHandlers implementation + const provider = new OktaAuthProvider({ + audience, + clientId, + clientSecret, + callbackUrl, + authHandler, + signInResolver: options?.signIn?.resolver, + resolverContext, + }); + + // Wrap the OAuthHandlers with OAuthProvider, which implements AuthProviderRouteHandlers + return OAuthProvider.fromConfig(globalConfig, provider, { + providerId, + tokenIssuer, + }); + }); + }, + resolvers: { + /** + * Looks up the user by matching their email local part to the entity name. + */ + emailLocalPartMatchingUserEntityName: () => commonByEmailLocalPartResolver, + + // ... additional predefined resolvers + }, +}); ``` The purpose of the different environments is to allow for a single auth-backend to serve as the authentication service for multiple different frontend environments, such as local development, staging, and production. -The factory function for other providers can be a lot simpler, as they might not -have configuration for each environment. Looking something like this: - -```ts -export const createProviderAProvider: AuthProviderFactory = ({ config }) => { - const a = config.getString('a'); - const b = config.getString('b'); - - return new ProviderAAuthProvider({ a, b }); -}; -``` - #### Verify Callback > Strategies require what is known as a verify callback. The purpose of a verify @@ -202,7 +331,7 @@ export { createProviderAProvider } from './provider'; **`plugins/auth-backend/src/providers/factories.ts`** When the `auth-backend` starts it sets up routing for all the available providers by calling -`createAuthProviderRouter` on each provider. You need to import the factory +the factory function of each provider. You need to import the factory function from the provider and add it to the factory: ```ts @@ -232,51 +361,3 @@ You can `curl -i localhost:7007/api/auth/providerA/start` and which should provide a `302` redirect with a `Location` header. Paste the URL from that header into a web browser and you should be able to trigger the authorization flow. - ---- - -##### OAuthProviderHandlers - -```ts -export interface OAuthProviderHandlers { - start( - req: express.Request, - options: Record, - ): Promise; - handler(req: express.Request): Promise<{ - response: AuthResponse; - refreshToken?: string; - }>; - refresh?( - refreshToken: string, - scope: string, - ): Promise>; - logout?(): Promise; -} -``` - -##### AuthProviderRouteHandlers - -```ts -export interface AuthProviderRouteHandlers { - start(req: express.Request, res: express.Response): Promise; - frameHandler(req: express.Request, res: express.Response): Promise; - refresh?(req: express.Request, res: express.Response): Promise; - logout(req: express.Request, res: express.Response): Promise; -} -``` - -##### AuthProviderFactory - -```ts -export type AuthProviderFactoryOptions = { - globalConfig: AuthProviderConfig; - config: Config; - logger: Logger; - tokenIssuer: TokenIssuer; -}; - -export type AuthProviderFactory = ( - options: AuthProviderFactoryOptions, -) => AuthProviderRouteHandlers; -``` diff --git a/docs/auth/auth-backend-classes.md b/docs/auth/auth-backend-classes.md deleted file mode 100644 index 5b5950f6c3..0000000000 --- a/docs/auth/auth-backend-classes.md +++ /dev/null @@ -1,206 +0,0 @@ ---- -id: auth-backend-classes -title: Auth backend classes -description: Documentation on Auth backend classes ---- - -## How Does Authentication Work? - -The Backstage application can use various external authentication providers for -authentication. An external provider is wrapped using an -`AuthProviderRouteHandlers` interface for handling authentication. This -interface consists of four methods. Each of these methods is hosted at an -endpoint (by default) `/api/auth/[provider]/method`, where `method` performs a -certain operation as follows: - -``` - /auth/[provider]/start -> Initiate a login from the web page - /auth/[provider]/handler/frame -> Handle a finished authentication operation - /auth/[provider]/refresh -> Refresh the validity of a login - /auth/[provider]/logout -> Log out a logged-in user -``` - -The flow is as follows: - -1. A user attempts to sign in. -2. A popup window is opened, pointing to the `auth` endpoint. That endpoint does - initial preparations and then re-directs the user to an external - authenticator, still inside the popup. -3. The authenticator validates the user and returns the result of the validation - (success OR failure), to the wrapper's endpoint (`handler/frame`). -4. The `handler/frame` rendered b´webpage will issue the appropriate response to - the webpage that opened the popup window, and the popup is closed. -5. The user signs out by clicking on a UI interface and the webpage makes a - request to logout the user. - -There are currently two different classes for two authentication mechanisms that -implement this interface: an `OAuthAdapter` for [OAuth](https://oauth.net/2/) -based mechanisms and a `SAMLAuthProvider` for -[SAML](http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html). - -If you do not have an `OAuth2` or `SAML` based authentication provider, look in -the section [below](#implementing-your-own-auth-wrapper). - -### OAuth Mechanisms - -For more information on how these methods are used and for which purpose, refer -to the [OAuth documentation](oauth.md). - -Currently OAuth is assumed to be the de facto authentication mechanism for -Backstage based applications. - -Backstage comes with a "batteries-included" set of supported commonly used OAuth -providers: Okta, GitHub, Google, GitLab, and a generic OAuth2 provider. For a -list of available providers, look at the available wrappers in -`backstage/plugins/auth-backend/src/providers/`. - -All of these use the **authorization flow** of OAuth2 to implement -authentication. - -If your authentication provider is any of the above mentioned providers, you can -configure them by setting the right variables in `app-config.yaml` under the -`auth` section. - -### SAML - -The SAML Provider is currently under development. Additional validation and -profile handling is still required before use in production. - -To configure the SAML Auth provider, look at the configuration parameters -supported by -[Passport-SAML](https://github.com/node-saml/passport-saml#config-parameter-details) -under the `auth.providers.saml` key - -For security reasons, validate that the response from the IdP is indeed signed -by also providing the `cert` configuration. - -### Configuration - -Each authentication provider (except SAML) needs six parameters: an OAuth client -ID, a client secret, an authorization endpoint, a token endpoint, an optional -list of scopes (as a string separated by spaces) that may be required by the -OAuth2 Server to enable end-user sign-on, and an app origin. The app origin is -the URL at which the frontend of the application is hosted, and it is read from -the `app.baseUrl` config. This is required because the application opens a popup -window to perform the authentication, and once the flow is completed, the popup -window sends a `postMessage` to the frontend application to indicate the result -of the operation. Also this URL is used to verify that authentication requests -are coming from only this endpoint. - -These values are configured via the `app-config.yaml` present in the root of -your app folder. - -``` -auth: - providers: - google: - development: - clientId: ${AUTH_GOOGLE_CLIENT_ID} - clientSecret: ${AUTH_GOOGLE_CLIENT_SECRET} - github: - development: - clientId: ${AUTH_GITHUB_CLIENT_ID} - clientSecret: ${AUTH_GITHUB_CLIENT_SECRET} - enterpriseInstanceUrl: ${AUTH_GITHUB_ENTERPRISE_INSTANCE_URL} - gitlab: - development: - clientId: ${AUTH_GITLAB_CLIENT_ID} - oauth2: - development: - clientId: ${AUTH_OAUTH2_CLIENT_ID} - clientSecret: ${AUTH_OAUTH2_CLIENT_SECRET} - authorizationUrl: ${AUTH_OAUTH2_AUTH_URL} - tokenUrl: ${AUTH_OAUTH2_TOKEN_URL} - scope: ${AUTH_OAUTH2_SCOPE} - saml: - entryPoint: ${AUTH_SAML_ENTRY_POINT} - issuer: ${AUTH_SAML_ISSUER} - ... -``` - -## Implementing Your Own Auth Wrapper - -The core interface of any auth wrapper is the `AuthProviderRouteHandlers` -interface. This interface has four methods corresponding to the API described in -the initial section. Any auth wrapper will have to implement this interface. - -When initiating a login, a pop-up window is created by the frontend, to allow -the user to initiate a login. This login request is done to the `/start` -endpoint which is handled by the `start` method. - -The `start` method re-directs to the external auth provider who authenticates -the request and re-directs the request to the `/frame/handler` endpoint, which -is handled by the `frameHandler` method. - -The `frameHandler` returns an HTML response, containing a script that does a -`postMessage` to the frontend's window, containing the result of the request. -The `WebMessageResponse` type is the message sent by the `postMessage` to the -frontend. - -A `postMessageResponse` utility function wraps the logic of generating a -`postMessage` response that ensures that CORS is successfully handled. This -function takes an `express.Response`, a `WebMessageResponse` and the URL of the -frontend (`appOrigin`) as parameters and return an HTML page with the script and -the message. - -### OAuth Wrapping Interfaces. - -Each OAuth external provider is supported by a corresponding -[Passport](https://github.com/jaredhanson/passport) strategy. For a generic -OAuth2 provider, passport has a `passport-oauth2` strategy. The strategy class -handles the implementation details of working with each provider. - -Each strategy is wrapped by an `OAuthHandlers` interface. - -This interface cannot be directly used as an Express HTTP request handler. To do -so, `OAuthHandlers` are wrapped in an `OAuthAdapter`, which implements the -`AuthProviderRouterHandlers` interface. - -#### Env - -The concept of an `env` is core to the way the auth backend works. It uses an -`env` query parameter to identify the environment in which the application is -running (`development`, `staging`, `production`, etc). Each runtime can -simultaneously support multiple environments at the same time and the right -handler for each request is identified and dispatched to, based on the `env` -parameter. - -`OAuthEnvironmentHandler` is a utility wrapper for an `OAuthHandlers` that -implements the `AuthProviderRouteHandlers` interface while supporting multiple -`env`s. - -To instantiate OAuth providers (the same but for different environments), use -`OAuthEnvironmentHandler.mapConfig`. It's a helper to iterate over a -configuration object that is a map of environments to configurations. See one of -the existing OAuth providers for an example of how it is used. - -Given the following configuration: - -```yaml -development: - clientId: abc - clientSecret: secret -production: - clientId: xyz - clientSecret: supersecret -``` - -The `OAuthEnvironmentHandler.mapConfig(config, envConfig => ...)` call will -split the config by the top level `development` and `production` keys, and pass -on each block as `envConfig`. - -For convenience, the `AuthProviderFactory` is a factory function that has to be -implemented which can then generate a `AuthProviderRouteHandlers` for a given -provider. - -All of the supported providers provide an `AuthProviderFactory` that returns an -`OAuthEnvironmentHandler`, capable of handling authentication for multiple -environments. - -### OAuth2 Provider - -The `oauth2` provider abstracts a generic **OAuth2 + OIDC** based authentication -provider. What this means is that after the application has been given -permission by the user, the `authorization code` will be exchanged for an -`access_token`, a `refresh_token` and an `id_token`. This `id_token` is used to -obtain an email id of the user, which is then used for creating the session. diff --git a/docs/auth/identity-resolver.md b/docs/auth/identity-resolver.md index c7f90d0bbf..2a256ae8fd 100644 --- a/docs/auth/identity-resolver.md +++ b/docs/auth/identity-resolver.md @@ -12,6 +12,34 @@ If you want to use an auth provider to sign in users, you need to explicitly con it have sign-in enabled and also tell it how the external identities should be mapped to user identities within Backstage. +## Guest Sign-In Resolver + +Backstage projects created with `npx @backstage/create-app` come configured with a +sign-in resolver for GitHub guest access. This resolver makes all users share +a single "guest" identity and is only intended as a minimum requirement to quickly +get up and running. You can replace `github` for any of the other providers if you need. + +This resolver should not be used in production, as it uses a single shared identity, +and has no restrictions on who is able to sign-in. Be sure to read through the rest +of this page to understand the Backstage identity system once you need to install +a resolver for your production environment. + +The guest resolver can be useful for testing purposes too, and it looks like this: + +```ts +signIn: { + resolver(_, ctx) { + const userRef = 'user:default/guest' + return ctx.issueToken({ + claims: { + sub: userRef, + ent: [userRef], + }, + }), + }, +}, +``` + ## Backstage User Identity A user identity within Backstage is built up from two pieces of information, a diff --git a/docs/auth/oauth2-proxy/provider.md b/docs/auth/oauth2-proxy/provider.md index 966596e268..e57ea96b26 100644 --- a/docs/auth/oauth2-proxy/provider.md +++ b/docs/auth/oauth2-proxy/provider.md @@ -6,7 +6,7 @@ description: Adding OAuth2Proxy as an authentication provider in Backstage --- The Backstage `@backstage/plugin-auth-backend` package comes with an -`oauth2proxy` authentication provider that can authenticate users by using a +`oauth2Proxy` authentication provider that can authenticate users by using a [oauth2-proxy](https://github.com/oauth2-proxy/oauth2-proxy) in front of an actual Backstage instance. This enables to reuse existing authentications within a cluster. In general the `oauth2-proxy` supports all OpenID Connect providers, @@ -21,17 +21,17 @@ The provider configuration can be added to your `app-config.yaml` under the root ```yaml auth: providers: - oauth2proxy: {} + oauth2Proxy: {} ``` Right now no configuration options are supported, but the empty object is needed to enable the provider in the auth backend. -To use the `oauth2proxy` provider you must also configure it with a sign-in resolver. +To use the `oauth2Proxy` provider you must also configure it with a sign-in resolver. For more information about the sign-in process in general, see the [Sign-in Identities and Resolvers](../identity-resolver.md) documentation. -For the `oauth2proxy` provider, the sign-in result is quite different than other providers. +For the `oauth2Proxy` provider, the sign-in result is quite different than other providers. Because it's a proxy provider that can be configured to forward information through arbitrary headers, the auth result simply just gives you access to the HTTP headers of the incoming request. Using these you can either extract the information directly, @@ -40,19 +40,22 @@ or grab ID or access tokens to look up additional information and/or validate th A simple sign-in resolver might for example look like this: ```ts -providers.oauth2Proxy.create({ - signIn: { - async resolver({ result }, ctx) { - const name = result.getHeader('x-forwarded-user'); - if (!name) { - throw new Error('Request did not contain a user') - } - return ctx.signInWithCatalogUser({ - entityRef: { name }, - }); +providerFactories: { + ...defaultAuthProviderFactories, + oauth2Proxy: providers.oauth2Proxy.create({ + signIn: { + async resolver({ result }, ctx) { + const name = result.getHeader('x-forwarded-user'); + if (!name) { + throw new Error('Request did not contain a user') + } + return ctx.signInWithCatalogUser({ + entityRef: { name }, + }); + }, }, - }, -}), + }), +}, ``` ## Adding the provider to the Backstage frontend @@ -65,7 +68,7 @@ installed in `packages/app/src/App.tsx` like this: const app = createApp({ components: { -+ SignInPage: props => , ++ SignInPage: props => , ``` See the [Sign-In with Proxy Providers](../index.md#sign-in-with-proxy-providers) section for more information. diff --git a/docs/features/software-templates/writing-templates.md b/docs/features/software-templates/writing-templates.md index 0163877a8b..27e6e76817 100644 --- a/docs/features/software-templates/writing-templates.md +++ b/docs/features/software-templates/writing-templates.md @@ -397,6 +397,26 @@ There's also the ability to pass additional scopes when requesting the `oauth` token from the user, which you can do on a per-provider basis, in case your template can be published to multiple providers. +### Accessing the signed-in users details + +Sometimes when authoring templates, you'll want to access the user that is running the template, and get details from the profile or the users `Entity` in the Catalog. + +If you have enabled a sign in provider and have a [sign in resolver](../../auth/identity-resolver.md) that points to a user in the Catalog, then you can use the `${{ user.entity }}` templating expression to access the raw entity from the Catalog. + +This can be particularly useful if you have processors setup in the Catalog to write `spec.profile.email` of the `User Entities` to reference them and pass them into actions like below: + +```yaml + steps: + action: publish:github + ... + input: + ... + gitAuthorName: ${{ user.entity.metadata.name }} + gitAuthorEmail: ${{ user.entity.spec.profile.email }} +``` + +You also have access to `user.entity.metadata.annotations` too, so if you have some other additional information stored in there, you reference those too. + ### The Owner Picker When the scaffolder needs to add new components to the catalog, it needs to have diff --git a/docs/plugins/analytics.md b/docs/plugins/analytics.md index d5fd02a46d..ccb4e5c5a7 100644 --- a/docs/plugins/analytics.md +++ b/docs/plugins/analytics.md @@ -52,11 +52,12 @@ learn how to contribute the integration yourself! The following table summarizes events that, depending on the plugins you have installed, may be captured. -| Action | Provided By | Subject | -| ---------- | -------------- | --------------------------------------------------- | -| `navigate` | Backstage Core | The URL of the page that was navigated to | -| `click` | Backstage Core | The text of the link that was clicked on | -| `search` | Backstage Core | The search term entered in any search bar component | +| Action | Subject | Other Notes | +| ---------- | --------------------------------------------------- | ----------------------------------------------------------------- | +| `navigate` | The URL of the page that was navigated to | | +| `click` | The text of the link that was clicked on | The `to` attribute represents the URL clicked to | +| `search` | The search term entered in any search bar component | The `searchTypes` attribute holds `types` constraining the search | +| `discover` | The title of the search result that was clicked on | The `value` is the result rank. A `to` attribute is also provided | If there is an event you'd like to see captured, please [open an issue][add-event] describing the event you want to see and the questions it diff --git a/microsite/data/plugins/dynatrace.yaml b/microsite/data/plugins/dynatrace.yaml new file mode 100644 index 0000000000..3ab85ae1eb --- /dev/null +++ b/microsite/data/plugins/dynatrace.yaml @@ -0,0 +1,12 @@ +--- +title: Dynatrace +author: TELUS +authorUrl: https://github.com/telus +category: Monitoring +description: View monitoring info from dynatrace for services in your software catalog. +documentation: https://github.com/backstage/backstage/tree/master/plugins/dynatrace +iconUrl: img/dynatrace.svg +npmPackageName: '@backstage/plugin-dynatrace' +tags: + - dynatrace + - monitoring diff --git a/microsite/sidebars.json b/microsite/sidebars.json index 6cbe079def..8c460c7d3d 100644 --- a/microsite/sidebars.json +++ b/microsite/sidebars.json @@ -259,11 +259,10 @@ "auth/oauth2-proxy/provider" ] }, - "auth/add-auth-provider", "auth/identity-resolver", "auth/auth-backend", "auth/oauth", - "auth/auth-backend-classes", + "auth/add-auth-provider", "auth/troubleshooting", "auth/glossary" ], diff --git a/microsite/static/img/dynatrace.svg b/microsite/static/img/dynatrace.svg new file mode 100644 index 0000000000..de114c0005 --- /dev/null +++ b/microsite/static/img/dynatrace.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mkdocs.yml b/mkdocs.yml index 3bd83832f7..04d62d32d4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -156,11 +156,10 @@ nav: - OneLogin: 'auth/onelogin/provider.md' - OAuth2Proxy: 'auth/oauth2-proxy/provider.md' - Bitbucket: 'auth/bitbucket/provider.md' - - Adding authentication providers: 'auth/add-auth-provider.md' - Sign in resolvers: 'auth/identity-resolver.md' - Auth backend: 'auth/auth-backend.md' - OAuth and OpenID Connect: 'auth/oauth.md' - - Auth backend classes: 'auth/auth-backend-classes.md' + - Contributing New Providers: 'auth/add-auth-provider.md' - Troubleshooting Auth: 'auth/troubleshooting.md' - Glossary: 'auth/glossary.md' - Deployment: diff --git a/packages/app/package.json b/packages/app/package.json index f07a4e590d..db53e99e0f 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -29,6 +29,7 @@ "@backstage/plugin-cloudbuild": "^0.3.6-next.1", "@backstage/plugin-code-coverage": "^0.1.33-next.1", "@backstage/plugin-cost-insights": "^0.11.28-next.2", + "@backstage/plugin-dynatrace": "^0.0.0", "@backstage/plugin-explore": "^0.3.37-next.1", "@backstage/plugin-gcalendar": "^0.3.2-next.1", "@backstage/plugin-gcp-projects": "^0.3.25-next.1", diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx index 799fe3e4d9..1958aabd2e 100644 --- a/packages/app/src/components/catalog/EntityPage.tsx +++ b/packages/app/src/components/catalog/EntityPage.tsx @@ -73,6 +73,10 @@ import { isCloudbuildAvailable, } from '@backstage/plugin-cloudbuild'; import { EntityCodeCoverageContent } from '@backstage/plugin-code-coverage'; +import { + DynatraceTab, + isDynatraceAvailable, +} from '@backstage/plugin-dynatrace'; import { EntityGithubActionsContent, EntityRecentGithubActionsRunsCard, @@ -447,6 +451,14 @@ const serviceEntityPage = ( + + + + ); @@ -495,6 +507,14 @@ const websiteEntityPage = ( + + + + void }) => { {({ results }) => ( - {results.map(({ type, document, highlight }) => { + {results.map(({ type, document, highlight, rank }) => { let resultItem; switch (type) { case 'software-catalog': @@ -194,6 +194,7 @@ export const SearchModal = ({ toggleModal }: { toggleModal: () => void }) => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); break; @@ -204,6 +205,7 @@ export const SearchModal = ({ toggleModal }: { toggleModal: () => void }) => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); break; @@ -213,6 +215,7 @@ export const SearchModal = ({ toggleModal }: { toggleModal: () => void }) => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); } diff --git a/packages/app/src/components/search/SearchPage.tsx b/packages/app/src/components/search/SearchPage.tsx index 9a2e85bd8c..053fa81da8 100644 --- a/packages/app/src/components/search/SearchPage.tsx +++ b/packages/app/src/components/search/SearchPage.tsx @@ -132,7 +132,7 @@ const SearchPage = () => { {({ results }) => ( - {results.map(({ type, document, highlight }) => { + {results.map(({ type, document, highlight, rank }) => { switch (type) { case 'software-catalog': return ( @@ -141,6 +141,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); case 'techdocs': @@ -150,6 +151,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); default: @@ -158,6 +160,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); } diff --git a/packages/create-app/templates/default-app/packages/app/src/components/search/SearchPage.tsx b/packages/create-app/templates/default-app/packages/app/src/components/search/SearchPage.tsx index 1b3bf5b77d..928b8201ea 100644 --- a/packages/create-app/templates/default-app/packages/app/src/components/search/SearchPage.tsx +++ b/packages/create-app/templates/default-app/packages/app/src/components/search/SearchPage.tsx @@ -112,7 +112,7 @@ const SearchPage = () => { {({ results }) => ( - {results.map(({ type, document, highlight }) => { + {results.map(({ type, document, highlight, rank }) => { switch (type) { case 'software-catalog': return ( @@ -120,6 +120,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); case 'techdocs': @@ -128,6 +129,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); default: @@ -136,6 +138,7 @@ const SearchPage = () => { key={document.location} result={document} highlight={highlight} + rank={rank} /> ); } diff --git a/packages/create-app/templates/default-app/packages/backend/src/plugins/auth.ts b/packages/create-app/templates/default-app/packages/backend/src/plugins/auth.ts index 13f18c55e9..159116d7b8 100644 --- a/packages/create-app/templates/default-app/packages/backend/src/plugins/auth.ts +++ b/packages/create-app/templates/default-app/packages/backend/src/plugins/auth.ts @@ -18,18 +18,36 @@ export default async function createPlugin( providerFactories: { ...defaultAuthProviderFactories, - // This overrides the default GitHub auth provider with a custom one. - // Since the options are empty it will behave just like the default - // provider, but if you uncomment the `signIn` section you will enable - // sign-in via GitHub. This particular configuration uses a resolver - // that matches the username to the user entity name. See the auth - // documentation for more details on how to enable and customize sign-in: + // This replaces the default GitHub auth provider with a customized one. + // The `signIn` option enables sign-in for this provider, using the + // identity resolution logic that's provided in the `resolver` callback. + // + // This particular resolver makes all users share a single "guest" identity. + // It should only be used for testing and trying out Backstage. + // + // If you want to use a production ready resolver you can switch to the + // the one that is commented out below, it looks up a user entity in the + // catalog using the GitHub username of the authenticated user. + // That resolver requires you to have user entities populated in the catalog, + // for example using https://backstage.io/docs/integrations/github/org + // + // There are other resolvers to choose from, and you can also create + // your own, see the auth documentation for more details: // // https://backstage.io/docs/auth/identity-resolver github: providers.github.create({ - // signIn: { - // resolver: providers.github.resolvers.usernameMatchingUserEntityName(), - // }, + signIn: { + resolver(_, ctx) { + const userRef = 'user:default/guest'; // Must be a full entity reference + return ctx.issueToken({ + claims: { + sub: userRef, // The user's own identity + ent: [userRef], // A list of identities that the user claims ownership through + }, + }); + }, + // resolver: providers.github.resolvers.usernameMatchingUserEntityName(), + }, }), }, }); diff --git a/plugins/catalog-react/src/components/EntityTable/EntityTable.tsx b/plugins/catalog-react/src/components/EntityTable/EntityTable.tsx index 3aa6857120..424d8b940e 100644 --- a/plugins/catalog-react/src/components/EntityTable/EntityTable.tsx +++ b/plugins/catalog-react/src/components/EntityTable/EntityTable.tsx @@ -85,6 +85,7 @@ export const EntityTable = (props: EntityTableProps) => { paging: false, actionsColumnIndex: -1, padding: 'dense', + draggable: false, }} data={entities} /> diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index 5b7e07701c..34bb5dfcec 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -114,6 +114,8 @@ export interface CatalogSearchResultListItemProps { // (undocumented) icon?: ReactNode; // (undocumented) + rank?: number; + // (undocumented) result: IndexableDocument; } diff --git a/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx b/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx index 993e34fbf6..a7307055c2 100644 --- a/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx +++ b/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx @@ -25,6 +25,7 @@ import { makeStyles, } from '@material-ui/core'; import { Link } from '@backstage/core-components'; +import { useAnalytics } from '@backstage/core-plugin-api'; import { IndexableDocument, ResultHighlight, @@ -51,6 +52,7 @@ export interface CatalogSearchResultListItemProps { icon?: ReactNode; result: IndexableDocument; highlight?: ResultHighlight; + rank?: number; } /** @public */ @@ -60,8 +62,16 @@ export function CatalogSearchResultListItem( const result = props.result as any; const classes = useStyles(); + const analytics = useAnalytics(); + const handleClick = () => { + analytics.captureEvent('discover', result.title, { + attributes: { to: result.location }, + value: props.rank, + }); + }; + return ( - + {props.icon && {props.icon}}
diff --git a/plugins/cost-insights/README.md b/plugins/cost-insights/README.md index 295cfcccd2..824cf6f9fe 100644 --- a/plugins/cost-insights/README.md +++ b/plugins/cost-insights/README.md @@ -72,37 +72,50 @@ import { CostInsightsPage } from '@backstage/plugin-cost-insights'; To expose the plugin to your users, you can integrate the `cost-insights` route anyway that suits your application, but most commonly it is added to the Sidebar. ```diff -// packages/app/src/sidebar.tsx +// packages/app/src/components/Root/Root.tsx + import MoneyIcon from '@material-ui/icons/MonetizationOn'; ... - export const AppSidebar = () => ( - - - } to="/search"> - - - - {/* Global nav, not org-specific */} - }> - - - - - - -+ - - {/* End global nav */} - - - - } to="/settings"> - - - - ); + export const Root = ({ children }: PropsWithChildren<{}>) => ( + + + + } to="/search"> + + {({ toggleModal }) => } + + + + + + + + {/* End global nav */} + + ++ + + + + + + + } + to="/settings" + > + + + + {children} + +); ``` ## Configuration @@ -157,7 +170,7 @@ costInsights: ### Currencies (Optional) -In the `Cost Overview` panel, users can choose from a dropdown of currencies to see costs in, such as Engineers or USD. Currencies must be defined as keys on the `currencies` field. A user-friendly label and unit are **required**. If not set, the `defaultCurrencies` in `currenc.ts` will be used. +In the `Cost Overview` panel, users can choose from a dropdown of currencies to see costs in, such as Engineers or USD. Currencies must be defined as keys on the `currencies` field. A user-friendly label and unit are **required**. If not set, the `defaultCurrencies` in `currency.ts` will be used. A currency without `kind` is reserved to calculate cost for `engineers`. There should only be one currency without `kind`. diff --git a/plugins/dynatrace/.eslintrc.js b/plugins/dynatrace/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/dynatrace/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/dynatrace/README.md b/plugins/dynatrace/README.md new file mode 100644 index 0000000000..150c9768af --- /dev/null +++ b/plugins/dynatrace/README.md @@ -0,0 +1,56 @@ +# Dynatrace + +Welcome to the Dynatrace plugin! + +## Getting started + +This plugin uses the Backstage proxy to communicate with Dynatrace's REST APIs. + +### Setup + +#### Dynatrace API Key + +The Dynatrace plugin will require the following information, to be used in the configuration options detailed below: + +- Dynatrace API URL, e.g. `https://my-dynatrace-instance.dynatrace.com/api/v2` +- Dynatrace API access token (see [documentation](https://www.dynatrace.com/support/help/dynatrace-api/basics/dynatrace-api-authentication)), with the following permissions: + - `entities.read` + - `problems.read` + +#### Plugin Configuration + +This plugin requires a proxy endpoint for Dynatrace configured in `app-config.yaml` like so: + +```yaml +proxy: + '/dynatrace': + target: 'https://example.dynatrace.com/api/v2' + headers: + Authorization: 'Api-Token ${DYNATRACE_ACCESS_TOKEN}' +``` + +It also requires a baseUrl for rendering links to problems in the table like so: + +```yaml +dynatrace: + baseUrl: 'https://example.dynatrace.com' +``` + +#### Catalog Configuration + +To show information from Dynatrace for a catalog entity, add the following annotation to `catalog-info.yaml`: + +```yaml +# catalog-info.yaml +# [...] +metadata: + annotations: + dynatrace.com/dynatrace-entity-id: DYNATRACE_ENTITY_ID +# [...] +``` + +The `DYNATRACE_ENTITY_ID` can be found in Dynatrace by browsing to the entity (a service, synthetic, frontend, workload, etc.). It will be located in the browser address bar in the `id` parameter and has the format `ENTITY_TYPE-ENTITY_ID`, where `ENTITY_TYPE` will be one of `SERVICE`, `SYNTHETIC_TEST`, or other, and `ENTITY_ID` will be a string of characters containing uppercase letters and numbers. + +## Disclaimer + +This plugin is not officially supported by Dynatrace. diff --git a/plugins/dynatrace/api-report.md b/plugins/dynatrace/api-report.md new file mode 100644 index 0000000000..026df62189 --- /dev/null +++ b/plugins/dynatrace/api-report.md @@ -0,0 +1,23 @@ +## API Report File for "@backstage/plugin-dynatrace" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { Entity } from '@backstage/catalog-model'; + +// @public +export const dynatracePlugin: BackstagePlugin<{}, {}>; + +// @public +export const DynatraceTab: () => JSX.Element; + +// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}' +// +// @public +export const isDynatraceAvailable: (entity: Entity) => boolean; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/dynatrace/config.d.ts b/plugins/dynatrace/config.d.ts new file mode 100644 index 0000000000..b06d0c7362 --- /dev/null +++ b/plugins/dynatrace/config.d.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export interface Config { + /** + * dynatrace config + * @visibility frontend + */ + dynatrace?: { + /** + * base url for links + * @visibility frontend + */ + baseUrl: string; + }; +} diff --git a/plugins/dynatrace/dev/index.tsx b/plugins/dynatrace/dev/index.tsx new file mode 100644 index 0000000000..d44f4381ec --- /dev/null +++ b/plugins/dynatrace/dev/index.tsx @@ -0,0 +1,27 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { createDevApp } from '@backstage/dev-utils'; +import { dynatracePlugin, DynatraceTab } from '../src/plugin'; + +createDevApp() + .registerPlugin(dynatracePlugin) + .addPage({ + element: , + title: 'Root Page', + path: '/dynatrace', + }) + .render(); diff --git a/plugins/dynatrace/package.json b/plugins/dynatrace/package.json new file mode 100644 index 0000000000..267db810ce --- /dev/null +++ b/plugins/dynatrace/package.json @@ -0,0 +1,58 @@ +{ + "name": "@backstage/plugin-dynatrace", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public", + "main": "dist/index.esm.js", + "types": "dist/index.d.ts" + }, + "backstage": { + "role": "frontend-plugin" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "clean": "backstage-cli package clean", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack" + }, + "dependencies": { + "@backstage/catalog-model": "^1.0.3-next.0", + "@backstage/core-components": "^0.9.5-next.1", + "@backstage/core-plugin-api": "^1.0.3-next.0", + "@backstage/theme": "^0.2.15", + "@material-ui/core": "^4.9.13", + "@material-ui/icons": "^4.9.1", + "@material-ui/lab": "4.0.0-alpha.57", + "cross-fetch": "^3.1.5", + "react-use": "^17.2.4" + }, + "peerDependencies": { + "@backstage/plugin-catalog-react": "^1.1.1-next.1", + "react": "^16.13.1 || ^17.0.0" + }, + "devDependencies": { + "@backstage/cli": "^0.17.2-next.1", + "@backstage/core-app-api": "^1.0.3-next.0", + "@backstage/dev-utils": "^1.0.3-next.1", + "@backstage/test-utils": "^1.1.1-next.0", + "@testing-library/jest-dom": "^5.10.1", + "@testing-library/react": "^12.1.3", + "@testing-library/user-event": "^14.0.0", + "@types/jest": "*", + "@types/node": "*", + "cross-fetch": "^3.1.5", + "express": "^4.18.1", + "msw": "^0.42.0" + }, + "files": [ + "dist", + "config.d.ts" + ], + "configSchema": "config.d.ts" +} diff --git a/plugins/dynatrace/src/api/DynatraceApi.ts b/plugins/dynatrace/src/api/DynatraceApi.ts new file mode 100644 index 0000000000..1865b20363 --- /dev/null +++ b/plugins/dynatrace/src/api/DynatraceApi.ts @@ -0,0 +1,50 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createApiRef } from '@backstage/core-plugin-api'; + +export type DynatraceEntity = { + entityId: { + id: string; + type: string; + }; + name: string; +}; + +export type DynatraceProblem = { + problemId: string; + impactLevel: string; + status: string; + startTime: number; + endTime: number; + title: string; + severityLevel: string; + rootCauseEntity: DynatraceEntity; + affectedEntities: Array; +}; + +export interface DynatraceProblems { + problems: Array; +} + +export const dynatraceApiRef = createApiRef({ + id: 'plugin.dynatrace.service', +}); + +export type DynatraceApi = { + getDynatraceProblems( + dynatraceEntityId: string, + ): Promise; +}; diff --git a/plugins/dynatrace/src/api/DynatraceClient.ts b/plugins/dynatrace/src/api/DynatraceClient.ts new file mode 100644 index 0000000000..27476ddbac --- /dev/null +++ b/plugins/dynatrace/src/api/DynatraceClient.ts @@ -0,0 +1,66 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { DynatraceProblems, DynatraceApi } from './DynatraceApi'; +import { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api'; + +export class DynatraceClient implements DynatraceApi { + discoveryApi: DiscoveryApi; + fetchApi: FetchApi; + + constructor({ + discoveryApi, + fetchApi, + }: { + discoveryApi: DiscoveryApi; + fetchApi: FetchApi; + }) { + this.discoveryApi = discoveryApi; + this.fetchApi = fetchApi; + } + + private async callApi( + path: string, + query: { [key in string]: any }, + ): Promise { + const apiUrl = `${await this.discoveryApi.getBaseUrl('proxy')}/dynatrace`; + const response = await this.fetchApi.fetch( + `${apiUrl}/${path}?${new URLSearchParams(query).toString()}`, + { + headers: { + 'Content-Type': 'application/json', + }, + }, + ); + if (response.status === 200) { + return (await response.json()) as T; + } + throw new Error( + `Dynatrace API call failed: ${response.status}:${response.statusText}`, + ); + } + + async getDynatraceProblems( + dynatraceEntityId: string, + ): Promise { + if (!dynatraceEntityId) { + throw new Error('Dynatrace entity ID is required'); + } + + return this.callApi('problems', { + entitySelector: `entityId(${dynatraceEntityId})`, + }); + } +} diff --git a/plugins/dynatrace/src/api/index.ts b/plugins/dynatrace/src/api/index.ts new file mode 100644 index 0000000000..97e33c9281 --- /dev/null +++ b/plugins/dynatrace/src/api/index.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export type { + DynatraceProblems, + DynatraceProblem, + DynatraceEntity, +} from './DynatraceApi'; +export { dynatraceApiRef } from './DynatraceApi'; +export { DynatraceClient } from './DynatraceClient'; diff --git a/plugins/dynatrace/src/components/DynatraceTab/DynatraceTab.tsx b/plugins/dynatrace/src/components/DynatraceTab/DynatraceTab.tsx new file mode 100644 index 0000000000..c284eaba0f --- /dev/null +++ b/plugins/dynatrace/src/components/DynatraceTab/DynatraceTab.tsx @@ -0,0 +1,56 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { Grid } from '@material-ui/core'; +import { + Page, + Content, + ContentHeader, + SupportButton, + MissingAnnotationEmptyState, +} from '@backstage/core-components'; +import { useEntity } from '@backstage/plugin-catalog-react'; +import { ProblemsList } from '../Problems/ProblemsList'; +import { isDynatraceAvailable } from '../../plugin'; +import { DYNATRACE_ID_ANNOTATION } from '../../constants'; + +export const DynatraceTab = () => { + const { entity } = useEntity(); + + if (!isDynatraceAvailable(entity)) { + return ; + } + + const dynatraceEntityId: string = + entity?.metadata.annotations?.[DYNATRACE_ID_ANNOTATION]!; + + return ( + + + + + Plugin to show information from Dynatrace + + + + + + + + + + ); +}; diff --git a/plugins/dynatrace/src/components/DynatraceTab/index.ts b/plugins/dynatrace/src/components/DynatraceTab/index.ts new file mode 100644 index 0000000000..cd3a1b8fc6 --- /dev/null +++ b/plugins/dynatrace/src/components/DynatraceTab/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { DynatraceTab } from './DynatraceTab'; diff --git a/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.test.tsx b/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.test.tsx new file mode 100644 index 0000000000..9ac20ea1a2 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.test.tsx @@ -0,0 +1,29 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { ProblemStatus } from './ProblemStatus'; +import { renderInTestApp } from '@backstage/test-utils'; + +describe('ProblemStatus', () => { + it('renders StatusOK for a closed issue', async () => { + const rendered = await renderInTestApp(); + expect(await rendered.findByText('Closed')).toBeInTheDocument(); + }); + it('renders StatusError for an open issue', async () => { + const rendered = await renderInTestApp(); + expect(await rendered.findByText('Open')).toBeInTheDocument(); + }); +}); diff --git a/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.tsx b/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.tsx new file mode 100644 index 0000000000..2ed861963a --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemStatus/ProblemStatus.tsx @@ -0,0 +1,39 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { DynatraceProblem } from '../../../api/DynatraceApi'; +import { StatusError, StatusOK } from '@backstage/core-components'; + +export const ProblemStatus = ({ status }: Partial) => { + switch (status?.toLocaleLowerCase()) { + case 'open': + return ( + <> + + Open + + ); + case 'closed': + return ( + <> + + Closed + + ); + default: + return <>; + } +}; diff --git a/plugins/dynatrace/src/components/Problems/ProblemStatus/index.ts b/plugins/dynatrace/src/components/Problems/ProblemStatus/index.ts new file mode 100644 index 0000000000..14124f8d46 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemStatus/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { ProblemStatus } from './ProblemStatus'; diff --git a/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.test.tsx b/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.test.tsx new file mode 100644 index 0000000000..1249f4e886 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.test.tsx @@ -0,0 +1,55 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { ProblemsList } from './ProblemsList'; +import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils'; +import { dynatraceApiRef } from '../../../api'; +import { problems } from '../../../mocks/problems.json'; +import { ApiProvider, ConfigReader } from '@backstage/core-app-api'; +import { configApiRef } from '@backstage/core-plugin-api'; + +const mockDynatraceApi = { + getDynatraceProblems: jest.fn(), +}; +const apis = TestApiRegistry.from( + [dynatraceApiRef, mockDynatraceApi], + [configApiRef, new ConfigReader({ dynatrace: { baseUrl: '__dynatrace__' } })], +); + +describe('ProblemStatus', () => { + it('renders a table with problem data', async () => { + mockDynatraceApi.getDynatraceProblems = jest + .fn() + .mockResolvedValue({ problems }); + const rendered = await renderInTestApp( + + + , + ); + expect(await rendered.findByText('example-service')).toBeInTheDocument(); + }); + it('renders "nothing to report :)" if no problems are found', async () => { + mockDynatraceApi.getDynatraceProblems = jest.fn().mockResolvedValue({}); + const rendered = await renderInTestApp( + + + , + ); + expect( + await rendered.findByText('Nothing to report :)'), + ).toBeInTheDocument(); + }); +}); diff --git a/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.tsx b/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.tsx new file mode 100644 index 0000000000..ac69abf93e --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsList/ProblemsList.tsx @@ -0,0 +1,43 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import useAsync from 'react-use/lib/useAsync'; +import { Progress } from '@backstage/core-components'; +import Alert from '@material-ui/lab/Alert'; +import { useApi } from '@backstage/core-plugin-api'; +import { ProblemsTable } from '../ProblemsTable'; +import { dynatraceApiRef } from '../../../api'; + +type ProblemsListProps = { + dynatraceEntityId: string; +}; + +export const ProblemsList = (props: ProblemsListProps) => { + const { dynatraceEntityId } = props; + const dynatraceApi = useApi(dynatraceApiRef); + const { value, loading, error } = useAsync(async () => { + return dynatraceApi.getDynatraceProblems(dynatraceEntityId); + }, [dynatraceApi, dynatraceEntityId]); + const problems = value?.problems; + + if (loading) { + return ; + } else if (error) { + return {error.message}; + } + if (!problems) return
Nothing to report :)
; + return ; +}; diff --git a/plugins/dynatrace/src/components/Problems/ProblemsList/index.ts b/plugins/dynatrace/src/components/Problems/ProblemsList/index.ts new file mode 100644 index 0000000000..f70c9c6f20 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsList/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { ProblemsList } from './ProblemsList'; diff --git a/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.test.tsx b/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.test.tsx new file mode 100644 index 0000000000..e4adc43656 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.test.tsx @@ -0,0 +1,44 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { ProblemsTable } from './ProblemsTable'; +import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils'; +import { problems } from '../../../mocks/problems.json'; +import { ApiProvider, ConfigReader } from '@backstage/core-app-api'; +import { configApiRef } from '@backstage/core-plugin-api'; + +describe('ProblemsTable', () => { + const apis = TestApiRegistry.from([ + configApiRef, + new ConfigReader({ dynatrace: { baseUrl: '__dynatrace__' } }), + ]); + it('renders the table with some problem data', async () => { + const rendered = await renderInTestApp( + + , + , + ); + expect(await rendered.findByText('example-service')).toBeInTheDocument(); + }); + it('renders an empty table when no data is provided', async () => { + const rendered = await renderInTestApp( + + + , + ); + expect(await rendered.findByText('Problems')).toBeInTheDocument(); + }); +}); diff --git a/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.tsx b/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.tsx new file mode 100644 index 0000000000..8e3d330c37 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsTable/ProblemsTable.tsx @@ -0,0 +1,86 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { Table, TableColumn } from '@backstage/core-components'; +import { DynatraceProblem } from '../../../api/DynatraceApi'; +import { ProblemStatus } from '../ProblemStatus'; +import { configApiRef } from '@backstage/core-plugin-api'; +import { useApi } from '@backstage/core-plugin-api'; +import { Link } from '@material-ui/core'; + +type ProblemsTableProps = { + problems: DynatraceProblem[]; +}; + +export const ProblemsTable = ({ problems }: ProblemsTableProps) => { + const configApi = useApi(configApiRef); + const dynatraceBaseUrl = configApi.getString('dynatrace.baseUrl'); + const columns: TableColumn[] = [ + { + title: 'Title', + field: 'title', + render: (row: Partial) => ( + + {row.title} + + ), + }, + { + title: 'Status', + field: 'status', + render: (row: Partial) => ( + + ), + }, + { title: 'Severity', field: 'severityLevel' }, + { + title: 'Root Cause', + field: 'rootCauseEntity', + render: (row: Partial) => row.rootCauseEntity?.name, + }, + { + title: 'Affected', + field: 'affectedEntities', + render: (row: Partial) => + row.affectedEntities?.map(e => e.name), + }, + { + title: 'Start Time', + field: 'startTime', + render: (row: Partial) => + new Date(row.startTime || 0).toString(), + }, + { + title: 'End Time', + field: 'endTime', + render: (row: Partial) => + row.endTime === -1 ? 'ongoing' : new Date(row.endTime || 0).toString(), + }, + ]; + + return ( + { + return { ...p, id: p.problemId }; + })} + /> + ); +}; diff --git a/plugins/dynatrace/src/components/Problems/ProblemsTable/index.ts b/plugins/dynatrace/src/components/Problems/ProblemsTable/index.ts new file mode 100644 index 0000000000..d1cd52e511 --- /dev/null +++ b/plugins/dynatrace/src/components/Problems/ProblemsTable/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { ProblemsTable } from './ProblemsTable'; diff --git a/plugins/dynatrace/src/constants.ts b/plugins/dynatrace/src/constants.ts new file mode 100644 index 0000000000..21453e0338 --- /dev/null +++ b/plugins/dynatrace/src/constants.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const DYNATRACE_ID_ANNOTATION = 'dynatrace.com/dynatrace-entity-id'; diff --git a/plugins/dynatrace/src/index.ts b/plugins/dynatrace/src/index.ts new file mode 100644 index 0000000000..c96c16201d --- /dev/null +++ b/plugins/dynatrace/src/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { dynatracePlugin, DynatraceTab, isDynatraceAvailable } from './plugin'; diff --git a/plugins/dynatrace/src/mocks/problems.json b/plugins/dynatrace/src/mocks/problems.json new file mode 100644 index 0000000000..b1894bef56 --- /dev/null +++ b/plugins/dynatrace/src/mocks/problems.json @@ -0,0 +1,135 @@ +{ + "totalCount": 0, + "pageSize": 0, + "nextPageKey": "AQAAABQBAAAABQ==", + "problems": [ + { + "managementZones": [ + { + "name": "string", + "id": "string" + } + ], + "severityLevel": "AVAILABILITY", + "entityTags": [ + { + "stringRepresentation": "string", + "value": "string", + "key": "string", + "context": "string" + } + ], + "problemId": "string", + "displayId": "string", + "affectedEntities": [ + { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "my-service" + }, + { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "example-service-3" + } + ], + "rootCauseEntity": { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "example-service" + }, + "impactedEntities": [ + { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "HELP ME" + }, + { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "HELP ME 2" + } + ], + "linkedProblemInfo": { + "problemId": "string", + "displayId": "string" + }, + "problemFilters": [ + { + "name": "string", + "id": "string" + } + ], + "evidenceDetails": { + "totalCount": 0, + "details": [ + { + "evidenceType": "AVAILABILITY_EVIDENCE", + "displayName": "string", + "entity": { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "string" + }, + "groupingEntity": { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "string" + }, + "rootCauseRelevant": true, + "startTime": 0 + } + ] + }, + "recentComments": { + "comments": [ + { + "createdAtTimestamp": 0, + "authorName": "string", + "context": "string", + "id": "string", + "content": "string" + } + ], + "totalCount": 0, + "pageSize": 0, + "nextPageKey": "AQAAABQBAAAABQ==" + }, + "impactAnalysis": { + "impacts": [ + { + "impactType": "APPLICATION", + "impactedEntity": { + "entityId": { + "id": "string", + "type": "string" + }, + "name": "string" + }, + "estimatedAffectedUsers": 0 + } + ] + }, + "impactLevel": "APPLICATION", + "status": "OPEN", + "startTime": 0, + "endTime": 0, + "title": "this IS a big problem" + } + ], + "warnings": ["string"] +} diff --git a/plugins/dynatrace/src/plugin.test.ts b/plugins/dynatrace/src/plugin.test.ts new file mode 100644 index 0000000000..94dc2da765 --- /dev/null +++ b/plugins/dynatrace/src/plugin.test.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { dynatracePlugin } from './plugin'; + +describe('dynatrace', () => { + it('should export plugin', () => { + expect(dynatracePlugin).toBeDefined(); + }); +}); diff --git a/plugins/dynatrace/src/plugin.ts b/plugins/dynatrace/src/plugin.ts new file mode 100644 index 0000000000..fc1778b45c --- /dev/null +++ b/plugins/dynatrace/src/plugin.ts @@ -0,0 +1,71 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { dynatraceApiRef, DynatraceClient } from './api'; +import { + createApiFactory, + createPlugin, + discoveryApiRef, + fetchApiRef, + createRoutableExtension, +} from '@backstage/core-plugin-api'; + +import { Entity } from '@backstage/catalog-model'; +import { DYNATRACE_ID_ANNOTATION } from './constants'; + +import { rootRouteRef } from './routes'; + +/** + * Create the Dynatrace plugin. + * @public + */ +export const dynatracePlugin = createPlugin({ + id: 'dynatrace', + apis: [ + createApiFactory({ + api: dynatraceApiRef, + deps: { + discoveryApi: discoveryApiRef, + fetchApi: fetchApiRef, + }, + factory: ({ discoveryApi, fetchApi }) => + new DynatraceClient({ + discoveryApi, + fetchApi, + }), + }), + ], +}); + +/** + * Checks if the entity has a dynatrace id annotation. + * @public + * @param entity {Entity} - The entity to check for the dynatrace id annotation. + */ +export const isDynatraceAvailable = (entity: Entity) => + Boolean(entity.metadata.annotations?.[DYNATRACE_ID_ANNOTATION]); + +/** + * Creates a routable extension for the dynatrace plugin tab. + * @public + */ +export const DynatraceTab = dynatracePlugin.provide( + createRoutableExtension({ + name: 'DynatraceTab', + component: () => + import('./components/DynatraceTab').then(m => m.DynatraceTab), + mountPoint: rootRouteRef, + }), +); diff --git a/plugins/dynatrace/src/routes.ts b/plugins/dynatrace/src/routes.ts new file mode 100644 index 0000000000..73f7b573b7 --- /dev/null +++ b/plugins/dynatrace/src/routes.ts @@ -0,0 +1,20 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createRouteRef } from '@backstage/core-plugin-api'; + +export const rootRouteRef = createRouteRef({ + id: 'dynatrace', +}); diff --git a/plugins/dynatrace/src/setupTests.ts b/plugins/dynatrace/src/setupTests.ts new file mode 100644 index 0000000000..9bb3e72355 --- /dev/null +++ b/plugins/dynatrace/src/setupTests.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import '@testing-library/jest-dom'; +import 'cross-fetch/polyfill'; diff --git a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts index c114406d99..7892b731ed 100644 --- a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts +++ b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.test.ts @@ -523,6 +523,7 @@ describe('ElasticSearchSearchEngine', () => { .map((_, i) => ({ type: 'mytype', document: { value: `${i}` }, + rank: i + 1, })), ), }); @@ -567,6 +568,7 @@ describe('ElasticSearchSearchEngine', () => { .map((_, i) => ({ type: 'mytype', document: { value: `${i}` }, + rank: i + 1, })), ), nextPageCursor: 'MQ==', @@ -614,6 +616,7 @@ describe('ElasticSearchSearchEngine', () => { .map((_, i) => ({ type: 'mytype', document: { value: `${i}` }, + rank: i + 1, })) .slice(25), ), @@ -667,6 +670,7 @@ describe('ElasticSearchSearchEngine', () => { .map((_, i) => ({ type: 'mytype', document: { value: `${i}` }, + rank: i + 1, highlight: { preTag: '', postTag: '', diff --git a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.ts b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.ts index d11d8a1f90..31112e3446 100644 --- a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.ts +++ b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchSearchEngine.ts @@ -334,27 +334,30 @@ export class ElasticSearchSearchEngine implements SearchEngine { : undefined; return { - results: result.body.hits.hits.map((d: ElasticSearchResult) => { - const resultItem: IndexableResult = { - type: this.getTypeFromIndex(d._index), - document: d._source, - }; - - if (d.highlight) { - resultItem.highlight = { - preTag: this.highlightOptions.preTag as string, - postTag: this.highlightOptions.postTag as string, - fields: Object.fromEntries( - Object.entries(d.highlight).map(([field, fragments]) => [ - field, - fragments.join(this.highlightOptions.fragmentDelimiter), - ]), - ), + results: result.body.hits.hits.map( + (d: ElasticSearchResult, index: number) => { + const resultItem: IndexableResult = { + type: this.getTypeFromIndex(d._index), + document: d._source, + rank: pageSize * page + index + 1, }; - } - return resultItem; - }), + if (d.highlight) { + resultItem.highlight = { + preTag: this.highlightOptions.preTag as string, + postTag: this.highlightOptions.postTag as string, + fields: Object.fromEntries( + Object.entries(d.highlight).map(([field, fragments]) => [ + field, + fragments.join(this.highlightOptions.fragmentDelimiter), + ]), + ), + }; + } + + return resultItem; + }, + ), nextPageCursor, previousPageCursor, }; diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts index cc89f28c80..3ed002567e 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts @@ -174,6 +174,7 @@ describe('PgSearchEngine', () => { location: 'location-1', }, type: 'my-type', + rank: 1, }, ], nextPageCursor: undefined, @@ -215,6 +216,7 @@ describe('PgSearchEngine', () => { location: `location-${i}`, }, type: 'my-type', + rank: i + 1, })), nextPageCursor: 'MQ==', }); @@ -257,6 +259,7 @@ describe('PgSearchEngine', () => { location: `location-${i}`, }, type: 'my-type', + rank: i + 1, })) .slice(25), previousPageCursor: 'MA==', diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts index 445d1bb5c1..bf98c58de9 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts @@ -18,6 +18,7 @@ import { SearchEngine } from '@backstage/plugin-search-backend-node'; import { SearchQuery, IndexableResultSet, + IndexableResult, } from '@backstage/plugin-search-common'; import { PgSearchEngineIndexer } from './PgSearchEngineIndexer'; import { @@ -104,10 +105,13 @@ export class PgSearchEngine implements SearchEngine { ? encodePageCursor({ page: page - 1 }) : undefined; - const results = pageRows.map(({ type, document }) => ({ - type, - document, - })); + const results = pageRows.map( + ({ type, document }, index): IndexableResult => ({ + type, + document, + rank: page * pageSize + index + 1, + }), + ); return { results, nextPageCursor, previousPageCursor }; } diff --git a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts index 84b1a35165..098d1e8b16 100644 --- a/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts +++ b/plugins/search-backend-node/src/engines/LunrSearchEngine.test.ts @@ -431,6 +431,7 @@ describe('LunrSearchEngine', () => { location: 'test/location', }, type: 'test-index', + rank: 1, }, ], nextPageCursor: undefined, @@ -469,6 +470,7 @@ describe('LunrSearchEngine', () => { text: 'testText', location: 'test/location', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -521,6 +523,7 @@ describe('LunrSearchEngine', () => { location: `${highlightTags.pre}test/location${highlightTags.post}`, }, }, + rank: 1, }, ], nextPageCursor: undefined, @@ -559,6 +562,7 @@ describe('LunrSearchEngine', () => { text: 'testText', location: 'test/location', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -598,6 +602,7 @@ describe('LunrSearchEngine', () => { text: 'testText', location: 'test/location', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -637,6 +642,7 @@ describe('LunrSearchEngine', () => { text: 'Hello World.', location: 'test/location', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -676,6 +682,7 @@ describe('LunrSearchEngine', () => { text: 'Searching', location: 'test/location', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -722,6 +729,7 @@ describe('LunrSearchEngine', () => { text: 'testText', location: 'test/location2', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -777,6 +785,7 @@ describe('LunrSearchEngine', () => { location: 'test/location2', extraField: 'testExtraField', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -823,6 +832,7 @@ describe('LunrSearchEngine', () => { text: 'testText', location: 'test:location2', }, + rank: 1, }, ], nextPageCursor: undefined, @@ -886,6 +896,7 @@ describe('LunrSearchEngine', () => { text: 'testText', title: 'testTitle', }, + rank: 1, }, { document: { @@ -893,6 +904,7 @@ describe('LunrSearchEngine', () => { text: 'testText', title: 'testTitle', }, + rank: 2, }, ], nextPageCursor: undefined, @@ -931,6 +943,7 @@ describe('LunrSearchEngine', () => { location: `test/location/${i}`, }, type: 'test-index', + rank: i + 1, })), nextPageCursor: 'MQ==', previousPageCursor: undefined, @@ -968,6 +981,7 @@ describe('LunrSearchEngine', () => { location: `test/location/${i}`, }, type: 'test-index', + rank: i + 1, })) .slice(25), nextPageCursor: undefined, diff --git a/plugins/search-backend-node/src/engines/LunrSearchEngine.ts b/plugins/search-backend-node/src/engines/LunrSearchEngine.ts index 4a5f4cdd18..03cb421653 100644 --- a/plugins/search-backend-node/src/engines/LunrSearchEngine.ts +++ b/plugins/search-backend-node/src/engines/LunrSearchEngine.ts @@ -207,9 +207,10 @@ export class LunrSearchEngine implements SearchEngine { // Translate results into IndexableResultSet const realResultSet: IndexableResultSet = { - results: results.slice(offset, offset + pageSize).map(d => ({ + results: results.slice(offset, offset + pageSize).map((d, index) => ({ type: d.type, document: this.docStore[d.result.ref], + rank: page * pageSize + index + 1, highlight: { preTag: this.highlightPreTag, postTag: this.highlightPostTag, diff --git a/plugins/search-backend/src/service/AuthorizedSearchEngine.test.ts b/plugins/search-backend/src/service/AuthorizedSearchEngine.test.ts index 256608fd82..b2355a7239 100644 --- a/plugins/search-backend/src/service/AuthorizedSearchEngine.test.ts +++ b/plugins/search-backend/src/service/AuthorizedSearchEngine.test.ts @@ -44,6 +44,7 @@ describe('AuthorizedSearchEngine', () => { .fill(0) .map((_, index) => ({ type, + rank: index + 1, document: { title: `${type}_doc_${index}`, authorization: withAuthorization @@ -261,9 +262,11 @@ describe('AuthorizedSearchEngine', () => { }), ); + const expectedResult = { ...usersWithAuth[8], rank: 1 }; + await expect( authorizedSearchEngine.query({ term: '' }, options), - ).resolves.toEqual({ results: [usersWithAuth[8]] }); + ).resolves.toEqual({ results: [expectedResult] }); expect(mockedQuery).toHaveBeenCalledWith( { term: '', types: ['users'] }, @@ -275,6 +278,7 @@ describe('AuthorizedSearchEngine', () => { const searchResults = [ { type: 'templates', + rank: 1, document: { title: `doc_0_a`, authorization: { resourceRef: `template_doc_0` }, @@ -282,6 +286,7 @@ describe('AuthorizedSearchEngine', () => { }, { type: 'templates', + rank: 2, document: { title: `doc_0_b`, authorization: { resourceRef: `template_doc_0` }, @@ -419,7 +424,9 @@ describe('AuthorizedSearchEngine', () => { { token: 'token' }, ); - const expectedResult = allDocuments.slice(0, 25); + const expectedResult = allDocuments + .slice(0, 25) + .map((r, i) => ({ ...r, rank: i + 1 })); const expectedFirstRequestCursor = 'MQ=='; expect(result).toEqual({ @@ -510,7 +517,8 @@ describe('AuthorizedSearchEngine', () => { const expectedResult = allDocuments .filter(d => d.type !== typeServices) - .slice(0, 25); + .slice(0, 25) + .map((d, i) => ({ ...d, rank: i + 1 })); const expectedFirstRequestCursor = 'MQ=='; expect(result).toEqual({ @@ -587,8 +595,12 @@ describe('AuthorizedSearchEngine', () => { { token: 'token' }, ); + const expectedResults = servicesWithAuth + .slice(5) + .map((r, i) => ({ ...r, rank: 25 + i + 1 })); + expect(result).toEqual({ - results: servicesWithAuth.slice(5), + results: expectedResults, previousPageCursor: encodePageCursor({ page: 0 }), }); }); diff --git a/plugins/search-backend/src/service/AuthorizedSearchEngine.ts b/plugins/search-backend/src/service/AuthorizedSearchEngine.ts index a74cdf8eef..ade43280be 100644 --- a/plugins/search-backend/src/service/AuthorizedSearchEngine.ts +++ b/plugins/search-backend/src/service/AuthorizedSearchEngine.ts @@ -189,10 +189,15 @@ export class AuthorizedSearchEngine implements SearchEngine { ); return { - results: filteredResults.slice( - page * this.pageSize, - (page + 1) * this.pageSize, - ), + results: filteredResults + .slice(page * this.pageSize, (page + 1) * this.pageSize) + .map((result, index) => { + // Overwrite any/all rank entries to avoid leaking knowledge of filtered results. + return { + ...result, + rank: page * this.pageSize + index + 1, + }; + }), previousPageCursor: page === 0 ? undefined : encodePageCursor({ page: page - 1 }), nextPageCursor: diff --git a/plugins/search-common/api-report.md b/plugins/search-common/api-report.md index bb049742f7..ea9fc2d26e 100644 --- a/plugins/search-common/api-report.md +++ b/plugins/search-common/api-report.md @@ -52,11 +52,9 @@ export type QueryTranslator = (query: SearchQuery) => unknown; // @public (undocumented) export interface Result { - // (undocumented) document: TDocument; - // (undocumented) highlight?: ResultHighlight; - // (undocumented) + rank?: number; type: string; } diff --git a/plugins/search-common/src/types.ts b/plugins/search-common/src/types.ts index fdcc06287c..4b4c25d423 100644 --- a/plugins/search-common/src/types.ts +++ b/plugins/search-common/src/types.ts @@ -56,9 +56,27 @@ export interface ResultHighlight { * @public */ export interface Result { + /** + * The "type" of the given document. See: {@link DocumentCollatorFactory."type"} + */ type: string; + + /** + * The raw value of the document, as indexed. + */ document: TDocument; + + /** + * Optional result highlight. Useful for improving the search result + * display/experience. + */ highlight?: ResultHighlight; + + /** + * Optional result rank, where 1 is the first/top result returned. Useful for + * understanding search effectiveness in analytics. + */ + rank?: number; } /** diff --git a/plugins/search-react/api-report.md b/plugins/search-react/api-report.md index f9bb993fd6..e4afee45ca 100644 --- a/plugins/search-react/api-report.md +++ b/plugins/search-react/api-report.md @@ -38,6 +38,7 @@ export type DefaultResultListItemProps = { secondaryAction?: ReactNode; result: SearchDocument; highlight?: ResultHighlight; + rank?: number; lineClamp?: number; }; diff --git a/plugins/search-react/src/components/DefaultResultListItem/DefaultResultListItem.tsx b/plugins/search-react/src/components/DefaultResultListItem/DefaultResultListItem.tsx index ff6f3d7fe1..f4260525d6 100644 --- a/plugins/search-react/src/components/DefaultResultListItem/DefaultResultListItem.tsx +++ b/plugins/search-react/src/components/DefaultResultListItem/DefaultResultListItem.tsx @@ -15,7 +15,7 @@ */ import React, { ReactNode } from 'react'; -import { AnalyticsContext } from '@backstage/core-plugin-api'; +import { AnalyticsContext, useAnalytics } from '@backstage/core-plugin-api'; import { ResultHighlight, SearchDocument, @@ -40,6 +40,7 @@ export type DefaultResultListItemProps = { secondaryAction?: ReactNode; result: SearchDocument; highlight?: ResultHighlight; + rank?: number; lineClamp?: number; }; @@ -51,12 +52,21 @@ export type DefaultResultListItemProps = { export const DefaultResultListItemComponent = ({ result, highlight, + rank, icon, secondaryAction, lineClamp = 5, }: DefaultResultListItemProps) => { + const analytics = useAnalytics(); + const handleClick = () => { + analytics.captureEvent('discover', result.title, { + attributes: { to: result.location }, + value: rank, + }); + }; + return ( - + {icon && {icon}} { + table + .dateTime('timestamp', { precision: 0 }) + .defaultTo(knex.fn.now()) + .notNullable() + .comment('The timestamp when this entry was created') + .alter(); + }); +}; + +/** + * @param {import('knex').Knex} _knex + */ +exports.down = async function down(_knex) {}; diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index bcccec65b5..09d409fecd 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,6 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; +import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { TokenManager } from '@backstage/backend-common'; @@ -76,7 +77,14 @@ export type FactRetrieverRegistration = { // @public export type FactSchema = { [name: string]: { - type: 'integer' | 'float' | 'string' | 'boolean' | 'datetime' | 'set'; + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; description: string; since?: string; metadata?: Record; @@ -136,6 +144,7 @@ export type TechInsightFact = { | string[] | boolean[] | DateTime[] + | JsonValue >; timestamp?: DateTime; }; diff --git a/plugins/tech-insights-node/package.json b/plugins/tech-insights-node/package.json index b17c635a8a..0312b1d91f 100644 --- a/plugins/tech-insights-node/package.json +++ b/plugins/tech-insights-node/package.json @@ -36,6 +36,7 @@ "@backstage/backend-common": "^0.14.0-next.2", "@backstage/config": "^1.0.1", "@backstage/plugin-tech-insights-common": "^0.2.4", + "@backstage/types": "^1.0.0", "@types/luxon": "^2.0.5", "luxon": "^2.0.2", "winston": "^3.2.1" diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index ffd3549bd5..bcc2aa42e1 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -15,6 +15,7 @@ */ import { DateTime, Duration, DurationLike } from 'luxon'; import { Config } from '@backstage/config'; +import { JsonValue } from '@backstage/types'; import { PluginEndpointDiscovery, TokenManager, @@ -55,6 +56,7 @@ export type TechInsightFact = { | string[] | boolean[] | DateTime[] + | JsonValue >; /** @@ -94,9 +96,16 @@ export type FactSchema = { * Type of the individual fact value * * Numbers are split into integers and floating point values. - * `set` indicates a collection of values + * `set` indicates a collection of values, `object` indicates JSON serializable value */ - type: 'integer' | 'float' | 'string' | 'boolean' | 'datetime' | 'set'; + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; /** * A description of this individual fact value diff --git a/plugins/techdocs-node/src/stages/publish/local.test.ts b/plugins/techdocs-node/src/stages/publish/local.test.ts index 761de03c5a..daf943dce4 100644 --- a/plugins/techdocs-node/src/stages/publish/local.test.ts +++ b/plugins/techdocs-node/src/stages/publish/local.test.ts @@ -54,62 +54,107 @@ const resolvedDir = resolvePackagePath( ); describe('local publisher', () => { - it('should publish generated documentation dir', async () => { - mockFs({ - [tmpDir]: { - 'index.html': '', - }, + describe('publish', () => { + beforeEach(() => { + mockFs({ + [tmpDir]: { + 'index.html': '', + }, + }); }); - const mockConfig = new ConfigReader({}); - - const publisher = LocalPublish.fromConfig( - mockConfig, - logger, - testDiscovery, - ); - const mockEntity = createMockEntity(); - const lowerMockEntity = createMockEntity(undefined, true); - - await publisher.publish({ entity: mockEntity, directory: tmpDir }); - - expect(await publisher.hasDocsBeenGenerated(mockEntity)).toBe(true); - - // Lower/upper should be treated the same. - expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(true); - - mockFs.restore(); - }); - - it('should respect legacy casing', async () => { - mockFs({ - [tmpDir]: { - 'index.html': '', - }, + afterEach(() => { + mockFs.restore(); }); - const mockConfig = new ConfigReader({ - techdocs: { - legacyUseCaseSensitiveTripletPaths: true, - }, + it('should publish generated documentation dir', async () => { + const mockConfig = new ConfigReader({}); + + const publisher = LocalPublish.fromConfig( + mockConfig, + logger, + testDiscovery, + ); + const mockEntity = createMockEntity(); + const lowerMockEntity = createMockEntity(undefined, true); + + await publisher.publish({ entity: mockEntity, directory: tmpDir }); + + expect(await publisher.hasDocsBeenGenerated(mockEntity)).toBe(true); + + // Lower/upper should be treated the same. + expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(true); + + mockFs.restore(); }); - const publisher = LocalPublish.fromConfig( - mockConfig, - logger, - testDiscovery, - ); - const mockEntity = createMockEntity(); - const lowerMockEntity = createMockEntity(undefined, true); + it('should respect legacy casing', async () => { + const mockConfig = new ConfigReader({ + techdocs: { + legacyUseCaseSensitiveTripletPaths: true, + }, + }); - await publisher.publish({ entity: mockEntity, directory: tmpDir }); + const publisher = LocalPublish.fromConfig( + mockConfig, + logger, + testDiscovery, + ); + const mockEntity = createMockEntity(); + const lowerMockEntity = createMockEntity(undefined, true); - expect(await publisher.hasDocsBeenGenerated(mockEntity)).toBe(true); + await publisher.publish({ entity: mockEntity, directory: tmpDir }); - // Lower/upper should be treated differently. - expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(false); + expect(await publisher.hasDocsBeenGenerated(mockEntity)).toBe(true); - mockFs.restore(); + // Lower/upper should be treated differently. + expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(false); + + mockFs.restore(); + }); + + it('should throw with unsafe triplet', async () => { + const mockConfig = new ConfigReader({}); + const publisher = LocalPublish.fromConfig( + mockConfig, + logger, + testDiscovery, + ); + const mockEntity = { + ...createMockEntity(), + ...{ + kind: '..', + metadata: { name: '..', namespace: '..' }, + }, + }; + + await expect(() => + publisher.publish({ entity: mockEntity, directory: tmpDir }), + ).rejects.toThrowError('Unable to publish TechDocs site'); + }); + + it('should throw with unsafe name', async () => { + const mockConfig = new ConfigReader({}); + const publisher = LocalPublish.fromConfig( + mockConfig, + logger, + testDiscovery, + ); + const mockEntity = { + ...createMockEntity(), + ...{ + kind: 'component', + metadata: { + name: '../component/other-component', + namespace: 'default', + }, + }, + }; + + await expect(() => + publisher.publish({ entity: mockEntity, directory: tmpDir }), + ).rejects.toThrowError('Unable to publish TechDocs site'); + }); }); describe('docsRouter', () => { diff --git a/plugins/techdocs-node/src/stages/publish/local.ts b/plugins/techdocs-node/src/stages/publish/local.ts index 4539d389df..c0de46eb22 100644 --- a/plugins/techdocs-node/src/stages/publish/local.ts +++ b/plugins/techdocs-node/src/stages/publish/local.ts @@ -16,8 +16,13 @@ import { PluginEndpointDiscovery, resolvePackagePath, + resolveSafeChildPath, } from '@backstage/backend-common'; -import { Entity, CompoundEntityRef } from '@backstage/catalog-model'; +import { + Entity, + CompoundEntityRef, + stringifyEntityRef, +} from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import express from 'express'; import fs from 'fs-extra'; @@ -37,7 +42,7 @@ import { getHeadersForFileExtension, lowerCaseEntityTripletInStoragePath, } from './helpers'; -import { assertError } from '@backstage/errors'; +import { ForwardedError } from '@backstage/errors'; // TODO: Use a more persistent storage than node_modules or /tmp directory. // Make it configurable with techdocs.publisher.local.publishDirectory @@ -103,12 +108,22 @@ export class LocalPublish implements PublisherBase { directory, }: PublishRequest): Promise { const entityNamespace = entity.metadata.namespace ?? 'default'; + let publishDir: string; - const publishDir = this.staticEntityPathJoin( - entityNamespace, - entity.kind, - entity.metadata.name, - ); + try { + publishDir = this.staticEntityPathJoin( + entityNamespace, + entity.kind, + entity.metadata.name, + ); + } catch (error) { + throw new ForwardedError( + `Unable to publish TechDocs site for entity: ${stringifyEntityRef( + entity, + )}`, + error, + ); + } if (!fs.existsSync(publishDir)) { this.logger.info(`Could not find ${publishDir}, creating the directory.`); @@ -144,21 +159,31 @@ export class LocalPublish implements PublisherBase { async fetchTechDocsMetadata( entityName: CompoundEntityRef, ): Promise { - const metadataPath = this.staticEntityPathJoin( - entityName.namespace, - entityName.kind, - entityName.name, - 'techdocs_metadata.json', - ); + let metadataPath: string; + + try { + metadataPath = this.staticEntityPathJoin( + entityName.namespace, + entityName.kind, + entityName.name, + 'techdocs_metadata.json', + ); + } catch (err) { + throw new ForwardedError( + `Unexpected entity when fetching metadata: ${stringifyEntityRef( + entityName, + )}`, + err, + ); + } try { return await fs.readJson(metadataPath); } catch (err) { - assertError(err); - this.logger.error( + throw new ForwardedError( `Unable to read techdocs_metadata.json at ${metadataPath}. Error: ${err}`, + err, ); - throw new Error(err.message); } } @@ -217,18 +242,26 @@ export class LocalPublish implements PublisherBase { async hasDocsBeenGenerated(entity: Entity): Promise { const namespace = entity.metadata.namespace ?? 'default'; - const indexHtmlPath = this.staticEntityPathJoin( - namespace, - entity.kind, - entity.metadata.name, - 'index.html', - ); - // Check if the file exists try { + const indexHtmlPath = this.staticEntityPathJoin( + namespace, + entity.kind, + entity.metadata.name, + 'index.html', + ); + await fs.access(indexHtmlPath, fs.constants.F_OK); + return true; } catch (err) { + if (err.name === 'NotAllowedError') { + this.logger.error( + `Unexpected entity when checking if generated: ${stringifyEntityRef( + entity, + )}`, + ); + } return false; } } @@ -278,17 +311,25 @@ export class LocalPublish implements PublisherBase { * Utility wrapper around path.join(), used to control legacy case logic. */ protected staticEntityPathJoin(...allParts: string[]): string { - if (this.legacyPathCasing) { - const [namespace, kind, name, ...parts] = allParts; - return path.join(staticDocsDir, namespace, kind, name, ...parts); - } - const [namespace, kind, name, ...parts] = allParts; - return path.join( - staticDocsDir, - namespace.toLowerCase(), - kind.toLowerCase(), - name.toLowerCase(), - ...parts, - ); + let staticEntityPath = staticDocsDir; + + allParts + .map(part => part.split(path.sep)) + .flat() + .forEach((part, index) => { + // Respect legacy path casing when operating on namespace, kind, or name. + if (index < 3) { + staticEntityPath = resolveSafeChildPath( + staticEntityPath, + this.legacyPathCasing ? part : part.toLowerCase(), + ); + return; + } + + // Otherwise, respect the provided case. + staticEntityPath = resolveSafeChildPath(staticEntityPath, part); + }); + + return staticEntityPath; } } diff --git a/plugins/techdocs/api-report.md b/plugins/techdocs/api-report.md index b66f868f1d..7778c07ef4 100644 --- a/plugins/techdocs/api-report.md +++ b/plugins/techdocs/api-report.md @@ -393,6 +393,7 @@ export type TechDocsSearchResultListItemProps = { icon?: ReactNode; result: any; highlight?: ResultHighlight; + rank?: number; lineClamp?: number; asListItem?: boolean; asLink?: boolean; diff --git a/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx b/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx index 9843443c7a..430165bf8b 100644 --- a/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx +++ b/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx @@ -23,6 +23,7 @@ import { makeStyles, } from '@material-ui/core'; import { Link } from '@backstage/core-components'; +import { useAnalytics } from '@backstage/core-plugin-api'; import { ResultHighlight } from '@backstage/plugin-search-common'; import { HighlightedSearchResultText } from '@backstage/plugin-search-react'; @@ -45,6 +46,7 @@ export type TechDocsSearchResultListItemProps = { icon?: ReactNode; result: any; highlight?: ResultHighlight; + rank?: number; lineClamp?: number; asListItem?: boolean; asLink?: boolean; @@ -62,6 +64,7 @@ export const TechDocsSearchResultListItem = ( const { result, highlight, + rank, lineClamp = 5, asListItem = true, asLink = true, @@ -69,6 +72,15 @@ export const TechDocsSearchResultListItem = ( icon, } = props; const classes = useStyles(); + + const analytics = useAnalytics(); + const handleClick = () => { + analytics.captureEvent('discover', result.title, { + attributes: { to: result.location }, + value: rank, + }); + }; + const TextItem = () => { const resultTitle = highlight?.fields.title ? ( ) => - asLink ? {children} : <>{children}; + asLink ? ( + + {children} + + ) : ( + <>{children} + ); const ListItemWrapper = ({ children }: PropsWithChildren<{}>) => asListItem ? ( diff --git a/plugins/user-settings/api-report.md b/plugins/user-settings/api-report.md index 136b23bd71..a38b37846a 100644 --- a/plugins/user-settings/api-report.md +++ b/plugins/user-settings/api-report.md @@ -7,6 +7,7 @@ import { ApiRef } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { BackstageUserIdentity } from '@backstage/core-plugin-api'; import { IconComponent } from '@backstage/core-plugin-api'; import { ProfileInfo } from '@backstage/core-plugin-api'; import { PropsWithChildren } from 'react'; @@ -70,6 +71,11 @@ export const UserSettingsFeatureFlags: () => JSX.Element; // @public (undocumented) export const UserSettingsGeneral: () => JSX.Element; +// Warning: (ae-missing-release-tag) "UserSettingsIdentityCard" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const UserSettingsIdentityCard: () => JSX.Element; + // Warning: (ae-missing-release-tag) "UserSettingsMenu" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -129,9 +135,17 @@ export const UserSettingsThemeToggle: () => JSX.Element; // Warning: (ae-missing-release-tag) "useUserProfile" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const useUserProfile: () => { - profile: ProfileInfo; - displayName: string; - loading: boolean; -}; +export const useUserProfile: () => + | { + profile: ProfileInfo; + displayName: string; + loading: boolean; + backstageIdentity?: undefined; + } + | { + profile: ProfileInfo; + backstageIdentity: BackstageUserIdentity; + displayName: string; + loading: false; + }; ``` diff --git a/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx b/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx index 6705997d1c..db7fdd7be6 100644 --- a/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsGeneral.tsx @@ -17,6 +17,7 @@ import { Grid } from '@material-ui/core'; import React from 'react'; import { UserSettingsProfileCard } from './UserSettingsProfileCard'; import { UserSettingsAppearanceCard } from './UserSettingsAppearanceCard'; +import { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; export const UserSettingsGeneral = () => { return ( @@ -27,6 +28,9 @@ export const UserSettingsGeneral = () => { + + + ); }; diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx new file mode 100644 index 0000000000..19c3eb2182 --- /dev/null +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + renderWithEffects, + wrapInTestApp, + TestApiRegistry, +} from '@backstage/test-utils'; +import { screen } from '@testing-library/react'; +import React from 'react'; +import { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; +import { ApiProvider } from '@backstage/core-app-api'; +import { identityApiRef } from '@backstage/core-plugin-api'; + +const apiRegistry = TestApiRegistry.from([ + identityApiRef, + { + getProfileInfo: jest.fn(async () => ({})), + getBackstageIdentity: jest.fn(async () => ({ + type: 'user' as const, + userEntityRef: 'foo:bar/foobar', + ownershipEntityRefs: ['test-ownership'], + })), + }, +]); + +describe('', () => { + it('displays an identity card', async () => { + await renderWithEffects( + wrapInTestApp( + + + , + ), + ); + + expect(screen.getByText('test-ownership')).toBeInTheDocument(); + expect(screen.getByText('foo:bar/foobar')).toBeInTheDocument(); + }); +}); diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx new file mode 100644 index 0000000000..908cda1423 --- /dev/null +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx @@ -0,0 +1,52 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { InfoCard } from '@backstage/core-components'; +import React from 'react'; +import { useUserProfile } from '../useUserProfileInfo'; +import Chip from '@material-ui/core/Chip'; +import Grid from '@material-ui/core/Grid'; +import Typography from '@material-ui/core/Typography'; + +export const UserSettingsIdentityCard = () => { + const { backstageIdentity } = useUserProfile(); + + return ( + + + + + + + User Entity:{' '} + + + + Ownership Entities:{' '} + {backstageIdentity?.ownershipEntityRefs.map(it => ( + + ))} + + + + + + + ); +}; diff --git a/plugins/user-settings/src/components/General/index.ts b/plugins/user-settings/src/components/General/index.ts index 80a9c75d89..ff4d1210c4 100644 --- a/plugins/user-settings/src/components/General/index.ts +++ b/plugins/user-settings/src/components/General/index.ts @@ -21,3 +21,4 @@ export { UserSettingsSignInAvatar } from './UserSettingsSignInAvatar'; export { UserSettingsAppearanceCard } from './UserSettingsAppearanceCard'; export { UserSettingsThemeToggle } from './UserSettingsThemeToggle'; export { UserSettingsPinToggle } from './UserSettingsPinToggle'; +export { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; diff --git a/plugins/user-settings/src/components/useUserProfileInfo.ts b/plugins/user-settings/src/components/useUserProfileInfo.ts index f893520cd2..c168fc12b4 100644 --- a/plugins/user-settings/src/components/useUserProfileInfo.ts +++ b/plugins/user-settings/src/components/useUserProfileInfo.ts @@ -53,6 +53,7 @@ export const useUserProfile = () => { return { profile: value!.profile, + backstageIdentity: value!.identity, displayName: value!.profile.displayName ?? value!.identity.userEntityRef, loading, }; diff --git a/yarn.lock b/yarn.lock index a82b4d5dab..0902601073 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2271,17 +2271,17 @@ teeny-request "^8.0.0" uuid "^8.0.0" -"@graphiql/react@^0.4.0": - version "0.4.0" - resolved "https://registry.npmjs.org/@graphiql/react/-/react-0.4.0.tgz#55099632c29be0c49f1251904b74cbfd2d31993b" - integrity sha512-9OtwzJ3EaDgD5Qi+WtnHA8Wv0XL9l+W4n3jtNR+wFDjC2vvbEd/grPm0eSikryVcq/0q6aR4HyR3SuKj6tKPYg== +"@graphiql/react@^0.4.1": + version "0.4.1" + resolved "https://registry.npmjs.org/@graphiql/react/-/react-0.4.1.tgz#c424951f4e1b2ffa22aa514b18663d7a848ff31f" + integrity sha512-YeB26Sc223zfv6wSzygKRfeJ7JeXZW40c6vY4Om/POXuytRyrxuKynuP1Z3ueGYY4Rji8YMg6dPAjtTOUDLjZw== dependencies: "@graphiql/toolkit" "^0.6.0" codemirror "^5.65.3" - codemirror-graphql "^1.3.0" + codemirror-graphql "^1.3.1" copy-to-clipboard "^3.2.0" escape-html "^1.0.3" - graphql-language-service "^5.0.4" + graphql-language-service "^5.0.5" markdown-it "^12.2.0" set-value "^4.1.0" @@ -5016,19 +5016,19 @@ resolved "https://registry.npmjs.org/@octokit/webhooks-methods/-/webhooks-methods-2.0.0.tgz#1108b9ea661ca6c81e4a8bfa63a09eb27d5bc2db" integrity sha512-35cfQ4YWlnZnmZKmIxlGPUPLtbkF8lr/A/1Sk1eC0ddLMwQN06dOuLc+dI3YLQS+T+MoNt3DIQ0NynwgKPilig== -"@octokit/webhooks-types@5.6.0": - version "5.6.0" - resolved "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-5.6.0.tgz#cbc908ef0df997de7f65da4e4003ecb8430410d3" - integrity sha512-y3MqE6N6Ksg1+YV0sXVpW2WP7Y24h7rUp2hDJuzoqWdKGr7owmRDyHC72INwfCYNzura/vsNPXvc6Xbfp4wGGw== +"@octokit/webhooks-types@5.7.1": + version "5.7.1" + resolved "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-5.7.1.tgz#26452dcd72fa77ac85bb188fda2a5980eb292932" + integrity sha512-zabCzfWvvquxDzj1lU7GhJQteACGfGXnHfROJD4A7LKhRjlkaggoSkE5cWQJJ6nW2t/UI51dSFrEA+A4mhqfPw== "@octokit/webhooks@^9.0.1", "@octokit/webhooks@^9.14.1": - version "9.24.0" - resolved "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-9.24.0.tgz#3e3b194ee67151f674e8d0d565c8179828a12b3d" - integrity sha512-s1nqplA+j4sP7Cz40jn/Q2ipkKRKJ7Gi+NzZiSnwNfisYNduLHEwMUJVBEKc5I0r6GMcZZRJOe6PJ2rJXYW66g== + version "9.25.0" + resolved "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-9.25.0.tgz#f1bd7815af59fb37892b87c86d2cb8625a570e9a" + integrity sha512-pyCraAmxHSnfTMe4K+QnNH/nSCJolCc++J2SAfYBwPFm6gg2WTGxWuegzuHul+Xm71+V9qL2NhIXX48U7MvTIA== dependencies: "@octokit/request-error" "^2.0.2" "@octokit/webhooks-methods" "^2.0.0" - "@octokit/webhooks-types" "5.6.0" + "@octokit/webhooks-types" "5.7.1" aggregate-error "^3.1.0" "@open-draft/until@^1.0.3": @@ -9589,12 +9589,12 @@ code-point-at@^1.0.0: resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= -codemirror-graphql@^1.3.0: - version "1.3.0" - resolved "https://registry.npmjs.org/codemirror-graphql/-/codemirror-graphql-1.3.0.tgz#6ca19eb2735dbfd5ac9db59b8fc4c8fc1e34fe43" - integrity sha512-Inqecp/PpUsNFz6+V6jpgQD1m7jjGg3yby60baw2t5yb2stBH8Z/6cHm/IYp9eN0Aq2EWqomd0GkGmiISPi4jQ== +codemirror-graphql@^1.3.1: + version "1.3.1" + resolved "https://registry.npmjs.org/codemirror-graphql/-/codemirror-graphql-1.3.1.tgz#c852b12b6909783681a5e37d61d1627a78f9c7a6" + integrity sha512-jlLwTARoMeuYLR5sQYbh5uYewIoYUYAn+0lOIKXpaHudk9X1rOrP/WtOqfDza1ETnyfnlpLidBnpieIMKktriQ== dependencies: - graphql-language-service "^5.0.4" + graphql-language-service "^5.0.5" codemirror@^5.65.3: version "5.65.3" @@ -12407,6 +12407,7 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: "@backstage/plugin-cloudbuild" "^0.3.6-next.1" "@backstage/plugin-code-coverage" "^0.1.33-next.1" "@backstage/plugin-cost-insights" "^0.11.28-next.2" + "@backstage/plugin-dynatrace" "^0.0.0" "@backstage/plugin-explore" "^0.3.37-next.1" "@backstage/plugin-gcalendar" "^0.3.2-next.1" "@backstage/plugin-gcp-projects" "^0.3.25-next.1" @@ -12618,7 +12619,7 @@ express-xml-bodyparser@^0.3.0: dependencies: xml2js "^0.4.11" -express@^4.17.1, express@^4.17.3: +express@^4.17.1, express@^4.17.3, express@^4.18.1: version "4.18.1" resolved "https://registry.npmjs.org/express/-/express-4.18.1.tgz#7797de8b9c72c857b9cd0e14a5eea80666267caf" integrity sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q== @@ -13905,14 +13906,14 @@ grapheme-splitter@^1.0.4: integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ== graphiql@^1.5.12, graphiql@^1.8.8: - version "1.9.6" - resolved "https://registry.npmjs.org/graphiql/-/graphiql-1.9.6.tgz#ab1714a0200bdcf358761d7e9625de41fe06a98c" - integrity sha512-HxKM2cu6SQUi8x1QqZc/GkLBnyjZerPOKmiBfsZmIWYLtZTJTd4dezeraD2klB80FkYKgPVPbojGLofuLq8w3w== + version "1.9.7" + resolved "https://registry.npmjs.org/graphiql/-/graphiql-1.9.7.tgz#2edadea4fbbd723f9ba27a1f464f4ff5b20866bd" + integrity sha512-rn0njwDkCpFn5GwDbSuzt7GwjiFLhYCdgiscYm4n8Oq9EeOyGrIxQK/PjUz1YaR/+T7lg1raIBuRAX/Nei9KcQ== dependencies: - "@graphiql/react" "^0.4.0" + "@graphiql/react" "^0.4.1" "@graphiql/toolkit" "^0.6.0" entities "^2.0.0" - graphql-language-service "^5.0.4" + graphql-language-service "^5.0.5" markdown-it "^12.2.0" graphlib@^2.1.8: @@ -13944,10 +13945,10 @@ graphql-executor@0.0.23: resolved "https://registry.npmjs.org/graphql-executor/-/graphql-executor-0.0.23.tgz#205c1764b39ee0fcf611553865770f37b45851a2" integrity sha512-3Ivlyfjaw3BWmGtUSnMpP/a4dcXCp0mJtj0PiPG14OKUizaMKlSEX+LX2Qed0LrxwniIwvU6B4w/koVjEPyWJg== -graphql-language-service@^5.0.4: - version "5.0.4" - resolved "https://registry.npmjs.org/graphql-language-service/-/graphql-language-service-5.0.4.tgz#068dd4ff5dc6fcc6c8560ccc8f05311d5fd63fcd" - integrity sha512-lX+ahYBwvTHJe1N7JqA08moNwbr0RWaFILxVnbciaaeb469TTIhQi87ZgVJ/y9Szre4d0r3vjIt2EstwafzcDA== +graphql-language-service@^5.0.5: + version "5.0.5" + resolved "https://registry.npmjs.org/graphql-language-service/-/graphql-language-service-5.0.5.tgz#894c08bee50070c97cc53ae514847aeef41bc0ac" + integrity sha512-hekBLI73r6ghShWrIMJ7Pe4Z+yJrda/U+kLenNJLNswuCrR0XfFOv5pNtnSXLcjFZkQfY1bwGV0D8IVKZEOW5Q== dependencies: nullthrows "^1.0.0" vscode-languageserver-types "^3.15.1" @@ -26099,7 +26100,7 @@ write-pkg@^4.0.0: type-fest "^0.4.1" write-json-file "^3.2.0" -ws@8.7.0, ws@^8.0.0, ws@^8.3.0: +ws@8.7.0: version "8.7.0" resolved "https://registry.npmjs.org/ws/-/ws-8.7.0.tgz#eaf9d874b433aa00c0e0d8752532444875db3957" integrity sha512-c2gsP0PRwcLFzUiA8Mkr37/MI7ilIlHQxaEAtd0uNMbVMoy8puJyafRlm0bV9MbGSabUPeLrRRaqIBcFcA2Pqg== @@ -26109,6 +26110,11 @@ ws@^7.3.1, ws@^7.4.6: resolved "https://registry.npmjs.org/ws/-/ws-7.5.7.tgz#9e0ac77ee50af70d58326ecff7e85eb3fa375e67" integrity sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A== +ws@^8.0.0, ws@^8.3.0: + version "8.8.0" + resolved "https://registry.npmjs.org/ws/-/ws-8.8.0.tgz#8e71c75e2f6348dbf8d78005107297056cb77769" + integrity sha512-JDAgSYQ1ksuwqfChJusw1LSJ8BizJ2e/vVu5Lxjq3YvNJNlROv1ui4i+c/kUUrPheBvQl4c5UbERhTwKa6QBJQ== + ws@^8.4.2: version "8.5.0" resolved "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f"