Skip to content

Commit

Permalink
Prevent altering certain fields on Instance
Browse files Browse the repository at this point in the history
- Prevents changing hostname, listener_port, or node_type for instances
that already exist
- API default node_type is execution
- API default node_state is installed
  • Loading branch information
fosterseth authored and jbradberry committed Sep 23, 2022
1 parent 9c6aa93 commit e0c9013
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4884,12 +4884,12 @@ class Meta:
read_only_fields = ('ip_address', 'uuid', 'version')
fields = (
'id',
'hostname',
'type',
'url',
'related',
'summary_fields',
'uuid',
'hostname',
'created',
'modified',
'last_seen',
Expand All @@ -4913,6 +4913,7 @@ class Meta:
'ip_address',
'listener_port',
)
extra_kwargs = {'node_type': {'default': 'execution'}, 'node_state': {'default': 'installed'}}

def get_related(self, obj):
res = super(InstanceSerializer, self).get_related(obj)
Expand Down Expand Up @@ -4974,6 +4975,18 @@ def validate_node_state(self, value):

return value

def validate_hostname(self, value):
if self.instance and self.instance.hostname != value:
raise serializers.ValidationError("Cannot change hostname.")

return value

def validate_listener_port(self, value):
if self.instance and self.instance.listener_port != value:
raise serializers.ValidationError("Cannot change listener port.")

return value


class InstanceHealthCheckSerializer(BaseSerializer):
class Meta:
Expand Down

0 comments on commit e0c9013

Please sign in to comment.