genericparser seed code
[modeling/etsicatalog.git] / genericparser / packages / serializers / subscription_auth_data.py
1 # Copyright (C) 2019 Verizon. All Rights Reserved
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 from rest_framework import serializers
16
17 from genericparser.packages import const
18
19
20 class OAuthCredentialsSerializer(serializers.Serializer):
21     clientId = serializers.CharField(
22         help_text="Client identifier to be used in the access token "
23         "request of the OAuth 2.0 client credentials grant type.",
24         required=False,
25         max_length=255,
26         allow_null=False
27     )
28     clientPassword = serializers.CharField(
29         help_text="Client password to be used in the access token "
30         "request of the OAuth 2.0 client credentials grant type.",
31         required=False,
32         max_length=255,
33         allow_null=False
34     )
35     tokenEndpoint = serializers.CharField(
36         help_text="The token endpoint from which the access token can "
37         "be obtained.",
38         required=False,
39         max_length=255,
40         allow_null=False
41     )
42
43
44 class BasicAuthSerializer(serializers.Serializer):
45     userName = serializers.CharField(
46         help_text="Username to be used in HTTP Basic authentication.",
47         max_length=255,
48         required=False,
49         allow_null=False
50     )
51     password = serializers.CharField(
52         help_text="Password to be used in HTTP Basic authentication.",
53         max_length=255,
54         required=False,
55         allow_null=False
56     )
57
58
59 class SubscriptionAuthenticationSerializer(serializers.Serializer):
60     authType = serializers.ListField(
61         child=serializers.ChoiceField(required=True, choices=const.AUTH_TYPES),
62         help_text="Defines the types of Authentication / Authorization "
63         "which the API consumer is willing to accept when "
64         "receiving a notification.",
65         required=True
66     )
67     paramsBasic = BasicAuthSerializer(
68         help_text="Parameters for authentication/authorization using BASIC.",
69         required=False,
70         allow_null=False
71     )
72     paramsOauth2ClientCredentials = OAuthCredentialsSerializer(
73         help_text="Parameters for authentication/authorization using "
74         "OAUTH2_CLIENT_CREDENTIALS.",
75         required=False,
76         allow_null=False
77     )