Skip to content

Commit

Permalink
fix: update access control
Browse files Browse the repository at this point in the history
OTT-6361
  • Loading branch information
thatsddr committed Aug 30, 2024
1 parent 789f411 commit 42dfef6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
51 changes: 22 additions & 29 deletions awsmt/helpers_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ func getCreateSourceLocationInput(model sourceLocationModel) mediatailor.CreateS
var params mediatailor.CreateSourceLocationInput

// Access Configuration
if model.AccessConfiguration != nil {
params.AccessConfiguration = getAccessConfigurationInput(model.AccessConfiguration)
}
params.AccessConfiguration = getAccessConfigurationInput(model.AccessConfiguration)

// Default Segment Delivery Configuration
if model.DefaultSegmentDeliveryConfiguration != nil {
params.DefaultSegmentDeliveryConfiguration = getDefaultSegmentDeliveryConfigurationInput(model.DefaultSegmentDeliveryConfiguration)
}
params.DefaultSegmentDeliveryConfiguration = getDefaultSegmentDeliveryConfigurationInput(model.DefaultSegmentDeliveryConfiguration)

// HTTP Configuration
if model.HttpConfiguration != nil {
params.HttpConfiguration = getHttpConfigurationInput(model.HttpConfiguration)
}
params.HttpConfiguration = getHttpConfigurationInput(model.HttpConfiguration)

// Source Location Name
params.SourceLocationName = model.Name
Expand All @@ -47,7 +42,7 @@ func getAccessConfigurationInput(accessConfiguration *accessConfigurationModel)

temp := &awsTypes.AccessConfiguration{}

if accessConfiguration.AccessType != nil && *accessConfiguration.AccessType != "" {
if accessConfiguration.AccessType != nil {
var accessType awsTypes.AccessType
switch *accessConfiguration.AccessType {
case "SECRETS_MANAGER_ACCESS_TOKEN":
Expand Down Expand Up @@ -82,19 +77,25 @@ func getSMATC(smatc secretsManagerAccessTokenConfigurationModel) *awsTypes.Secre
}

func getDefaultSegmentDeliveryConfigurationInput(defaultSegmentDeliveryConfiguration *defaultSegmentDeliveryConfigurationModel) *awsTypes.DefaultSegmentDeliveryConfiguration {
temp := &awsTypes.DefaultSegmentDeliveryConfiguration{}
if defaultSegmentDeliveryConfiguration.BaseUrl != nil && *defaultSegmentDeliveryConfiguration.BaseUrl != "" {
temp.BaseUrl = defaultSegmentDeliveryConfiguration.BaseUrl
if defaultSegmentDeliveryConfiguration.BaseUrl == nil || *defaultSegmentDeliveryConfiguration.BaseUrl == "" {
return nil
}
temp := &awsTypes.DefaultSegmentDeliveryConfiguration{
BaseUrl: defaultSegmentDeliveryConfiguration.BaseUrl,
}

return temp
}

func getHttpConfigurationInput(httpConfiguration *httpConfigurationModel) *awsTypes.HttpConfiguration {
temp := &awsTypes.HttpConfiguration{}
if httpConfiguration != nil {
if httpConfiguration.BaseUrl != nil && *httpConfiguration.BaseUrl != "" {
temp.BaseUrl = httpConfiguration.BaseUrl
}
if httpConfiguration == nil {
return nil
}
if httpConfiguration.BaseUrl == nil || *httpConfiguration.BaseUrl == "" {
return nil
}
temp := &awsTypes.HttpConfiguration{
BaseUrl: httpConfiguration.BaseUrl,
}
return temp
}
Expand All @@ -113,19 +114,11 @@ func getSegmentDeliveryConfigurationsInput(segmentDeliveryConfigurations []segme
func getUpdateSourceLocationInput(model sourceLocationModel) mediatailor.UpdateSourceLocationInput {
var params mediatailor.UpdateSourceLocationInput

// Access Configuration
if model.AccessConfiguration != nil {
params.AccessConfiguration = getAccessConfigurationInput(model.AccessConfiguration)
}
params.AccessConfiguration = getAccessConfigurationInput(model.AccessConfiguration)
// Default Segment Delivery Configuration
if model.DefaultSegmentDeliveryConfiguration != nil {
params.DefaultSegmentDeliveryConfiguration = getDefaultSegmentDeliveryConfigurationInput(model.DefaultSegmentDeliveryConfiguration)
}

params.DefaultSegmentDeliveryConfiguration = getDefaultSegmentDeliveryConfigurationInput(model.DefaultSegmentDeliveryConfiguration)
// HTTP Configuration
if model.HttpConfiguration != nil {
params.HttpConfiguration = getHttpConfigurationInput(model.HttpConfiguration)
}
params.HttpConfiguration = getHttpConfigurationInput(model.HttpConfiguration)

// Segment Delivery Configurations
if len(model.SegmentDeliveryConfigurations) > 0 && model.SegmentDeliveryConfigurations != nil {
Expand Down
4 changes: 2 additions & 2 deletions awsmt/resource_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (r *resourceSourceLocation) Schema(_ context.Context, _ resource.SchemaRequ
Optional: true,
Attributes: map[string]schema.Attribute{
"access_type": schema.StringAttribute{
Optional: true,
Required: true,
Validators: []validator.String{
stringvalidator.OneOf("S3_SIGV4", "SECRETS_MANAGER_ACCESS_TOKEN"),
stringvalidator.OneOf("S3_SIGV4", "SECRETS_MANAGER_ACCESS_TOKEN", "AUTODETECT_SIGV4"),
},
},
"smatc": schema.SingleNestedAttribute{
Expand Down
3 changes: 1 addition & 2 deletions awsmt/resource_source_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func TestAccSourceLocationResource(t *testing.T) {
},
// Update and Read testing
{
Config: basicSourceLocationWithAccessConfig(name, baseUrl2, k3, v3, k2, v2),
Config: basicSourceLocation(name, baseUrl2, k3, v3, k2, v2),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", "test_source_location"),
resource.TestCheckResourceAttr(resourceName, "access_configuration.access_type", "S3_SIGV4"),
resource.TestCheckResourceAttr(resourceName, "name", "test_source_location"),
resource.TestCheckResourceAttr(resourceName, "http_configuration.base_url", "https://ott-mediatailor-test.s3.eu-central-1.amazonaws.com"),
resource.TestCheckResourceAttr(resourceName, "default_segment_delivery_configuration.base_url", "https://example.com/"),
Expand Down

0 comments on commit 42dfef6

Please sign in to comment.