Skip to content

Commit

Permalink
Make some methods static
Browse files Browse the repository at this point in the history
They don't need any class properties besides what's given to them, so
why not?
  • Loading branch information
zhimsel committed Nov 13, 2018
1 parent fec8744 commit c972797
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions r53_dns_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def domain_name(self):

return self._domain_name

def get_public_ip(self, max_tries):
@staticmethod
def get_public_ip(max_tries):
"""
Get the actual public IP of the internet connection we're on.
Expand Down Expand Up @@ -237,11 +238,13 @@ def get_current_record(self):
our_record_targets[0]['Value'], our_record_ttl)
return str(our_record_targets[0]['Value']), int(our_record_ttl)

def publish_to_sns(self, msg):
@staticmethod
def publish_to_sns(sns_arn, msg):
"""
Attempt to publish a message to the provided SNS topic
Args:
sns_arn (str): ARN of the SNS topic to send to
msg (str): body for the SNS message
"""
if not sns_arn:
Expand All @@ -251,11 +254,11 @@ def publish_to_sns(self, msg):

# Determine which region we need to use, because the 'default' region
# (as set by config) needs to match the region of the SNS topic
aws_region = self.sns_arn.split(':')[3]
aws_region = sns_arn.split(':')[3]
sns = boto3.client('sns', region_name=aws_region)

try:
sns.publish(TopicArn=self.sns_arn, Message=str(msg))
sns.publish(TopicArn=sns_arn, Message=str(msg))
except Exception as e:
log.error('Failed to send SNS message: %s', e)

Expand Down Expand Up @@ -315,7 +318,8 @@ def update_target_record_value(self, ttl=None):
# If requested, send an SNS message to alert that the IP changed
if self.sns_arn:
self.publish_to_sns(
'IP for DNS record {} changed to {}'.format(
sns_arn=str(self.sns_arn),
msg='IP for DNS record {} changed to {}'.format(
self.target_record, self.actual_ip))


Expand Down

0 comments on commit c972797

Please sign in to comment.