我知道如何使用命令行安装 ssl 证书。但是这次我需要一个 shell 脚本来完成这个任务。
通常在手动执行此操作时,我首先执行以下操作:-
sudo apt-get install certbot python-certbot-nginx
Run Code Online (Sandbox Code Playgroud)
通过执行上述我将被要求继续或不?[是/否]。我将输入'Y'。然后我将执行以下命令
sudo certbot --nginx
Run Code Online (Sandbox Code Playgroud)
执行上述将要求我按顺序回答以下步骤:
完成所有这些步骤后,https 将被启用。现在我需要通过 shell 文件以编程方式完成这些事情。我想使用这个来安装 certbot 和 python-certbot-nginx
sudo apt-get install certbot python-certbot-nginx -y
Run Code Online (Sandbox Code Playgroud)
但我不知道如何进一步进行,因为我从未使用过 shell 脚本
PS:我在执行 sudo certbot --nginx 并自己输入详细信息时提供示例结果。
sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mygmailid@gmail.com
- - …Run Code Online (Sandbox Code Playgroud) 我正在使用 POSTMAN 调用 Microsoft Graph API。我正在尝试订阅多个用户的状态。文档中提到,为了订阅对多个用户状态的更改,请使用以下 url:/communications/presences?$filter=id in ({id},{id}...)
请求网址
https://graph.microsoft.com/beta/subscriptions
Run Code Online (Sandbox Code Playgroud)
这是请求正文(原始)
{
"changeType": "updated",
"notificationUrl": "https://d3a8ebc3581d.ngrok.io/presence-notify/",
"resource": "/communications/presences?$filter=id in (abcd-efgh-4856-a935-c9a2f685xyz,abcd-efgh-47f8-9d79-eacb0fd6xyz)",
"expirationDateTime": "2020-09-22T07:37:13Z",
"clientState": "secretClientState"
}
Run Code Online (Sandbox Code Playgroud)
我代表用户调用此 API,即我正在使用UserAccessToken. 这是回应:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2020-09-21T16:24:50",
"request-id": "2cf476f0-2270-417f-a987-5c5bbc92a351",
"client-request-id": "2cf476f0-2270-417f-a987-5c5bbc92a351"
}
}
}
Run Code Online (Sandbox Code Playgroud)
PS:我已经更改了两个用户 ID 的前几个和最后几个字符。所以这不是问题。
场景:我有组和权限,权限与组关联,并且该组与用户关联。现在我尝试通过DjangoModelPermissions实现视图的权限
这对于实现查询集的以下代码行效果很好;
class UpdateCampaignView(generics.UpdateAPIView):
authentication_classes = [TokenAuthentication]
permission_classes = [DjangoModelPermissions]
queryset = Campaign.objects.all()
serializer_class = UpdateCampaignSerializer
def get_object(self):
campaign_id = self.request.data.get("id")
return Campaign.objects.get(id =campaign_id)
Run Code Online (Sandbox Code Playgroud)
但我想将其实现为基于类的 APIView,无需使用 queryset 关键字,如下所示:
class RetrieveCampaignView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [DjangoModelPermissions] #this is what i want to do
def get(self, request, *args, **kwargs):
try:
campaign = Campaign.objects.get(id = request.data.get("id"))
searializer = GetCampaignSerializer(campaign)
return Response({"status":True , "payload":searializer.data})
except:
return Response({"status":False}, status=status.HTTP_404_NOT_FOUND)
Run Code Online (Sandbox Code Playgroud)
但这给出了以下错误:
djangorest框架错误无法在未设置.queryset或没有.get_queryset()方法的视图上应用DjangoModelPermissions
python django django-models django-views django-rest-framework