| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package pinpoint |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | |||
| 6 | "github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
||
| 7 | ) |
||
| 8 | |||
| 9 | // XExistsApp checks if the application already exists or not. |
||
| 10 | func (svc *Pinpoint) XExistsApp(ctx context.Context, appID string) (bool, error) { |
||
| 11 | _, err := svc.GetApp(ctx, GetAppRequest{ |
||
| 12 | ApplicationID: appID, |
||
| 13 | }) |
||
| 14 | if err == nil { |
||
| 15 | return true, nil |
||
| 16 | } |
||
| 17 | |||
| 18 | if e, ok := err.(errors.ErrorData); ok { |
||
| 19 | if e.GetAWSErrCode() == "NotFoundException" { |
||
| 20 | return false, nil |
||
| 21 | } |
||
| 22 | } |
||
| 23 | return false, err |
||
| 24 | } |
||
| 25 | |||
| 26 | // XGetAppIDByName searches app by name and returns its ID. |
||
| 27 | func (svc *Pinpoint) XGetAppIDByName(ctx context.Context, appName string) (appID string, err error) { |
||
| 28 | nextToken := "" |
||
| 29 | for { |
||
| 30 | resp, err := svc.GetApps(ctx, GetAppsRequest{ |
||
| 31 | PageSize: "1000", |
||
| 32 | Token: nextToken, |
||
| 33 | }) |
||
| 34 | if err != nil { |
||
| 35 | return "", err |
||
| 36 | } |
||
| 37 | for _, v := range resp.Item { |
||
| 38 | if v.Name == appName { |
||
| 39 | return v.ID, nil |
||
| 40 | } |
||
| 41 | } |
||
| 42 | if resp.NextToken == "" { |
||
| 43 | return "", nil |
||
| 44 | } |
||
| 45 | nextToken = resp.NextToken |
||
| 46 | } |
||
| 48 |