Skip to content

Commit

Permalink
Merge pull request #128 from p4tin/Issues_64_127
Browse files Browse the repository at this point in the history
fixes to correct queueUrl and queueArn
  • Loading branch information
p4tin authored Jan 20, 2018
2 parents 0f96ff5 + 181002b commit a5b8f61
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 461 deletions.
29 changes: 29 additions & 0 deletions app/common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
package app

/*** config ***/
type EnvSubsciption struct {
QueueName string
Raw bool
}

type EnvTopic struct {
Name string
Subscriptions []EnvSubsciption
}

type EnvQueue struct {
Name string
}

type Environment struct {
Host string
Port string
SqsPort string
SnsPort string
Region string
LogMessages bool
LogFile string
Topics []EnvTopic
Queues []EnvQueue
}

var CurrentEnvironment Environment

/*** Common ***/
type ResponseMetadata struct {
RequestId string `xml:"RequestId"`
Expand Down
70 changes: 22 additions & 48 deletions app/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,17 @@ import (
log "github.com/sirupsen/logrus"

"github.com/ghodss/yaml"
"github.com/p4tin/goaws/app"
"github.com/p4tin/goaws/app/common"
sns "github.com/p4tin/goaws/app/gosns"
sqs "github.com/p4tin/goaws/app/gosqs"
)

type EnvSubsciption struct {
QueueName string
Raw bool
}

type EnvTopic struct {
Name string
Subscriptions []EnvSubsciption
}

type EnvQueue struct {
Name string
}

type Environment struct {
Host string
Port string
SqsPort string
SnsPort string
Region string
LogMessages bool
LogFile string
Topics []EnvTopic
Queues []EnvQueue
}

var envs map[string]Environment
var envs map[string]app.Environment

func LoadYamlConfig(filename string, env string) []string {
ports := []string{"4100"}

if filename == "" {
filename, _ = filepath.Abs("./conf/goaws.yaml")
filename, _ = filepath.Abs("./app/conf/goaws.yaml")
}
log.Warnf("Loading config file: %s", filename)
yamlFile, err := ioutil.ReadFile(filename)
Expand All @@ -70,8 +43,11 @@ func LoadYamlConfig(filename string, env string) []string {
ports = []string{envs[env].Port}
} else if envs[env].SqsPort != "" && envs[env].SnsPort != "" {
ports = []string{envs[env].SqsPort, envs[env].SnsPort}
app.CurrentEnvironment.Port = envs[env].SqsPort
}

app.CurrentEnvironment = envs[env]

common.LogMessages = false
common.LogFile = "./goaws_messages.log"

Expand All @@ -82,41 +58,39 @@ func LoadYamlConfig(filename string, env string) []string {
}
}

sqs.SyncQueues.Lock()
sns.SyncTopics.Lock()
app.SyncQueues.Lock()
app.SyncTopics.Lock()
for _, queue := range envs[env].Queues {
queueUrl := "http://" + envs[env].Host + ":" + ports[0] + "/queue/" + queue.Name
sqs.SyncQueues.Queues[queue.Name] = &sqs.Queue{Name: queue.Name, TimeoutSecs: 30, Arn: queueUrl, URL: queueUrl}
queueUrl := "http://" + app.CurrentEnvironment.Host + ":" + app.CurrentEnvironment.Port + "/queue/" + queue.Name
queueArn := "arn:aws:sqs:" + app.CurrentEnvironment.Host + ":000000000000:" + queue.Name
app.SyncQueues.Queues[queue.Name] = &app.Queue{Name: queue.Name, TimeoutSecs: 30, Arn: queueArn, URL: queueUrl}
}

for _, topic := range envs[env].Topics {
topicArn := "arn:aws:sns:" + region + ":000000000000:" + topic.Name

newTopic := &sns.Topic{Name: topic.Name, Arn: topicArn}
newTopic.Subscriptions = make([]*sns.Subscription, 0, 0)
newTopic := &app.Topic{Name: topic.Name, Arn: topicArn}
newTopic.Subscriptions = make([]*app.Subscription, 0, 0)

for _, subs := range topic.Subscriptions {
if _, ok := sqs.SyncQueues.Queues[subs.QueueName]; !ok {
if _, ok := app.SyncQueues.Queues[subs.QueueName]; !ok {
//Queue does not exist yet, create it.
queueUrl := "http://" + envs[env].Host + ":" + ports[0] + "/queue/" + subs.QueueName
sqs.SyncQueues.Queues[subs.QueueName] = &sqs.Queue{Name: subs.QueueName, TimeoutSecs: 30, Arn: queueUrl, URL: queueUrl}
queueUrl := "http://" + app.CurrentEnvironment.Host + ":" + app.CurrentEnvironment.Port + "/queue/" + subs.QueueName
queueArn := "arn:aws:sqs:" + app.CurrentEnvironment.Host + ":000000000000:" + subs.QueueName
app.SyncQueues.Queues[subs.QueueName] = &app.Queue{Name: subs.QueueName, TimeoutSecs: 30, Arn: queueArn, URL: queueUrl}
}
qUrl := sqs.SyncQueues.Queues[subs.QueueName].URL
newSub := &sns.Subscription{EndPoint: qUrl, Protocol: "sqs", TopicArn: topicArn, Raw: subs.Raw}
qUrl := app.SyncQueues.Queues[subs.QueueName].URL
newSub := &app.Subscription{EndPoint: qUrl, Protocol: "sqs", TopicArn: topicArn, Raw: subs.Raw}
subArn, _ := common.NewUUID()
subArn = topicArn + ":" + subArn
newSub.SubscriptionArn = subArn
newTopic.Subscriptions = append(newTopic.Subscriptions, newSub)
}
sns.SyncTopics.Topics[topic.Name] = newTopic
app.SyncTopics.Topics[topic.Name] = newTopic
}

sqs.SyncQueues.Unlock()
sns.SyncTopics.Unlock()
app.SyncQueues.Unlock()
app.SyncTopics.Unlock()

return ports
}

func GetLogFileName(env string) (string, bool) {
return envs[env].LogFile, envs[env].LogMessages
}
12 changes: 6 additions & 6 deletions app/conf/config_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package conf

import (
"github.com/p4tin/goaws/app/gosns"
"github.com/p4tin/goaws/app/gosqs"
"testing"

"github.com/p4tin/goaws/app"
)

func TestConfig_NoQueuesOrTopics(t *testing.T) {
Expand All @@ -17,7 +17,7 @@ func TestConfig_NoQueuesOrTopics(t *testing.T) {
if numQueues != 0 {
t.Errorf("Expected zero queues to be in the environment but got %s\n", numQueues)
}
numQueues = len(gosqs.SyncQueues.Queues)
numQueues = len(app.SyncQueues.Queues)
if numQueues != 0 {
t.Errorf("Expected zero queues to be in the sqs topics but got %s\n", numQueues)
}
Expand All @@ -26,7 +26,7 @@ func TestConfig_NoQueuesOrTopics(t *testing.T) {
if numTopics != 0 {
t.Errorf("Expected zero topics to be in the environment but got %s\n", numTopics)
}
numTopics = len(gosns.SyncTopics.Topics)
numTopics = len(app.SyncTopics.Topics)
if numTopics != 0 {
t.Errorf("Expected zero topics to be in the sns topics but got %s\n", numTopics)
}
Expand All @@ -43,7 +43,7 @@ func TestConfig_CreateQueuesTopicsAndSubscriptions(t *testing.T) {
if numQueues != 3 {
t.Errorf("Expected three queues to be in the environment but got %s\n", numQueues)
}
numQueues = len(gosqs.SyncQueues.Queues)
numQueues = len(app.SyncQueues.Queues)
if numQueues != 5 {
t.Errorf("Expected five queues to be in the sqs topics but got %s\n", numQueues)
}
Expand All @@ -52,7 +52,7 @@ func TestConfig_CreateQueuesTopicsAndSubscriptions(t *testing.T) {
if numTopics != 2 {
t.Errorf("Expected two topics to be in the environment but got %s\n", numTopics)
}
numTopics = len(gosns.SyncTopics.Topics)
numTopics = len(app.SyncTopics.Topics)
if numTopics != 2 {
t.Errorf("Expected two topics to be in the sns topics but got %s\n", numTopics)
}
Expand Down
2 changes: 1 addition & 1 deletion app/conf/goaws.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Local: # Environment name that can be passed on the command line
# (i.e.: ./goaws [Local | Dev] -- defaults to 'Local')
Host: localhost # hostname of the goaws system (for docker-compose this is the tag name of the container)
Host: goaws # hostname of the goaws system (for docker-compose this is the tag name of the container)
# you can now use either 1 port for both sns and sqs or alternatively you can comment out Port and use SqsPort + SnsPort for compatibilyt with
# yopa and (fage-sns + face-sqs). If both ways are in the config file on the one "Port" will be used by GoAws
Port: 4100 # port to listen on.
Expand Down
Loading

0 comments on commit a5b8f61

Please sign in to comment.