sourcegraph/lib
Robert Lin 857d5200b3
feat/dotcom: use Enterprise Portal for Cody Gateway usage (#63653)
Closes https://linear.app/sourcegraph/issue/CORE-211

See https://linear.app/sourcegraph/issue/CORE-100 for a higher-level
view - this is the first proof-of-concept for achieving our migration
strategy to extract Enterprise subscription data out of dotcom while
retaining the existing UI until a future project ships a dedicated
Enterprise Portal UI
(https://linear.app/sourcegraph/project/kr-p-enterprise-portal-user-interface-dadd5ff28bd8).

The integration uses generated ConnectRPC client code + `react-query`,
the latter of which has already been used elsewhere for SSC
integrations. This is partly supported by
https://github.com/connectrpc/connect-query-es which offers
mostly-first-class integration with `react-query`, but I had to do some
fenangling to provide the query clients directly as I can't get the
React provider thing to work. The ConnectRPC clients point to the
proxies introduced in
https://github.com/sourcegraph/sourcegraph/pull/63652 which
authenticates the requests for Enterprise Portal, until we ship
https://linear.app/sourcegraph/project/kr-p1-streamlined-role-assignment-via-sams-and-entitle-2f118b3f9d4c/overview

## Test plan

### Local

First, `sg start dotcom`

Choose a subscription you have locally. Use `psql -d sourcegraph` to
connect to local database, then:

```
sourcegraph=# delete from product_licenses where product_subscription_id = '<local subscription ID>';
DELETE 1
sourcegraph=# update product_subscriptions set id = '58b95c21-c2d0-4b4b-8b15-bf1b926d3557' where id = '<local subscription ID>';
UPDATE 1
```

Now annoyingly the UI will break because there is no license, we need:

```gql
query getGraphQLID {
  dotcom {
    productSubscription(uuid:"58b95c21-c2d0-4b4b-8b15-bf1b926d3557") {
      id # graphQL ID
    }
  }
}

mutation createLicense {
  dotcom {
    generateProductLicenseForSubscription(productSubscriptionID:"<graphQLID>", license:{
      tags:["dev"]
      userCount:100
      expiresAt:1814815397
    }) {
      id
    }
  }
}
```

This effectively lets us have a "pretend S2" subscription locally.
Visiting the subscription page now at
https://sourcegraph.test:3443/site-admin/dotcom/product/subscriptions/58b95c21-c2d0-4b4b-8b15-bf1b926d3557


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/1e77d77d-8032-436b-ab1d-393b34e8e4b5)

The data matches the "real" data currently at
https://sourcegraph.com/site-admin/dotcom/product/subscriptions/58b95c21-c2d0-4b4b-8b15-bf1b926d3557

### Against dotcom

```
sg start web-standalone
```

follow
https://www.loom.com/share/6cb3b3ca475b4b9392aa4b11938e76e6?sid=6cd1a689-d75d-4133-bcff-b0c7d25b23f1
and then check out some product subscriptions
2024-07-10 19:22:08 +00:00
..
accesstoken chore: Expose ParsePersonalAccessToken publicly for src-cli (#62587) 2024-05-10 19:32:14 +08:00
api enterprise: Move last directory out (#57392) 2023-10-05 20:15:40 +00:00
background feat/cody-gateway: use Enterprise Portal for actor/productsubscriptions (#62934) 2024-06-07 11:46:01 -07:00
batches batches: use "keyword" as default pattern type (#63613) 2024-07-09 10:35:01 +02:00
cliutil sg: improve positional completions (#58569) 2023-11-27 16:30:59 -08:00
codeintel chore(codeintel): Differentiate between paths relative to upload root vs repo root (#63437) 2024-06-24 20:27:26 +08:00
enterpriseportal feat/dotcom: use Enterprise Portal for Cody Gateway usage (#63653) 2024-07-10 19:22:08 +00:00
errors chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
gitservice bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
iterator ci: re-enable race detection (#52776) 2023-06-05 20:41:47 +02:00
managedservicesplatform chore/otel-collector: upgrade to v0.103.0, remove jaegerexporter (#63171) 2024-07-10 09:01:41 -07:00
output fix(local): fix race in sg_start_test.go (#63642) 2024-07-04 19:11:10 +02:00
pointers feat/sg: add 'sg enterprise' commands for Cody Analytics (#63414) 2024-06-21 16:29:31 -07:00
process fix/sg: fix mangled log output from sg start and sg run (#63405) 2024-06-20 16:07:27 -07:00
redislock enterprise-portal: implement basic MSP IAM and RPCs (#63173) 2024-06-19 21:46:48 -04:00
servicecatalog bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
telemetrygateway internal/telemetry: make adding EventsStore middleware easier (#63216) 2024-06-13 11:55:06 +01:00
buf.yaml lib/enterpriseportal: initial service API for RFC 885 (#62263) 2024-05-15 12:58:55 -07:00
go.mod feat/enterpriseportal: validate and normalize instance domains (#63415) 2024-06-21 16:14:23 -07:00
go.sum feat/enterpriseportal: validate and normalize instance domains (#63415) 2024-06-21 16:14:23 -07:00
README.md lib: Introduce non-enterprise lib directory (#18992) 2021-03-10 19:41:33 -06:00
tools.go bump to Go 1.22.1 (#60902) 2024-03-06 17:38:43 -07:00

Sourcegraph lib module

This directory is the root of a separate go module from the primary module rooted at sourcegraph/sourcegraph. This module exists to hold code that we want to reuse outside of the sourcegraph/sourcegraph repo.

Code in this module should not import from sourcegraph/sourcegraph or from other Sourcegraph repositories to avoid complicated dependency relationships. Instead consider moving code from elsewhere into this module.