Skip to content

Commit

Permalink
Merge pull request #86 from spring-media/chore/OTT-6334
Browse files Browse the repository at this point in the history
Chore/ott 6334
  • Loading branch information
thatsddr authored Aug 21, 2024
2 parents 30531b3 + fe19888 commit 3298ec4
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 344 deletions.
20 changes: 10 additions & 10 deletions awsmt/data_source_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package awsmt

import (
"context"
"github.com/aws/aws-sdk-go/service/mediatailor"
"github.com/aws/aws-sdk-go-v2/service/mediatailor"
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand All @@ -19,7 +19,7 @@ func DataSourceChannel() datasource.DataSource {
}

type dataSourceChannel struct {
client *mediatailor.MediaTailor
client *mediatailor.Client
}

func (d *dataSourceChannel) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -86,26 +86,25 @@ func (d *dataSourceChannel) Configure(_ context.Context, req datasource.Configur
return
}

d.client = req.ProviderData.(clients).v1
d.client = req.ProviderData.(clients).v2
}

func (d *dataSourceChannel) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data channelModel
diags := req.Config.Get(ctx, &data)
resp.Diagnostics.Append(diags...)
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

channelName := data.Name

channel, err := d.client.DescribeChannel(&mediatailor.DescribeChannelInput{ChannelName: channelName})
channel, err := d.client.DescribeChannel(ctx, &mediatailor.DescribeChannelInput{ChannelName: channelName})
if err != nil {
resp.Diagnostics.AddError("Error while describing channel "+*channelName, err.Error())
return
}

policy, err := d.client.GetChannelPolicy(&mediatailor.GetChannelPolicyInput{ChannelName: channelName})
policy, err := d.client.GetChannelPolicy(ctx, &mediatailor.GetChannelPolicyInput{ChannelName: channelName})
if err != nil && !strings.Contains(err.Error(), "NotFound") {
resp.Diagnostics.AddError(
"Error while getting the channel policy "+err.Error(),
Expand All @@ -114,12 +113,13 @@ func (d *dataSourceChannel) Read(ctx context.Context, req datasource.ReadRequest
return
}

if policy.Policy != nil {
if policy != nil && policy.Policy != nil {
data.Policy = jsontypes.NewNormalizedPointerValue(policy.Policy)
}

if channel.ChannelState != nil {
data.ChannelState = channel.ChannelState
if channel.ChannelState != "" {
channelState := string(channel.ChannelState)
data.ChannelState = &channelState
}

data = writeChannelToState(data, *channel)
Expand Down
6 changes: 2 additions & 4 deletions awsmt/data_source_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ func (d *dataSourcePlaybackConfiguration) Schema(_ context.Context, _ datasource
"content_segment_url_prefix": computedString,
},
},
"configuration_aliases": schema.ListAttribute{
"configuration_aliases": schema.MapAttribute{
Computed: true,
ElementType: types.MapType{
ElemType: types.MapType{
ElemType: types.StringType,
},
ElemType: types.StringType,
},
},
"dash_configuration": schema.SingleNestedAttribute{
Expand Down
46 changes: 27 additions & 19 deletions awsmt/data_source_playback_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,35 @@ import (
)

func TestAccPlaybackConfigurationDataSourceBasic(t *testing.T) {
resourceName := "data.awsmt_playback_configuration.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: playbackConfigDS(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "id", "example-playback-configuration-awsmt"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "ad_decision_server_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "avail_suppression.fill_policy", "FULL_AVAIL_ONLY"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "avail_suppression.mode", "BEHIND_LIVE_EDGE"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "avail_suppression.value", "00:00:00"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "bumper.end_url", "https://wxample.com/endbumper"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "bumper.start_url", "https://wxample.com/startbumper"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "cdn_configuration.ad_segment_url_prefix", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "cdn_configuration.content_segment_url_prefix", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "dash_configuration.mpd_location", "DISABLED"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "dash_configuration.origin_manifest_type", "SINGLE_PERIOD"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "live_pre_roll_configuration.ad_decision_server_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "live_pre_roll_configuration.max_duration_seconds", "2"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "name", "example-playback-configuration-awsmt"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "personalization_threshold_seconds", "2"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "slate_ad_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "tags.Environment", "dev"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "video_content_source_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr("data.awsmt_playback_configuration.test", "log_configuration_percent_enabled", "0"),
resource.TestCheckResourceAttr(resourceName, "id", "example-playback-configuration-awsmt"),
resource.TestCheckResourceAttr(resourceName, "ad_decision_server_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "avail_suppression.fill_policy", "FULL_AVAIL_ONLY"),
resource.TestCheckResourceAttr(resourceName, "avail_suppression.mode", "BEHIND_LIVE_EDGE"),
resource.TestCheckResourceAttr(resourceName, "avail_suppression.value", "00:00:00"),
resource.TestCheckResourceAttr(resourceName, "bumper.end_url", "https://wxample.com/endbumper"),
resource.TestCheckResourceAttr(resourceName, "bumper.start_url", "https://wxample.com/startbumper"),
resource.TestCheckResourceAttr(resourceName, "cdn_configuration.ad_segment_url_prefix", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "cdn_configuration.content_segment_url_prefix", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "configuration_aliases.%", "1"),
resource.TestCheckResourceAttr(resourceName, "configuration_aliases.player_params.foo.player_params.bar", "player_params.buzz"),
resource.TestCheckResourceAttr(resourceName, "dash_configuration.mpd_location", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "dash_configuration.origin_manifest_type", "SINGLE_PERIOD"),
resource.TestCheckResourceAttr(resourceName, "live_pre_roll_configuration.ad_decision_server_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "live_pre_roll_configuration.max_duration_seconds", "2"),
resource.TestCheckResourceAttr(resourceName, "name", "example-playback-configuration-awsmt"),
resource.TestCheckResourceAttr(resourceName, "personalization_threshold_seconds", "2"),
resource.TestCheckResourceAttr(resourceName, "slate_ad_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "tags.Environment", "dev"),
resource.TestCheckResourceAttr(resourceName, "video_content_source_url", "https://exampleurl.com/"),
resource.TestCheckResourceAttr(resourceName, "log_configuration_percent_enabled", "0"),
),
},
},
Expand Down Expand Up @@ -68,6 +71,11 @@ func playbackConfigDS() string {
ad_segment_url_prefix = "https://exampleurl.com/"
content_segment_url_prefix = "https://exampleurl.com/"
}
configuration_aliases = {
"player_params.foo" = {
"player_params.bar" = "player_params.buzz"
}
}
dash_configuration = {
mpd_location = "DISABLED",
origin_manifest_type = "SINGLE_PERIOD"
Expand Down
Loading

0 comments on commit 3298ec4

Please sign in to comment.