Skip to content
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

ENG-12292: Add: SQL Server settings (version field) #438

Merged
merged 12 commits into from
Sep 12, 2023
Merged

Conversation

gengdahlCyral
Copy link
Contributor

@gengdahlCyral gengdahlCyral commented Aug 14, 2023

Note! Crud v5.9.0 has the API additions for which this TF PR is targeted.

Description of the change

The background to the changes made in the Cyral Terraform Provider is the updated listener API {{baseUrl}}/sidecars/:sidecarID/listeners.

This API has been extended with a complex attribute (similar to the mysql settings attribute):

  • Sql server settings (optional)
    • version (string in format x.y.z) Required
      The SQL server settings is applicable for listeners associated with SQL server repo type only, and is only relevant for listeners that are multiplexed.
      Version is the version the sidecar will advertise in PRELOGIN MESSAGE to the client connecting.

Short description of changes in this PR:
This PR introduces changes to the Makefile, cyral/data_source_cyral_sidecar_listener.go,

In the Makefile, an up-deps target has been added to update module and test dependencies to the latest minor and patch levels.

In cyral/data_source_cyral_sidecar_listener.go, SQL Server settings have been added to the SidecarListener struct. This includes a new SQLServerSettings struct, methods to convert to and from interface representations, and relevant constants.

In cyral/resource_cyral_sidecar_listener.go, the SidecarListener struct has been expanded to include SQL Server settings similar to other data repository settings. Additionally, SQL Server settings methods for interface conversion have been added. The schema definition for SQL Server settings has also been included in the getSidecarListenerSchema function.

In cyral/resource_cyral_sidecar_listener_test.go, a test step has been added to cover SQL Server settings.

Documentation files (docs/data-sources/sidecar_listener.md and docs/resources/sidecar_listener.md) have been generated from updated code.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Jira issue referenced in commit message and/or PR title

Testing

Using Helm CP running updated crud

  • Created a listener without Sql server settings using TF.
  • Updated listener with sql server settings, but no version -> error from TF (expected)
  • Updated listener with valid server version (no error)
  • Listed listeners, noticed presence of sql server version
  • tried incorrect version format -> error from API (expected)

…s has one attribute: version. This is mandatory for listeners that are multiplexed.
…cific version (parent element is optional though). Added computed to the two optional elements "override repo client tls settings" and "tls mode" since these are populated by API if not provided.
@gengdahlCyral gengdahlCyral marked this pull request as ready for review August 15, 2023 12:21
@wcmjunior wcmjunior changed the title ENG-12292 - Add: SQL Server settings, Override client tls flag and TLS mode for listeners ENG-12292: Add: SQL Server settings, Override client tls flag and TLS mode for listeners Aug 17, 2023
@gengdahlCyral gengdahlCyral changed the title ENG-12292: Add: SQL Server settings, Override client tls flag and TLS mode for listeners ENG-12292: Add: SQL Server settings (version field) Aug 21, 2023
@@ -8,8 +8,9 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could you please delete this blank line so that all 3rd party imports are in the same block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

ProxyModeKey = "proxy_mode"
DynamoDbSettingsKey = "dynamodb_settings"
SQLServerSettingsKey = "sqlserver_settings"
VersionKey = "version"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about (for clarity)?

Suggested change
VersionKey = "version"
SQLServerVersionKey = "version"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I took your suggestion. Thanks

)

func tlsModes() []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bring this change in later (since it's not being planned for implementation right now)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, leftover from refactor. Missed this one.

Copy link
Contributor

@wcmjunior wcmjunior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests to cover the ConflictsWith controls.

…alidation. Updated setupSidecarListenerConfig method to support constructing faulty configurations (switch -> multiple if statements)
@gengdahlCyral
Copy link
Contributor Author

Please add some tests to cover the ConflictsWith controls.

Addressed by d0576c6

dbVersion, charSet := "null", "null"
if listener.MySQLSettings.CharacterSet != "" {
charSet = fmt.Sprintf(`"%s"`, listener.MySQLSettings.CharacterSet)
}
if listener.MySQLSettings.DbVersion != "" {
dbVersion = fmt.Sprintf(`"%s"`, listener.MySQLSettings.DbVersion)
}
settings = fmt.Sprintf(
settings += fmt.Sprintf(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ doesn't actually look required here, but shouldn't hurt to keep either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually intentional in order to create an invalid configuration (conflicting settings)

Copy link
Member

@juniocezar juniocezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes looks good to me, regarding what the API expects.

Copy link
Contributor

@VictorGFM VictorGFM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good @gengdahlCyral, please consider my comment below regarding the ConflictsWith validation before we merge the PR, thanks

@@ -352,7 +378,7 @@ func getSidecarListenerSchema() map[string]*schema.Schema {
Optional: true,
// Notice the MaxItems: 1 here. This ensures that the user can only specify one this block.
MaxItems: 1,
ConflictsWith: []string{MySQLSettingsKey, DynamoDbSettingsKey},
ConflictsWith: []string{MySQLSettingsKey, DynamoDbSettingsKey, SQLServerSettingsKey},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also update the ConflictsWith in DynamoDbSettingsKey?

ConflictsWith: []string{S3SettingsKey, MySQLSettingsKey, SQLServerSettingsKey}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry. Fixed

"Note: If the query returns a four part version number, only the first three parts " +
"should be used. Example: 16.0.1000.6 -> 16.0.1000",
Type: schema.TypeString,
Optional: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Optional: false,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In API Sqlserver settings is optional, if provided though, it has to carry the version so I believe we want to align with that here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, my intention here is just to point out that there's no need to specify Optional: false - it can be omitted from the schema declaration, especially because we are already defining Required: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry I didn't get that at first :) Want me to remove and push or leave it be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gengdahlCyral thats just a nit, so up to you! Let me know once we can merge the PR and I can help with that, changes look good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I removed this line, it's a bit confusing to have optional and required mixed (and not really valid when I read the docs).
Feel free to merge. @VictorGFM

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@VictorGFM VictorGFM merged commit 79b4d46 into main Sep 12, 2023
3 checks passed
@VictorGFM VictorGFM deleted the feature/ENG-12292 branch September 12, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants