Skip to content

Commit

Permalink
chore: allow use of old and new aws client
Browse files Browse the repository at this point in the history
OTT-6126
  • Loading branch information
thatsddr committed Jul 12, 2024
1 parent 2d4df69 commit b18c97a
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion awsmt/data_source_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (d *dataSourceChannel) Configure(_ context.Context, req datasource.Configur
return
}

d.client = req.ProviderData.(*mediatailor.MediaTailor)
d.client = req.ProviderData.(clients).v1
}

func (d *dataSourceChannel) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/data_source_live_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (d *dataSourceLiveSource) Configure(_ context.Context, req datasource.Confi
return
}

d.client = req.ProviderData.(*mediatailor.MediaTailor)
d.client = req.ProviderData.(clients).v1
}

func (d *dataSourceLiveSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/data_source_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *dataSourcePlaybackConfiguration) Configure(_ context.Context, req datas
return
}

d.client = req.ProviderData.(*mediatailor.MediaTailor)
d.client = req.ProviderData.(clients).v1
}

func (d *dataSourcePlaybackConfiguration) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/data_source_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (d *dataSourceSourceLocation) Configure(_ context.Context, req datasource.C
return
}

d.client = req.ProviderData.(*mediatailor.MediaTailor)
d.client = req.ProviderData.(clients).v1
}

func (d *dataSourceSourceLocation) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/data_source_vod_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *dataSourceVodSource) Configure(_ context.Context, req datasource.Config
return
}

d.client = req.ProviderData.(*mediatailor.MediaTailor)
d.client = req.ProviderData.(clients).v1
}

func (d *dataSourceVodSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
5 changes: 4 additions & 1 deletion awsmt/helpers_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ func readPlaybackConfigToPlan(plan playbackConfigurationModel, playbackConfigura

// MANIFEST PROCESSING RULES
if playbackConfiguration.ManifestProcessingRules != nil {
plan = readManifestProcessingRules(plan, playbackConfiguration)
var mpr = playbackConfiguration.ManifestProcessingRules
if mpr.AdMarkerPassthrough != nil && mpr.AdMarkerPassthrough.Enabled != nil && *mpr.AdMarkerPassthrough.Enabled {
plan.ManifestProcessingRules = &manifestProcessingRulesModel{AdMarkerPassthrough: &adMarkerPassthroughModel{Enabled: mpr.AdMarkerPassthrough.Enabled}}
}
}

plan.Name, plan.PersonalizationThresholdSeconds, plan.PlaybackEndpointPrefix, plan.SessionInitializationEndpointPrefix, plan.SlateAdUrl, plan.TranscodeProfileName, plan.VideoContentSourceUrl, plan.Tags = readPlaybackConfigurationTemps(plan, playbackConfiguration)
Expand Down
27 changes: 23 additions & 4 deletions awsmt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package awsmt

import (
"context"
v2 "github.com/aws/aws-sdk-go-v2/aws"
v2config "github.com/aws/aws-sdk-go-v2/config"
v2mt "github.com/aws/aws-sdk-go-v2/service/mediatailor"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/mediatailor"
Expand Down Expand Up @@ -29,6 +32,11 @@ type awsmtProviderModel struct {
Region types.String `tfsdk:"region"`
}

type clients struct {
v1 *mediatailor.MediaTailor
v2 *v2mt.Client
}

func (p *awsmtProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "awsmt"
}
Expand Down Expand Up @@ -60,14 +68,16 @@ func (p *awsmtProvider) Configure(ctx context.Context, req provider.ConfigureReq

var region = "eu-central-1"
var profile = ""
var err error
// Old sdk version creation
var sess *session.Session
// New sdk version creation
var cfg v2.Config

if !config.Region.IsUnknown() || !config.Region.IsNull() {
region = config.Region.ValueString()
}

var sess *session.Session
var err error

if config.Profile.IsUnknown() || config.Profile.IsNull() || config.Profile.ValueString() == "" {
if os.Getenv("AWS_PROFILE") != "" {
profile = os.Getenv("AWS_PROFILE")
Expand All @@ -79,23 +89,32 @@ func (p *awsmtProvider) Configure(ctx context.Context, req provider.ConfigureReq
tflog.Debug(ctx, "Creating AWS client session")

if profile != "" {
// Old sdk
sess, err = session.NewSessionWithOptions(session.Options{

Check failure on line 93 in awsmt/provider.go

View workflow job for this annotation

GitHub Actions / Lint Code

ineffectual assignment to err (ineffassign)
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{
Region: aws.String(region),
},
Profile: profile,
})
// New sdk
cfg, err = v2config.LoadDefaultConfig(ctx, v2config.WithSharedConfigProfile(profile), v2config.WithRegion(region))
} else {
// Old sdk
sess, err = session.NewSession(&aws.Config{Region: aws.String(region)})

Check failure on line 104 in awsmt/provider.go

View workflow job for this annotation

GitHub Actions / Lint Code

ineffectual assignment to err (ineffassign)
// New sdk
cfg, err = v2config.LoadDefaultConfig(ctx, v2config.WithRegion(region))
}

if err != nil {
resp.Diagnostics.AddError("Failed to Initialize Provider in Region", "unable to initialize provider in the specified region: "+err.Error())
return
}

c := mediatailor.New(sess)
c := clients{
v1: mediatailor.New(sess),
v2: v2mt.NewFromConfig(cfg),
}

resp.DataSourceData = c
resp.ResourceData = c
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *resourceChannel) Configure(_ context.Context, req resource.ConfigureReq
return
}

r.client = req.ProviderData.(*mediatailor.MediaTailor)
r.client = req.ProviderData.(clients).v1
}

func (r *resourceChannel) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_live_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *resourceLiveSource) Configure(_ context.Context, req resource.Configure
return
}

r.client = req.ProviderData.(*mediatailor.MediaTailor)
r.client = req.ProviderData.(clients).v1
}

func (r *resourceLiveSource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *resourcePlaybackConfiguration) Configure(_ context.Context, req resourc
return
}

r.client = req.ProviderData.(*mediatailor.MediaTailor)
r.client = req.ProviderData.(clients).v1
}

func (r *resourcePlaybackConfiguration) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *resourceSourceLocation) Configure(_ context.Context, req resource.Confi
return
}

r.client = req.ProviderData.(*mediatailor.MediaTailor)
r.client = req.ProviderData.(clients).v1
}

