Skip to content
Snippets Groups Projects
Commit 5f86eac1 authored by Edward Hicks's avatar Edward Hicks :8ball:
Browse files

fix operation check

parent e8e56823
No related branches found
No related tags found
No related merge requests found
Pipeline #91827 passed
......@@ -9,6 +9,7 @@ import numbers
import json
import boto3
from botocore.exceptions import ProfileNotFound, NoCredentialsError
from botocore.config import Config
class bcolors:
HEADER = '\033[95m'
......@@ -107,6 +108,9 @@ def extractSettings(settingsFile):
return out
def sanityCheckMessage(body, payload):
global Config
global Session
# Make sure message came from the right SNS channel
if body['TopicArn'] != Session['topicArn']:
printLog("Message came from an invalid SNS topic")
......@@ -123,7 +127,7 @@ def sanityCheckMessage(body, payload):
# Verify that the payload includes a valid operation to perform
try:
if not hasattr(payload, 'operation') or not hasattr(Config['events'], payload['operation']):
if payload['operation'] not in Config['events']:
printLog("Message has invalid operation '"+str(payload['operation'])+"'")
return false
except KeyError:
......@@ -132,7 +136,7 @@ def sanityCheckMessage(body, payload):
# Verify that the payload includes a timestamp
try:
if not hasattr(payload, 'timestamp') or not isinstance(payload['timestamp'], numbers.Number) or payload['timestamp'] < 0:
if not isinstance(payload['timestamp'], numbers.Number) or payload['timestamp'] < 0:
printLog("Message has invalid timestamp '"+str(payload['timestamp'])+"'")
return false
except KeyError:
......@@ -174,6 +178,7 @@ args = parser.parse_args()
ret = 1 # init as a failure code
logFile = False
Session = {}
Session['nodename'] = str(os.uname().nodename.split('.')[0])
Config = {}
Config['events'] = {}
......@@ -323,7 +328,7 @@ except Exception as e:
# Create an SQS queue to subscribe to the SNS topic
Session['queue'] = Config['sqsQueuePrefix']+str(os.uname().nodename.split('.')[0])
Session['queue'] = Config['sqsQueuePrefix']+Session['nodename']
printLog("Creating SQS queue "+Session['queue'], loglevels.INFO)
try:
Session['sqs'] = Session['boto3'].client('sqs')
......@@ -439,7 +444,7 @@ while True:
# If the SQS message is ok then make sure it's meant for us
# check nodes for Session['nodename']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment