Fix NS update serializers error
[vfc/nfvo/lcm.git] / lcm / ns / serializers / sol / subscription_auth_data.py
1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6
7 # http://www.apache.org/licenses/LICENSE-2.0
8
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 from rest_framework import serializers
17
18 from lcm.ns import const
19
20
21 class OAuthCredentialsSerializer(serializers.Serializer):
22     clientId = serializers.CharField(
23         help_text="Client identifier to be used in the access token request of the OAuth 2.0 client credentials grant type.",
24         required=False,
25         max_length=255,
26         allow_null=False)
27     clientPassword = serializers.CharField(
28         help_text="Client password to be used in the access token request of the OAuth 2.0 client credentials grant type.",
29         required=False,
30         max_length=255,
31         allow_null=False)
32     tokenEndpoint = serializers.CharField(
33         help_text="The token endpoint from which the access token can be obtained.",
34         required=False,
35         max_length=255,
36         allow_null=False)
37
38
39 class BasicAuthSerializer(serializers.Serializer):
40     userName = serializers.CharField(
41         help_text="Username to be used in HTTP Basic authentication.",
42         max_length=255,
43         required=False,
44         allow_null=False)
45     password = serializers.CharField(
46         help_text="Password to be used in HTTP Basic authentication.",
47         max_length=255,
48         required=False,
49         allow_null=False)
50
51
52 class SubscriptionAuthenticationSerializer(serializers.Serializer):
53     authType = serializers.ListField(
54         help_text="Defines the types of Authentication / Authorization which the API consumer is"
55                   " willing to accept when receiving a notification.",
56         child=serializers.ChoiceField(
57             required=True,
58             choices=const.AUTH_TYPES),
59         required=True)
60     paramsBasic = BasicAuthSerializer(
61         help_text="Parameters for authentication/authorization using BASIC.",
62         required=False,
63         allow_null=False)
64     paramsOauth2ClientCredentials = OAuthCredentialsSerializer(
65         help_text="Parameters for authentication/authorization using OAUTH2_CLIENT_CREDENTIALS.",
66         required=False,
67         allow_null=False)