forked from theaaf/cloudformation-media-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedialive_input.go
81 lines (71 loc) · 1.88 KB
/
medialive_input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/medialive"
)
func init() {
RegisterType("Custom::MediaLiveInput", MediaLiveInput)
}
func createMediaLiveInput(props map[string]interface{}, client *medialive.MediaLive) (*Success, error) {
var input medialive.CreateInputInput
if err := ReshapeProps(props, &input); err != nil {
return nil, err
}
resp, err := client.CreateInputRequest(&input).Send()
if err != nil {
return nil, err
}
return &Success{
PhysicalResourceId: *resp.Input.Id,
Data: map[string]interface{}{
"Arn": *resp.Input.Arn,
"Id": *resp.Input.Id,
},
}, nil
}
func MediaLiveInput(request *CustomResourceRequest, cfg aws.Config) (*Success, error) {
client := medialive.New(cfg)
switch request.RequestType {
case "Create":
return createMediaLiveInput(request.ResourceProperties, client)
case "Update":
needsReplacement := false
updateProps := make(map[string]interface{})
for k, v := range request.ResourceProperties {
switch k {
case "Type":
if v != request.OldResourceProperties[k] {
needsReplacement = true
}
default:
updateProps[k] = v
}
}
if needsReplacement {
return createMediaLiveInput(request.ResourceProperties, client)
}
var input medialive.UpdateInputInput
if err := ReshapeProps(updateProps, &input); err != nil {
return nil, err
}
input.InputId = &request.PhysicalResourceId
resp, err := client.UpdateInputRequest(&input).Send()
if err != nil {
return nil, err
}
return &Success{
PhysicalResourceId: *resp.Input.Id,
Data: map[string]interface{}{
"Arn": *resp.Input.Arn,
"Id": *resp.Input.Id,
},
}, nil
case "Delete":
_, err := client.DeleteInputRequest(&medialive.DeleteInputInput{
InputId: &request.PhysicalResourceId,
}).Send()
return nil, err
}
return nil, fmt.Errorf("unexpected request type")
}