-
Notifications
You must be signed in to change notification settings - Fork 89
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
Pass-through un-configurable options for enterprise connections #802
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,12 +84,19 @@ func expandConnection( | |
connection.Realms = value.Strings(config.GetAttr("realms")) | ||
} | ||
|
||
var diagnostics diag.Diagnostics | ||
connection.Options, diagnostics = expandConnectionOptions(data, strategy) | ||
|
||
if connectionIsEnterprise(strategy) { | ||
connection.ShowAsButton = value.Bool(config.GetAttr("show_as_button")) | ||
} | ||
|
||
var diagnostics diag.Diagnostics | ||
connection.Options, diagnostics = expandConnectionOptions(data, strategy) | ||
if !data.IsNewResource() { | ||
err := passThroughUnconfigurableConnectionOptions(ctx, api, data.Id(), strategy, connection) | ||
if err != nil { | ||
return nil, diag.FromErr(err) | ||
} | ||
} | ||
} | ||
|
||
// Prevent erasing database configuration secrets. | ||
if !data.IsNewResource() && strategy == management.ConnectionStrategyAuth0 { | ||
|
@@ -773,3 +780,198 @@ func expandConnectionOptionsScopes(data *schema.ResourceData, options scoper) { | |
options.SetScopes(true, scope.(string)) | ||
} | ||
} | ||
|
||
// passThroughUnconfigurableConnectionOptions ensures that read-only connection options | ||
// set by external services do not get removed from the connection resource. | ||
// | ||
// This is necessary because the "/api/v2/connections/{id}" endpoint does not follow usual | ||
// PATCH behavior, the 'options' property is entirely replaced by the payload object. | ||
func passThroughUnconfigurableConnectionOptions( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
strategy string, | ||
connection *management.Connection, | ||
) error { | ||
var err error | ||
|
||
switch strategy { | ||
case management.ConnectionStrategyAD: | ||
err = passThroughUnconfigurableConnectionOptionsAD(ctx, api, connectionID, connection) | ||
case management.ConnectionStrategyAzureAD: | ||
err = passThroughUnconfigurableConnectionOptionsAzureAD(ctx, api, connectionID, connection) | ||
case management.ConnectionStrategySAML: | ||
err = passThroughUnconfigurableConnectionOptionsSAML(ctx, api, connectionID, connection) | ||
case management.ConnectionStrategyADFS: | ||
err = passThroughUnconfigurableConnectionOptionsADFS(ctx, api, connectionID, connection) | ||
case management.ConnectionStrategyPingFederate: | ||
err = passThroughUnconfigurableConnectionOptionsPingFederate(ctx, api, connectionID, connection) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func passThroughUnconfigurableConnectionOptionsAD( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
connection *management.Connection, | ||
) error { | ||
existingConnection, err := api.Connection.Read(ctx, connectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existingConnection.Options == nil { | ||
return nil | ||
} | ||
|
||
existingOptions := existingConnection.Options.(*management.ConnectionOptionsAD) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized after the initial implementation is that we should perform a nil check against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious: Can an already created enterprise connection, not have any options defined? 🤔 I added a nil check in which case we'll skip over the func call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually not sure and to your point, even if it were possible it should be incredibly rare. This would only be precautionary since we've seen occasional panics with type assertions. If you are certain that it is not applicable here, we can remove. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mind keeping the check for now. |
||
|
||
expandedOptions := connection.Options.(*management.ConnectionOptionsAD) | ||
expandedOptions.Thumbprints = existingOptions.Thumbprints | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
expandedOptions.Certs = existingOptions.Certs | ||
expandedOptions.AgentIP = existingOptions.AgentIP | ||
expandedOptions.AgentVersion = existingOptions.AgentVersion | ||
expandedOptions.AgentMode = existingOptions.AgentMode | ||
|
||
connection.Options = expandedOptions | ||
|
||
return nil | ||
} | ||
|
||
func passThroughUnconfigurableConnectionOptionsAzureAD( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
connection *management.Connection, | ||
) error { | ||
existingConnection, err := api.Connection.Read(ctx, connectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existingConnection.Options == nil { | ||
return nil | ||
} | ||
|
||
existingOptions := existingConnection.Options.(*management.ConnectionOptionsAzureAD) | ||
|
||
expandedOptions := connection.Options.(*management.ConnectionOptionsAzureAD) | ||
expandedOptions.Thumbprints = existingOptions.Thumbprints | ||
expandedOptions.AppDomain = existingOptions.AppDomain | ||
expandedOptions.CertRolloverNotification = existingOptions.CertRolloverNotification | ||
expandedOptions.Granted = existingOptions.Granted | ||
expandedOptions.TenantID = existingOptions.TenantID | ||
|
||
connection.Options = expandedOptions | ||
|
||
return nil | ||
} | ||
|
||
func passThroughUnconfigurableConnectionOptionsADFS( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
connection *management.Connection, | ||
) error { | ||
existingConnection, err := api.Connection.Read(ctx, connectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existingConnection.Options == nil { | ||
return nil | ||
} | ||
|
||
existingOptions := existingConnection.Options.(*management.ConnectionOptionsADFS) | ||
|
||
expandedOptions := connection.Options.(*management.ConnectionOptionsADFS) | ||
expandedOptions.Thumbprints = existingOptions.Thumbprints | ||
expandedOptions.CertRolloverNotification = existingOptions.CertRolloverNotification | ||
expandedOptions.EntityID = existingOptions.EntityID | ||
expandedOptions.PreviousThumbprints = existingOptions.PreviousThumbprints | ||
|
||
connection.Options = expandedOptions | ||
|
||
return nil | ||
} | ||
|
||
func passThroughUnconfigurableConnectionOptionsSAML( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
connection *management.Connection, | ||
) error { | ||
existingConnection, err := api.Connection.Read(ctx, connectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existingConnection.Options == nil { | ||
return nil | ||
} | ||
|
||
existingOptions := existingConnection.Options.(*management.ConnectionOptionsSAML) | ||
|
||
expandedOptions := connection.Options.(*management.ConnectionOptionsSAML) | ||
expandedOptions.Thumbprints = existingOptions.Thumbprints | ||
expandedOptions.BindingMethod = existingOptions.BindingMethod | ||
expandedOptions.CertRolloverNotification = existingOptions.CertRolloverNotification | ||
expandedOptions.AgentIP = existingOptions.AgentIP | ||
expandedOptions.AgentVersion = existingOptions.AgentVersion | ||
expandedOptions.AgentMode = existingOptions.AgentMode | ||
expandedOptions.ExtGroups = existingOptions.ExtGroups | ||
expandedOptions.ExtProfile = existingOptions.ExtProfile | ||
|
||
connection.Options = expandedOptions | ||
|
||
return nil | ||
} | ||
|
||
func passThroughUnconfigurableConnectionOptionsPingFederate( | ||
ctx context.Context, | ||
api *management.Management, | ||
connectionID string, | ||
connection *management.Connection, | ||
) error { | ||
existingConnection, err := api.Connection.Read(ctx, connectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if existingConnection.Options == nil { | ||
return nil | ||
} | ||
|
||
existingOptions := existingConnection.Options.(*management.ConnectionOptionsPingFederate) | ||
|
||
expandedOptions := connection.Options.(*management.ConnectionOptionsPingFederate) | ||
expandedOptions.APIEnableUsers = existingOptions.APIEnableUsers | ||
expandedOptions.SignOutEndpoint = existingOptions.SignOutEndpoint | ||
expandedOptions.Subject = existingOptions.Subject | ||
expandedOptions.DisableSignout = existingOptions.DisableSignout | ||
expandedOptions.UserIDAttribute = existingOptions.UserIDAttribute | ||
expandedOptions.Debug = existingOptions.Debug | ||
expandedOptions.ProtocolBinding = existingOptions.ProtocolBinding | ||
expandedOptions.RequestTemplate = existingOptions.RequestTemplate | ||
expandedOptions.Thumbprints = existingOptions.Thumbprints | ||
expandedOptions.BindingMethod = existingOptions.BindingMethod | ||
expandedOptions.Expires = existingOptions.Expires | ||
expandedOptions.MetadataURL = existingOptions.MetadataURL | ||
expandedOptions.FieldsMap = existingOptions.FieldsMap | ||
expandedOptions.MetadataXML = existingOptions.MetadataXML | ||
expandedOptions.EntityID = existingOptions.EntityID | ||
expandedOptions.CertRolloverNotification = existingOptions.CertRolloverNotification | ||
expandedOptions.SigningKey = existingOptions.SigningKey | ||
expandedOptions.DecryptionKey = existingOptions.DecryptionKey | ||
expandedOptions.AgentIP = existingOptions.AgentIP | ||
expandedOptions.AgentVersion = existingOptions.AgentVersion | ||
expandedOptions.AgentMode = existingOptions.AgentMode | ||
expandedOptions.ExtGroups = existingOptions.ExtGroups | ||
expandedOptions.ExtProfile = existingOptions.ExtProfile | ||
|
||
connection.Options = expandedOptions | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or something similar.