Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab Org Data integration fetches memberships via graphQL #16856

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

jamieklassen
Copy link
Member

Hey, I just made a Pull Request!

Resolves #16023. The GraphQL API could be leveraged more thoroughly to cut down on traffic to GitLab, but this covers the basic requirement to make the integration usable without an admin PAT.

I performed some end-to-end acceptance testing with the following procedure on my Mac:

  1. Create a kind cluster and install gitlab locally via helm, running:
    git clone https://gitlab.com/gitlab-org/charts/gitlab.git
    cd gitlab
    helm repo add gitlab https://charts.gitlab.io/
    helm repo update
    kind create cluster --config examples/kind/kind-no-ssl.yaml
    helm upgrade --install gitlab gitlab/gitlab \
      --set global.hosts.domain=$(ipconfig getifaddr en0).nip.io \
      -f examples/kind/values-base.yaml \
      -f examples/kind/values-no-ssl.yaml
  2. Log in at gitlab.$(ipconfig getifaddr en0).nip.io with the username root and password given by
    kubectl get secret gitlab-gitlab-initial-root-password -o go-template='{{.data.password | base64decode}}'
  3. Create a non-admin user, impersonate them and provision an access token
  4. Create any other users and groups to test
  5. Add the org data entity provider to the backend via a patch like
     @@ -19,6 +19,7 @@ import { EntityProvider } from '@backstage/plugin-catalog-node';
     import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
     import { Router } from 'express';
     import { PluginEnvironment } from '../types';
    +import { GitlabOrgDiscoveryEntityProvider } from '@backstage/plugin-catalog-backend-module-gitlab';
     
     export default async function createPlugin(
       env: PluginEnvironment,
    @@ -27,6 +28,15 @@ export default async function createPlugin(
       const builder = await CatalogBuilder.create(env);
       builder.addProcessor(new ScaffolderEntitiesProcessor());
       builder.addEntityProvider(providers ?? []);
    +  builder.addEntityProvider(
    +    ...GitlabOrgDiscoveryEntityProvider.fromConfig(env.config, {
    +      logger: env.logger,
    +      schedule: env.scheduler.createScheduledTaskRunner({
    +        frequency: { minutes: 1 },
    +        timeout: { minutes: 5 },
    +      }),
    +    }),
    +  );
       const { processingEngine, router } = await builder.build();
       await processingEngine.start();
       return router;
  6. Run yarn dev with an app-config.local.yaml like:
    integrations: 
      gitlab: 
        - host: gitlab.$(ipconfig getifaddr en0).nip.io
          token: glpat-XXXXXXXXXXXXXXXXXXXX # non-admin token from step 3. above
          apiBaseUrl: http://gitlab.$(ipconfig getifaddr en0).nip.io/api/v4
          baseUrl: http://gitlab.$(ipconfig getifaddr en0).nip.io
    catalog: 
      locations: []
      providers: 
        gitlab: 
          providerId: 
            host: gitlab.$(ipconfig getifaddr en0).nip.io
            orgEnabled: true
  7. Browse the catalog.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

Signed-off-by: Jamie Klassen <jklassen@vmware.com>
@jamieklassen jamieklassen requested review from a team as code owners March 14, 2023 20:51
@github-actions github-actions bot added area:catalog Related to the Catalog Project Area documentation Improvements or additions to documentation labels Mar 14, 2023
@backstage-goalie
Copy link
Contributor

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-catalog-backend-module-gitlab plugins/catalog-backend-module-gitlab patch v0.1.14

@jamieklassen jamieklassen changed the title Gitlab orgdata nonadmin Gitlab Org Data integration fetches memberships via graphQL Mar 14, 2023
Jamie Klassen added 2 commits March 14, 2023 17:08
The new `getGroupMembers` method replaces the existing `getUserMemberships` on
`GitLabClient`.

Signed-off-by: Jamie Klassen <jklassen@vmware.com>
Signed-off-by: Jamie Klassen <jklassen@vmware.com>
Signed-off-by: Jamie Klassen <jklassen@vmware.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2023

Uffizzi Preview deployment-18964 was deleted.

Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's try it!

@freben freben merged commit e00f382 into backstage:master Mar 15, 2023
@github-actions
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.13.0 release, scheduled for Tue, 18 Apr 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: use GraphQL to discover gitlab group memberships
2 participants