-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 7 commits
02c9725
beee09c
08689a0
eecb689
1ec2032
05899b3
453304a
5d8aa7b
d0576c6
40776c9
1519e70
6643e84
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,25 +14,36 @@ import ( | |||||
// create a constant block for schema keys | ||||||
|
||||||
const ( | ||||||
RepoTypesKey = "repo_types" | ||||||
NetworkAddressKey = "network_address" | ||||||
MySQLSettingsKey = "mysql_settings" | ||||||
DbVersionKey = "db_version" | ||||||
CharacterSetKey = "character_set" | ||||||
S3SettingsKey = "s3_settings" | ||||||
ProxyModeKey = "proxy_mode" | ||||||
DynamoDbSettingsKey = "dynamodb_settings" | ||||||
RepoTypesKey = "repo_types" | ||||||
NetworkAddressKey = "network_address" | ||||||
MySQLSettingsKey = "mysql_settings" | ||||||
DbVersionKey = "db_version" | ||||||
CharacterSetKey = "character_set" | ||||||
S3SettingsKey = "s3_settings" | ||||||
ProxyModeKey = "proxy_mode" | ||||||
DynamoDbSettingsKey = "dynamodb_settings" | ||||||
SQLServerSettingsKey = "sqlserver_settings" | ||||||
VersionKey = "version" | ||||||
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. How about (for clarity)?
Suggested change
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. yes, I took your suggestion. Thanks |
||||||
) | ||||||
|
||||||
func tlsModes() []string { | ||||||
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. bring this change in later (since it's not being planned for implementation right now)? 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. thank you, leftover from refactor. Missed this one. |
||||||
return []string{ | ||||||
"allow", // default, must be kept at position 0 | ||||||
"require", | ||||||
"disable", | ||||||
} | ||||||
} | ||||||
|
||||||
// SidecarListener struct for sidecar listener. | ||||||
type SidecarListener struct { | ||||||
SidecarId string `json:"-"` | ||||||
ListenerId string `json:"id"` | ||||||
RepoTypes []string `json:"repoTypes"` | ||||||
NetworkAddress *NetworkAddress `json:"address,omitempty"` | ||||||
MySQLSettings *MySQLSettings `json:"mysqlSettings,omitempty"` | ||||||
S3Settings *S3Settings `json:"s3Settings,omitempty"` | ||||||
DynamoDbSettings *DynamoDbSettings `json:"dynamoDbSettings,omitempty"` | ||||||
SidecarId string `json:"-"` | ||||||
ListenerId string `json:"id"` | ||||||
RepoTypes []string `json:"repoTypes"` | ||||||
NetworkAddress *NetworkAddress `json:"address,omitempty"` | ||||||
MySQLSettings *MySQLSettings `json:"mysqlSettings,omitempty"` | ||||||
S3Settings *S3Settings `json:"s3Settings,omitempty"` | ||||||
DynamoDbSettings *DynamoDbSettings `json:"dynamoDbSettings,omitempty"` | ||||||
SQLServerSettings *SQLServerSettings `json:"sqlServerSettings,omitempty"` | ||||||
} | ||||||
type NetworkAddress struct { | ||||||
Host string `json:"host,omitempty"` | ||||||
|
@@ -49,6 +60,10 @@ type DynamoDbSettings struct { | |||||
ProxyMode bool `json:"proxyMode,omitempty"` | ||||||
} | ||||||
|
||||||
type SQLServerSettings struct { | ||||||
Version string `json:"version,omitempty"` | ||||||
} | ||||||
|
||||||
var ReadSidecarListenersConfig = ResourceOperationConfig{ | ||||||
Name: "SidecarListenersResourceRead", | ||||||
HttpMethod: http.MethodGet, | ||||||
|
@@ -83,6 +98,7 @@ func (data ReadSidecarListenerAPIResponse) WriteToSchema(d *schema.ResourceData) | |||||
_ = d.Set(S3SettingsKey, data.ListenerConfig.S3SettingsAsInterface()) | ||||||
_ = d.Set(MySQLSettingsKey, data.ListenerConfig.MySQLSettingsAsInterface()) | ||||||
_ = d.Set(DynamoDbSettingsKey, data.ListenerConfig.DynamoDbSettingsAsInterface()) | ||||||
_ = d.Set(SQLServerSettingsKey, data.ListenerConfig.SQLServerSettingsAsInterface()) | ||||||
} | ||||||
log.Printf("[DEBUG] End ReadSidecarListenerAPIResponse.WriteToSchema") | ||||||
return nil | ||||||
|
@@ -175,6 +191,22 @@ func (l *SidecarListener) DynamoDbSettingsFromInterface(anInterface []interface{ | |||||
ProxyMode: anInterface[0].(map[string]interface{})[ProxyModeKey].(bool), | ||||||
} | ||||||
} | ||||||
func (l *SidecarListener) SQLServerSettingsAsInterface() []interface{} { | ||||||
if l.SQLServerSettings == nil { | ||||||
return nil | ||||||
} | ||||||
return []interface{}{map[string]interface{}{ | ||||||
VersionKey: l.SQLServerSettings.Version, | ||||||
}} | ||||||
} | ||||||
func (l *SidecarListener) SQLServerSettingsFromInterface(anInterface []interface{}) { | ||||||
if len(anInterface) == 0 { | ||||||
return | ||||||
} | ||||||
l.SQLServerSettings = &SQLServerSettings{ | ||||||
Version: anInterface[0].(map[string]interface{})[VersionKey].(string), | ||||||
} | ||||||
} | ||||||
|
||||||
// SidecarListenerResource represents the payload of a create or update a listener request | ||||||
type SidecarListenerResource struct { | ||||||
|
@@ -192,6 +224,8 @@ func (s *SidecarListenerResource) ReadFromSchema(d *schema.ResourceData) error { | |||||
s.ListenerConfig.MySQLSettingsFromInterface(d.Get(MySQLSettingsKey).(*schema.Set).List()) | ||||||
s.ListenerConfig.S3SettingsFromInterface(d.Get(S3SettingsKey).(*schema.Set).List()) | ||||||
s.ListenerConfig.DynamoDbSettingsFromInterface(d.Get(DynamoDbSettingsKey).(*schema.Set).List()) | ||||||
s.ListenerConfig.SQLServerSettingsFromInterface(d.Get(SQLServerSettingsKey).(*schema.Set).List()) | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
|
@@ -205,7 +239,7 @@ func resourceSidecarListener() *schema.Resource { | |||||
return &schema.Resource{ | ||||||
Description: "Manages [sidecar listeners](https://cyral.com/docs/sidecars/sidecar-listeners)." + | ||||||
"\n~> **Warning** Multiple listeners can be associated to a single sidecar as long as " + | ||||||
"`host` and `port` are unique. If `host` is ommitted, then `port` must be unique.", | ||||||
"`host` and `port` are unique. If `host` is omitted, then `port` must be unique.", | ||||||
CreateContext: CreateResource( | ||||||
ResourceOperationConfig{ | ||||||
Name: "SidecarListenersResourceCreate", | ||||||
|
@@ -315,7 +349,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{S3SettingsKey, DynamoDbSettingsKey}, | ||||||
ConflictsWith: []string{S3SettingsKey, DynamoDbSettingsKey, SQLServerSettingsKey}, | ||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
DbVersionKey: { | ||||||
|
@@ -352,7 +386,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}, | ||||||
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. Should we also update the ConflictsWith: []string{S3SettingsKey, MySQLSettingsKey, SQLServerSettingsKey} 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. yes, sorry. Fixed |
||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
ProxyModeKey: { | ||||||
|
@@ -402,5 +436,34 @@ func getSidecarListenerSchema() map[string]*schema.Schema { | |||||
}, | ||||||
}, | ||||||
}, | ||||||
SQLServerSettingsKey: { | ||||||
Description: "SQL Server settings.", | ||||||
Type: schema.TypeSet, | ||||||
Optional: true, | ||||||
// Notice the MaxItems: 1 here. This ensures that the user can only specify one this block. | ||||||
MaxItems: 1, | ||||||
ConflictsWith: []string{S3SettingsKey, MySQLSettingsKey, DynamoDbSettingsKey}, | ||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
VersionKey: { | ||||||
Description: "Advertised SQL Server version. Required (and only relevant) for " + | ||||||
"Listeners of type 'sqlserver' " + | ||||||
"The format of the version should be <major>.<minor>.<build_number> " + | ||||||
"API will validate that the version is a valid version number. " + | ||||||
"Major version is an integer in range 0-255. " + | ||||||
"Minor version is an integer in range 0-255. " + | ||||||
"Build number is an integer in range 0-65535. " + | ||||||
"Example: 16.0.1000 " + | ||||||
"To get the version of the SQL Server runtime, run the following query: " + | ||||||
"SELECT SERVERPROPERTY('productversion') " + | ||||||
"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, | ||||||
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.
Suggested change
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. 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. 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. Sure, my intention here is just to point out that there's no need to specify 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. ah, sorry I didn't get that at first :) Want me to remove and push or leave it be? 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. @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. 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. 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). |
||||||
Required: true, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
} |
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.
nit: could you please delete this blank line so that all 3rd party imports are in the same block?
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.
fixed