Skip to content

Commit

Permalink
[sns] Add GetPlatformApplicationAttribtutes() (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia authored Apr 24, 2020
1 parent b64bc81 commit 3b2944d
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ At this time, it suports services below,
- CreateTopic
- DeleteTopic
- GetEndpointAttributes
- GetPlatformApplicationAttributes
- Publish
- SetEndpointAttributes
- Subscribe
Expand Down
13 changes: 13 additions & 0 deletions sns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ func (svc *SNS) GetEndpoint(arn string) (*PlatformEndpoint, error) {
return ep, err
}

// GetPlatformApplicationAttributes executes `GetPlatformApplicationAttributes`.
func (svc *SNS) GetPlatformApplicationAttributes(arn string) (PlatformAttributes, error) {
resp, err := svc.client.GetPlatformApplicationAttributes(&SDK.GetPlatformApplicationAttributesInput{
PlatformApplicationArn: pointers.String(arn),
})
if err != nil {
svc.Errorf("error on `GetPlatformApplicationAttributes` operation; arn=%s; error=%s;", arn, err.Error())
return PlatformAttributes{}, err
}

return NewPlatformAttributesFromMap(resp.Attributes), nil
}

func (svc *SNS) newApplicationEndpoint(arn string) *PlatformEndpoint {
return &PlatformEndpoint{
svc: svc,
Expand Down
19 changes: 19 additions & 0 deletions sns/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,22 @@ func TestBulkPublish(t *testing.T) {
err := svc.BulkPublish(tokens, "message")
assert.Nil(err)
}

func TestGetPlatformApplicationAttributes(t *testing.T) {
a := assert.New(t)
svc := getTestClient(t)

list := []string{
testAppleARN,
testGoogleARN,
}

t.Skip("fakesns does not implement GetPlatformApplicationAttributes() yet.")

for _, v := range list {
resp, err := svc.GetPlatformApplicationAttributes(v)
a.NoError(err, v)
a.True(resp.HasEnabled, v)
a.True(resp.Enabled, v)
}
}
120 changes: 120 additions & 0 deletions sns/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package sns

import (
"strconv"
"time"
)

// PlatformAttributes contains platform application attributes.
type PlatformAttributes struct {
HasPlatformCredential bool
PlatformCredential string

HasPlatformPrincipal bool
PlatformPrincipal string

HasEventEndpointCreated bool
EventEndpointCreated string

HasEventEndpointDeleted bool
EventEndpointDeleted string

HasEventEndpointUpdated bool
EventEndpointUpdated string

HasEventDeliveryFailure bool
EventDeliveryFailure string

HasSuccessFeedbackRoleArn bool
SuccessFeedbackRoleArn string

HasFailureFeedbackRoleArn bool
FailureFeedbackRoleArn string

HasSuccessFeedbackSampleRate bool
SuccessFeedbackSampleRate int // 0 - 100

HasEnabled bool
Enabled bool

HasAppleCertificateExpirationDate bool
AppleCertificateExpirationDate time.Time
}

func NewPlatformAttributesFromMap(attr map[string]*string) PlatformAttributes {
a := PlatformAttributes{}
if len(attr) == 0 {
return a
}

if v, ok := attr["PlatformCredential"]; ok {
a.HasPlatformCredential = true
if v != nil {
a.PlatformCredential = *v
}
}
if v, ok := attr["PlatformPrincipal"]; ok {
a.HasPlatformPrincipal = true
if v != nil {
a.PlatformPrincipal = *v
}
}
if v, ok := attr["EventEndpointCreated"]; ok {
a.HasEventEndpointCreated = true
if v != nil {
a.EventEndpointCreated = *v
}
}
if v, ok := attr["EventEndpointDeleted"]; ok {
a.HasEventEndpointDeleted = true
if v != nil {
a.EventEndpointDeleted = *v
}
}
if v, ok := attr["EventEndpointUpdated"]; ok {
a.HasEventEndpointUpdated = true
if v != nil {
a.EventEndpointUpdated = *v
}
}
if v, ok := attr["EventDeliveryFailure"]; ok {
a.HasEventDeliveryFailure = true
if v != nil {
a.EventDeliveryFailure = *v
}
}
if v, ok := attr["SuccessFeedbackRoleArn"]; ok {
a.HasSuccessFeedbackRoleArn = true
if v != nil {
a.SuccessFeedbackRoleArn = *v
}
}
if v, ok := attr["FailureFeedbackRoleArn"]; ok {
a.HasFailureFeedbackRoleArn = true
if v != nil {
a.FailureFeedbackRoleArn = *v
}
}
if v, ok := attr["SuccessFeedbackSampleRate"]; ok {
a.HasSuccessFeedbackSampleRate = true
if v != nil {
num, _ := strconv.Atoi(*v)
a.SuccessFeedbackSampleRate = num
}
}
if v, ok := attr["Enabled"]; ok {
a.HasEnabled = true
if v != nil {
ok, _ := strconv.ParseBool(*v)
a.Enabled = ok
}
}
if v, ok := attr["AppleCertificateExpirationDate"]; ok {
a.HasAppleCertificateExpirationDate = true
if v != nil {
dt, _ := time.Parse(time.RFC3339, *v)
a.AppleCertificateExpirationDate = dt
}
}
return a
}

0 comments on commit 3b2944d

Please sign in to comment.