mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-29 17:58:15 +08:00
Implement Create/Update for auth connectors (#33181)
Updates services.UserService and auth.ClientI to contain the Create and Update methods for all auth connectors and implements them at the client, server, and services layer. Upsert was untouched to prevent breaking e and will be addressed in a follow up PR. Contributes to #30416.
This commit is contained in:
+75
-2
@@ -103,7 +103,29 @@ func (g *GithubConverter) UpsertGithubConnector(ctx context.Context, connector t
|
||||
if err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
return g.ClientI.UpsertGithubConnector(ctx, convertedConnector)
|
||||
|
||||
err = g.ClientI.UpsertGithubConnector(ctx, convertedConnector)
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
|
||||
func (g *GithubConverter) CreateGithubConnector(ctx context.Context, connector types.GithubConnector) (types.GithubConnector, error) {
|
||||
convertedConnector, err := services.ConvertGithubConnector(connector)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
created, err := g.ClientI.CreateGithubConnector(ctx, convertedConnector)
|
||||
return created, trace.Wrap(err)
|
||||
}
|
||||
|
||||
func (g *GithubConverter) UpdateGithubConnector(ctx context.Context, connector types.GithubConnector) (types.GithubConnector, error) {
|
||||
convertedConnector, err := services.ConvertGithubConnector(connector)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
updated, err := g.ClientI.UpdateGithubConnector(ctx, convertedConnector)
|
||||
return updated, trace.Wrap(err)
|
||||
}
|
||||
|
||||
// CreateGithubAuthRequest creates a new request for Github OAuth2 flow
|
||||
@@ -135,7 +157,7 @@ func (a *Server) upsertGithubConnector(ctx context.Context, connector types.Gith
|
||||
if err := a.UpsertGithubConnector(ctx, connector); err != nil {
|
||||
return trace.Wrap(err)
|
||||
}
|
||||
if err := a.emitter.EmitAuditEvent(a.closeCtx, &apievents.GithubConnectorCreate{
|
||||
if err := a.emitter.EmitAuditEvent(ctx, &apievents.GithubConnectorCreate{
|
||||
Metadata: apievents.Metadata{
|
||||
Type: events.GithubConnectorCreatedEvent,
|
||||
Code: events.GithubConnectorCreatedCode,
|
||||
@@ -151,6 +173,57 @@ func (a *Server) upsertGithubConnector(ctx context.Context, connector types.Gith
|
||||
return nil
|
||||
}
|
||||
|
||||
// createGithubConnector creates a new Github connector.
|
||||
func (a *Server) createGithubConnector(ctx context.Context, connector types.GithubConnector) (types.GithubConnector, error) {
|
||||
if err := checkGithubOrgSSOSupport(ctx, connector, nil, a.githubOrgSSOCache, nil); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
|
||||
created, err := a.CreateGithubConnector(ctx, connector)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
if err := a.emitter.EmitAuditEvent(ctx, &apievents.GithubConnectorCreate{
|
||||
Metadata: apievents.Metadata{
|
||||
Type: events.GithubConnectorCreatedEvent,
|
||||
Code: events.GithubConnectorCreatedCode,
|
||||
},
|
||||
UserMetadata: authz.ClientUserMetadata(ctx),
|
||||
ResourceMetadata: apievents.ResourceMetadata{
|
||||
Name: connector.GetName(),
|
||||
},
|
||||
}); err != nil {
|
||||
log.WithError(err).Warn("Failed to emit GitHub connector create event.")
|
||||
}
|
||||
|
||||
return created, nil
|
||||
}
|
||||
|
||||
// updateGithubConnector updates an existing Github connector.
|
||||
func (a *Server) updateGithubConnector(ctx context.Context, connector types.GithubConnector) (types.GithubConnector, error) {
|
||||
if err := checkGithubOrgSSOSupport(ctx, connector, nil, a.githubOrgSSOCache, nil); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
updated, err := a.UpdateGithubConnector(ctx, connector)
|
||||
if err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
if err := a.emitter.EmitAuditEvent(ctx, &apievents.GithubConnectorCreate{
|
||||
Metadata: apievents.Metadata{
|
||||
Type: events.GithubConnectorCreatedEvent,
|
||||
Code: events.GithubConnectorCreatedCode,
|
||||
},
|
||||
UserMetadata: authz.ClientUserMetadata(ctx),
|
||||
ResourceMetadata: apievents.ResourceMetadata{
|
||||
Name: connector.GetName(),
|
||||
},
|
||||
}); err != nil {
|
||||
log.WithError(err).Warn("Failed to emit GitHub connector create event.")
|
||||
}
|
||||
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
// httpRequester allows a net/http.Client to be mocked for tests.
|
||||
// TODO(capnspacehook): test without using this interface
|
||||
type httpRequester interface {
|
||||
|
||||
Reference in New Issue
Block a user