-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from stelligent/develop
v1.4.1
- Loading branch information
Showing
21 changed files
with
493 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.3.2 | ||
1.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package common | ||
|
||
// SubscriptionCreator for creating subscriptions | ||
type SubscriptionCreator interface { | ||
CreateSubscription(topic string, protocol string, endpoint string) error | ||
} | ||
|
||
// SubscriptionGetter for creating subscriptions | ||
type SubscriptionGetter interface { | ||
GetSubscription(topic string, protocol string, endpoint string) (interface{}, error) | ||
} | ||
|
||
// SubscriptionManager composite of all subscription capabilities | ||
type SubscriptionManager interface { | ||
SubscriptionCreator | ||
SubscriptionGetter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sns" | ||
"github.com/aws/aws-sdk-go/service/sns/snsiface" | ||
"github.com/stelligent/mu/common" | ||
) | ||
|
||
type snsManager struct { | ||
snsAPI snsiface.SNSAPI | ||
} | ||
|
||
func newSnsManager(sess *session.Session) (common.SubscriptionManager, error) { | ||
log.Debug("Connecting to SNS service") | ||
snsAPI := sns.New(sess) | ||
|
||
return &snsManager{ | ||
snsAPI: snsAPI, | ||
}, nil | ||
} | ||
|
||
// CreateSubscription | ||
func (snsMgr *snsManager) CreateSubscription(topic string, protocol string, endpoint string) error { | ||
snsAPI := snsMgr.snsAPI | ||
|
||
_, err := snsAPI.Subscribe(&sns.SubscribeInput{ | ||
TopicArn: aws.String(topic), | ||
Endpoint: aws.String(endpoint), | ||
Protocol: aws.String(protocol), | ||
}) | ||
return err | ||
} | ||
|
||
// GetSubscription | ||
func (snsMgr *snsManager) GetSubscription(topic string, protocol string, endpoint string) (interface{}, error) { | ||
snsAPI := snsMgr.snsAPI | ||
|
||
out, err := snsAPI.ListSubscriptionsByTopic(&sns.ListSubscriptionsByTopicInput{ | ||
TopicArn: aws.String(topic), | ||
}) | ||
|
||
for _, sub := range out.Subscriptions { | ||
if aws.StringValue(sub.Protocol) == protocol && aws.StringValue(sub.Endpoint) == endpoint { | ||
return sub, nil | ||
} | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, fmt.Errorf("unable to find subscription") | ||
} |
Oops, something went wrong.