func (r *resourceSourceLocation) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
5 changes: 1 addition & 4 deletions awsmt/resource_vod_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ func (r *resourceVodSource) Metadata(_ context.Context, req resource.MetadataReq
resp.TypeName = req.ProviderTypeName + "_vod_source"
}

// @ADR
// Context: The schemas for the VOD Source and the LIVE source are almost identical, except for one field.
// Decision: We decided to make the duplication undetectable for SonarCloud
func (r *resourceVodSource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -73,7 +70,7 @@ func (r *resourceVodSource) Configure(_ context.Context, req resource.ConfigureR
return
}

r.client = req.ProviderData.(*mediatailor.MediaTailor)
r.client = req.ProviderData.(clients).v1
}

func (r *resourceVodSource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.26 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.26 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect
github.com/aws/aws-sdk-go-v2/service/mediatailor v1.40.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand Down
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/aws/aws-sdk-go v1.47.5 h1:U2JlfPmrUoz5p+2X/XwKxmaJFo2oV+LbJqx8jyEvyAY=
github.com/aws/aws-sdk-go v1.47.5/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc=
github.com/aws/aws-sdk-go-v2/config v1.27.26 h1:T1kAefbKuNum/AbShMsZEro6eRkeOT8YILfE9wyjAYQ=
github.com/aws/aws-sdk-go-v2/config v1.27.26/go.mod h1:ivWHkAWFrw/nxty5Fku7soTIVdqZaZ7dw+tc5iGW3GA=
github.com/aws/aws-sdk-go-v2/credentials v1.17.26 h1:tsm8g/nJxi8+/7XyJJcP2dLrnK/5rkFp6+i2nhmz5fk=
github.com/aws/aws-sdk-go-v2/credentials v1.17.26/go.mod h1:3vAM49zkIa3q8WT6o9Ve5Z0vdByDMwmdScO0zvThTgI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 h1:KreluoV8FZDEtI6Co2xuNk/UqI9iwMrOx/87PBNIKqw=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11/go.mod h1:SeSUYBLsMYFoRvHE0Tjvn7kbxaUhl75CJi1sbfhMxkU=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 h1:SoNJ4RlFEQEbtDcCEt+QG56MY4fm4W8rYirAmq+/DdU=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15/go.mod h1:U9ke74k1n2bf+RIgoX1SXFed1HLs51OgUSs+Ph0KJP8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 h1:C6WHdGnTDIYETAm5iErQUiVNsclNx9qbJVPIt03B6bI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15/go.mod h1:ZQLZqhcu+JhSrA9/NXRm8SkDvsycE+JkV3WGY41e+IM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 h1:dT3MqvGhSoaIhRseqw2I0yH81l7wiR2vjs57O51EAm8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3/go.mod h1:GlAeCkHwugxdHaueRr4nhPuY+WW+gR8UjlcqzPr1SPI=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 h1:HGErhhrxZlQ044RiM+WdoZxp0p+EGM62y3L6pwA4olE=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17/go.mod h1:RkZEx4l0EHYDJpWppMJ3nD9wZJAa8/0lq9aVC+r2UII=
github.com/aws/aws-sdk-go-v2/service/mediatailor v1.40.3 h1:GpQjYLjSut2LHI4jw7aMxQ/Tx8B8GLdKY7jcDngk130=
github.com/aws/aws-sdk-go-v2/service/mediatailor v1.40.3/go.mod h1:cbgPAannZfnXy9W74odbFh30dLvz2UfsLbh8NMIBRNM=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.3 h1:Fv1vD2L65Jnp5QRsdiM64JvUM4Xe+E0JyVsRQKv6IeA=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.3/go.mod h1:ooyCOXjvJEsUw7x+ZDHeISPMhtwI3ZCB7ggFMcFfWLU=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 h1:yiwVzJW2ZxZTurVbYWA7QOrAaCYQR72t0wrSBfoesUE=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4/go.mod h1:0oxfLkpz3rQ/CHlx5hB7H69YUpFiI1tql6Q6Ne+1bCw=
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 h1:ZsDKRLXGWHk8WdtyYMoGNO7bTudrvuKpDKgMVRlepGE=
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3/go.mod h1:zwySh8fpFyXp9yOr/KVzxOl8SRqgf/IDw5aUt9UKFcQ=
github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE=
github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand Down

0 comments on commit b18c97a

Please sign in to comment.