Skip to content

Commit b726853

Browse files
committed
fix(s3): ensure sqs queue names are valid
1 parent f5f6178 commit b726853

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

front50-s3/src/main/java/com/netflix/spinnaker/front50/model/TemporarySQSQueue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public TemporarySQSQueue(AmazonSQS amazonSQS, AmazonSNS amazonSNS, String snsTop
5959
this.amazonSQS = amazonSQS;
6060
this.amazonSNS = amazonSNS;
6161

62+
String sanitizedInstanceId = getSanitizedInstanceId(instanceId);
6263
String snsTopicArn = getSnsTopicArn(amazonSNS, snsTopicName);
63-
String sqsQueueName = snsTopicName + "__" + instanceId;
64+
String sqsQueueName = snsTopicName + "__" + sanitizedInstanceId;
6465
String sqsQueueArn = snsTopicArn.substring(0, snsTopicArn.lastIndexOf(":") + 1).replace("sns", "sqs") + sqsQueueName;
6566

6667
this.temporaryQueue = createQueue(snsTopicArn, sqsQueueArn, sqsQueueName);
@@ -151,6 +152,10 @@ private TemporaryQueue createQueue(String snsTopicArn, String sqsQueueArn, Strin
151152
return new TemporaryQueue(snsTopicArn, sqsQueueArn, sqsQueueUrl, snsTopicSubscriptionArn);
152153
}
153154

155+
static String getSanitizedInstanceId(String instanceId) {
156+
return instanceId.replaceAll("[^\\w\\-]", "_");
157+
}
158+
154159
protected static class TemporaryQueue {
155160
final String snsTopicArn;
156161
final String sqsQueueArn;

front50-s3/src/test/groovy/com/netflix/spinnaker/front50/model/TemporarySQSQueueSpec.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,16 @@ class TemporarySQSQueueSpec extends Specification {
6767
1 * amazonSNS.unsubscribe("arn:subscription")
6868
0 * _
6969
}
70+
71+
def "should convert instanceId into something SQS queue ARN friendly"() {
72+
expect:
73+
TemporarySQSQueue.getSanitizedInstanceId(source) == expected
74+
75+
where:
76+
source | expected
77+
'127.0.0.1' | '127_0_0_1'
78+
'my-host.local' | 'my-host_local'
79+
'localhoser' | 'localhoser'
80+
'something123-ABC.def' | 'something123-ABC_def'
81+
}
7082
}

0 commit comments

Comments
 (0)