mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-07-02 07:01:30 +00:00
feat: integration-app add refresh-secret api, and modify app secret logic
This commit is contained in:
@@ -26,7 +26,8 @@ class IntegrationApplicationViewSet(OrgBulkModelViewSet):
|
||||
rbac_perms = {
|
||||
'get_once_secret': 'accounts.change_integrationapplication',
|
||||
'get_account_secret': 'accounts.view_integrationapplication',
|
||||
'get_sdks_info': 'accounts.view_integrationapplication'
|
||||
'get_sdks_info': 'accounts.view_integrationapplication',
|
||||
'refresh_secret': 'accounts.change_integrationapplication',
|
||||
}
|
||||
|
||||
def read_file(self, path):
|
||||
@@ -63,6 +64,15 @@ class IntegrationApplicationViewSet(OrgBulkModelViewSet):
|
||||
def get_once_secret(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
return Response(data={'id': instance.id, 'secret': instance.secret})
|
||||
|
||||
@action(
|
||||
['GET'], detail=True, url_path='refresh-secret',
|
||||
permission_classes=[RBACPermission]
|
||||
)
|
||||
def refresh_secret(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
instance.refresh_secret()
|
||||
return Response(data={'id': instance.id, 'msg': 'Successfully refreshed secret'})
|
||||
|
||||
@action(['GET'], detail=False, url_path='account-secret',
|
||||
permission_classes=[RBACPermission])
|
||||
|
||||
@@ -49,7 +49,7 @@ class IntegrationApplication(JMSOrgBaseModel):
|
||||
support_perms = ['accounts.view_integrationapplication']
|
||||
return all([perm in support_perms for perm in perms])
|
||||
|
||||
def get_secret(self):
|
||||
def refresh_secret(self):
|
||||
self.secret = random_string(36)
|
||||
self.save(update_fields=['secret'])
|
||||
return self.secret
|
||||
|
||||
@@ -38,9 +38,10 @@ class IntegrationApplicationSerializer(BulkOrgResourceModelSerializer):
|
||||
data['logo'] = static('img/logo.png')
|
||||
return data
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs['secret'] = random_string(36)
|
||||
return attrs
|
||||
def create(self, validated_data):
|
||||
instance = super().create(validated_data)
|
||||
instance.refresh_secret()
|
||||
return instance
|
||||
|
||||
|
||||
class IntegrationAccountSecretSerializer(serializers.Serializer):
|
||||
|
||||
Reference in New Issue
Block a user