Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

feat/enterpriseportal: implement UpdateCodyGatewayAccess #63926

Merged

Conversation

bobheadxi
Copy link
Member

@bobheadxi bobheadxi commented Jul 18, 2024

Implements the only Cody Access write API we have right now, the ability to apply overrides to Cody Gateway rate limits, which we'll have in Enterprise Portal with https://github.com/sourcegraph/sourcegraph/pull/63858

A lot of the diff is a new generated mock for the Cody Access store so that we can write some simple unit tests.

With this addition, all initially proposed Cody Gateway access APIs are implemented.

Part of https://linear.app/sourcegraph/issue/CORE-218
Closes https://linear.app/sourcegraph/issue/CORE-160

Test plan

Unit and existing integration tests

@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from d7e4757 to 6529733 Compare July 18, 2024 20:58
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 03604aa to e659c84 Compare July 18, 2024 20:58
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch 2 times, most recently from 5097b92 to 2987359 Compare July 18, 2024 21:33
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 3ce5453 to 0b64444 Compare July 18, 2024 21:34
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 2987359 to e81f272 Compare July 18, 2024 21:34
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 0b64444 to 5a5d757 Compare July 18, 2024 22:39
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from e81f272 to a5c9edb Compare July 18, 2024 22:39
@bobheadxi bobheadxi marked this pull request as ready for review July 18, 2024 22:40
@bobheadxi bobheadxi requested a review from a team July 18, 2024 22:40
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from a5c9edb to e786e7a Compare July 18, 2024 22:47
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from ab95895 to f9f0fa8 Compare July 19, 2024 18:16
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from e786e7a to 889233c Compare July 19, 2024 18:16
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from f9f0fa8 to ad3dc7b Compare July 19, 2024 18:56
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from a42857f to 6bb1bea Compare July 19, 2024 18:57
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from ad3dc7b to b125b3e Compare July 19, 2024 21:07
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 2fa6111 to 5726960 Compare July 19, 2024 21:07
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 4ac0f1c to 74b7746 Compare August 7, 2024 16:37
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 3b1da16 to c68cb07 Compare August 7, 2024 18:18
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 74b7746 to 2990832 Compare August 7, 2024 18:19
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from c68cb07 to 47163fe Compare August 7, 2024 18:25
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 2990832 to 225b19f Compare August 7, 2024 18:25
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 47163fe to f27525f Compare August 7, 2024 18:32
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 225b19f to d702c53 Compare August 7, 2024 18:32
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from f27525f to 8739a6f Compare August 7, 2024 18:45
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from d702c53 to 6731b8f Compare August 7, 2024 18:45
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 8739a6f to 07dcdf6 Compare August 7, 2024 21:13
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 6731b8f to cbfba83 Compare August 7, 2024 21:13
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 07dcdf6 to 3bf020e Compare August 7, 2024 23:16
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from cbfba83 to 5cc880c Compare August 7, 2024 23:16
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from 3bf020e to c8dd5d0 Compare August 7, 2024 23:18
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 5cc880c to 0e7192d Compare August 7, 2024 23:18
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access branch from c8dd5d0 to 6211943 Compare August 8, 2024 17:03
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 0e7192d to 8e39464 Compare August 8, 2024 17:03
Comment on lines +152 to +182
// 🚨 SECURITY: Require approrpiate M2M scope.
requiredScope := samsm2m.EnterprisePortalScope(
scopes.PermissionEnterprisePortalCodyAccess, scopes.ActionWrite)
clientAttrs, err := samsm2m.RequireScope(ctx, logger, s.store, requiredScope, req)
if err != nil {
return nil, err
}
logger = logger.With(clientAttrs...)

subscriptionID := req.Msg.GetAccess().SubscriptionId
if subscriptionID == "" {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("subscription ID is required"))
}

var opts codyaccess.UpsertCodyGatewayAccessOptions

update := req.Msg.GetAccess()
fieldPaths := req.Msg.GetUpdateMask().GetPaths()
// Empty field paths means update all non-empty fields.
if len(fieldPaths) == 0 {
if update.Enabled {
opts.Enabled = pointers.Ptr(update.Enabled)
}
if update.GetChatCompletionsRateLimit().GetLimit() > 0 {
opts.ChatCompletionsRateLimit = pointers.Ptr(
int64(update.GetChatCompletionsRateLimit().Limit),
)
}
if update.GetChatCompletionsRateLimit().GetIntervalDuration().GetSeconds() > 0 {
opts.ChatCompletionsRateLimitIntervalSeconds = pointers.Ptr(
int32(update.GetChatCompletionsRateLimit().GetIntervalDuration().Seconds),

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: security-semgrep-rules.semgrep-rules.generic.comment-tagging-rule Note

Code that highlight SECURITY in comment has changed. Please review the code for changes. The changes might be sensitive.
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from 4a2c055 to be61fc6 Compare August 8, 2024 17:24
Base automatically changed from 07-18-feat_enterpriseportal_use_enterprise_portal_database_for_cody_gateway_access to main August 8, 2024 17:39
@bobheadxi bobheadxi force-pushed the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch from be61fc6 to 6251655 Compare August 8, 2024 17:39
@bobheadxi bobheadxi merged commit 076498f into main Aug 8, 2024
14 checks passed
@bobheadxi bobheadxi deleted the 07-18-feat_enterpriseportal_implement_updatecodygatewayaccess branch August 8, 2024 20:21
bobheadxi referenced this pull request Aug 8, 2024
…tal (#64090)

Upgrades the self-contained Cody Gateway modal to only depend on
Enterprise Portal to read/write Cody Gateway access.

I also made some minor tweaks to parsing empty form inputs, and also
made the "Cody Gateway access token" collapsed by default, with warnings
to discourage its use (opted not to remove entirely since it may be
useful for dev/debugging)

Depends on:

- https://github.com/sourcegraph/sourcegraph/pull/63926 
- https://github.com/sourcegraph/sourcegraph/pull/63925 
- https://github.com/sourcegraph/sourcegraph/pull/63858 

Closes https://linear.app/sourcegraph/issue/CORE-218

## Test plan

```
sg start dotcom
```

Edit the Cody Gateway access stuff, toggling it up and down.
Cross-reference with the `enterprise_portal_cody_gateway_access` table.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants