forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_alicloud_fc.go
81 lines (73 loc) · 2.52 KB
/
service_alicloud_fc.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 alicloud
import (
"fmt"
"strings"
"github.com/aliyun/fc-go-sdk"
"github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity"
)
type FcService struct {
client *connectivity.AliyunClient
}
func (s *FcService) DescribeFcService(name string) (service *fc.GetServiceOutput, err error) {
raw, err := s.client.WithFcClient(func(fcClient *fc.Client) (interface{}, error) {
return fcClient.GetService(&fc.GetServiceInput{ServiceName: &name})
})
if err != nil {
if IsExceptedErrors(err, []string{ServiceNotFound}) {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Service", name))
} else {
err = fmt.Errorf("GetService %s got an error: %#v.", name, err)
}
return
}
service, _ = raw.(*fc.GetServiceOutput)
if service == nil || *service.ServiceName == "" {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Service", name))
}
return
}
func (s *FcService) DescribeFcFunction(service, name string) (function *fc.GetFunctionOutput, err error) {
raw, err := s.client.WithFcClient(func(fcClient *fc.Client) (interface{}, error) {
return fcClient.GetFunction(&fc.GetFunctionInput{
ServiceName: &service,
FunctionName: &name,
})
})
if err != nil {
if IsExceptedErrors(err, []string{ServiceNotFound, FunctionNotFound}) {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Function", name))
} else {
err = fmt.Errorf("GetFunction %s got an error: %#v.", name, err)
}
return
}
function, _ = raw.(*fc.GetFunctionOutput)
if function == nil || *function.FunctionName == "" {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Function", name))
}
return
}
func (s *FcService) DescribeFcTrigger(service, function, name string) (trigger *fc.GetTriggerOutput, err error) {
raw, err := s.client.WithFcClient(func(fcClient *fc.Client) (interface{}, error) {
return fcClient.GetTrigger(fc.NewGetTriggerInput(service, function, name))
})
if err != nil {
if IsExceptedErrors(err, []string{ServiceNotFound, FunctionNotFound, TriggerNotFound}) {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Trigger", name))
} else {
err = fmt.Errorf("GetTrigger %s got an error: %#v.", name, err)
}
return
}
trigger, _ = raw.(*fc.GetTriggerOutput)
if trigger == nil || *trigger.TriggerName == "" {
err = GetNotFoundErrorFromString(GetNotFoundMessage("FC Trigger", name))
}
return
}
func removeSpaceAndEnter(s string) string {
if Trim(s) == "" {
return Trim(s)
}
return strings.Replace(strings.Replace(strings.Replace(s, " ", "", -1), "\n", "", -1), "\t", "", -1)
}