MCPcopy Create free account
hub / github.com/bytebase/bytebase / CreateOAuth2Client

Method CreateOAuth2Client

backend/store/oauth2_client.go:27–53  ·  view source on GitHub ↗
(ctx context.Context, create *OAuth2ClientMessage)

Source from the content-addressed store, hash-verified

25}
26
27func (s *Store) CreateOAuth2Client(ctx context.Context, create *OAuth2ClientMessage) (*OAuth2ClientMessage, error) {
28 configBytes, err := protojson.Marshal(create.Config)
29 if err != nil {
30 return nil, errors.Wrap(err, "failed to marshal config")
31 }
32
33 var workspaceArg any
34 if create.Workspace != "" {
35 workspaceArg = create.Workspace
36 }
37
38 q := qb.Q().Space(`
39 INSERT INTO oauth2_client (client_id, workspace, client_secret_hash, config, last_active_at)
40 VALUES (?, ?, ?, ?, NOW())
41 RETURNING last_active_at
42 `, create.ClientID, workspaceArg, create.ClientSecretHash, configBytes)
43
44 query, args, err := q.ToSQL()
45 if err != nil {
46 return nil, err
47 }
48
49 if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&create.LastActiveAt); err != nil {
50 return nil, errors.Wrap(err, "failed to create OAuth2 client")
51 }
52 return create, nil
53}
54
55// GetOAuth2Client looks up a client by client_id (the table's primary key).
56// Workspace is no longer a lookup key — clients are workspace-agnostic since

Callers 1

handleRegisterMethod · 0.80

Calls 5

GetDBMethod · 0.95
QFunction · 0.92
SpaceMethod · 0.80
ToSQLMethod · 0.80
ScanMethod · 0.80

Tested by

no test coverage detected