make sshkeys readonly; use instance_id instead of instance_name
diff --git a/xos/api/utility/sshkeys.py b/xos/api/utility/sshkeys.py
index d9960b3..74d1f20 100644
--- a/xos/api/utility/sshkeys.py
+++ b/xos/api/utility/sshkeys.py
@@ -27,7 +27,7 @@
# return None
class SSHKeysSerializer(PlusModelSerializer):
- id = serializers.CharField(read_only=True, source="instance_name")
+ id = serializers.CharField(read_only=True, source="instance_id")
public_keys = serializers.ListField(read_only=True, source="get_public_keys")
node_name = serializers.CharField(read_only=True, source="node.name")
@@ -40,12 +40,13 @@
method_name = "sshkeys"
method_kind = "viewset"
serializer_class = SSHKeysSerializer
+ read_only = True
- lookup_field = "instance_name"
+ lookup_field = "instance_id"
lookup_url_kwarg = "pk"
def get_queryset(self):
- queryset = queryset=SSHKeys.objects.exclude(Q(instance_name__isnull=True) | Q(instance_name__exact=''))
+ queryset = queryset=SSHKeys.objects.exclude(Q(instance_id__isnull=True) | Q(instance_id__exact=''))
node_name = self.request.query_params.get('node_name', None)
if node_name is not None:
diff --git a/xos/api/xosapi_helpers.py b/xos/api/xosapi_helpers.py
index 23a2645..8c737cb 100644
--- a/xos/api/xosapi_helpers.py
+++ b/xos/api/xosapi_helpers.py
@@ -75,6 +75,7 @@
class XOSViewSet(viewsets.ModelViewSet):
api_path=""
+ read_only=False
@classmethod
def get_api_method_path(self):
@@ -101,8 +102,12 @@
patterns = []
- patterns.append(url(self.get_api_method_path() + '$', self.as_view({'get': 'list', 'post': 'create'}), name=self.base_name+'_list'))
- patterns.append(url(self.get_api_method_path() + '(?P<pk>[a-zA-Z0-9\-_]+)/$', self.as_view({'get': 'retrieve', 'put': 'update', 'post': 'update', 'delete': 'destroy', 'patch': 'partial_update'}), name=self.base_name+'_detail'))
+ if self.read_only:
+ patterns.append(url(self.get_api_method_path() + '$', self.as_view({'get': 'list'}), name=self.base_name+'_list'))
+ patterns.append(url(self.get_api_method_path() + '(?P<pk>[a-zA-Z0-9\-_]+)/$', self.as_view({'get': 'retrieve'}), name=self.base_name+'_detail'))
+ else:
+ patterns.append(url(self.get_api_method_path() + '$', self.as_view({'get': 'list', 'post': 'create'}), name=self.base_name+'_list'))
+ patterns.append(url(self.get_api_method_path() + '(?P<pk>[a-zA-Z0-9\-_]+)/$', self.as_view({'get': 'retrieve', 'put': 'update', 'post': 'update', 'delete': 'destroy', 'patch': 'partial_update'}), name=self.base_name+'_detail'))
return patterns