1
- from marshmallow import Schema , fields , validate , INCLUDE
1
+ from marshmallow import Schema , fields , validate , INCLUDE , validates_schema , ValidationError
2
2
3
- from api .validation .validators import comma_splittable , aws_region_validator , is_alphanumeric_with_hyphen , valid_api_log_levels_predicate
4
- from api . logging import VALID_LOG_LEVELS
3
+ from api .validation .validators import comma_splittable , aws_region_validator , is_alphanumeric_with_hyphen , \
4
+ valid_api_log_levels_predicate , size_not_exceeding
5
5
6
6
7
7
class EC2ActionSchema (Schema ):
8
8
action = fields .String (required = True , validate = validate .OneOf (['stop_instances' , 'start_instances' ]))
9
- instance_ids = fields .String (required = True , validate = comma_splittable )
9
+ instance_ids = fields .String (required = True , validate = validate . And ( comma_splittable , validate . Length ( max = 2048 )) )
10
10
region = fields .String (validate = aws_region_validator )
11
11
12
12
13
13
EC2Action = EC2ActionSchema (unknown = INCLUDE )
14
14
15
15
16
16
class CreateUserSchema (Schema ):
17
- Username = fields .Email (required = True )
18
- Phonenumber = fields .String ()
17
+ Username = fields .Email (required = True , validate = validate . Length ( max = 320 )) # Email RFC allows max 320 chars
18
+ Phonenumber = fields .String (validate = validate . Length ( max = 15 )) # ITU-T E.164 allows phone numbers no more than 15 digits
19
19
20
20
21
21
CreateUser = CreateUserSchema (unknown = INCLUDE )
@@ -29,13 +29,13 @@ class DeleteUserSchema(Schema):
29
29
30
30
class GetClusterConfigSchema (Schema ):
31
31
region = fields .String (validate = aws_region_validator )
32
- cluster_name = fields .String (required = True , validate = is_alphanumeric_with_hyphen )
32
+ cluster_name = fields .String (required = True , validate = validate . And ( is_alphanumeric_with_hyphen , validate . Length ( max = 60 ))) # PC allow cluster name of max 60 chars
33
33
34
34
GetClusterConfig = GetClusterConfigSchema (unknown = INCLUDE )
35
35
36
36
37
37
class GetCustomImageConfigSchema (Schema ):
38
- image_id = fields .String (required = True , validate = is_alphanumeric_with_hyphen )
38
+ image_id = fields .String (required = True , validate = validate . And ( is_alphanumeric_with_hyphen , validate . Length ( min = 1 , max = 1024 ))) # AMI id min 1, max 1024 chars
39
39
40
40
GetCustomImageConfig = GetCustomImageConfigSchema (unknown = INCLUDE )
41
41
@@ -53,72 +53,82 @@ class GetInstanceTypesSchema(Schema):
53
53
54
54
55
55
class GetDcvSessionSchema (Schema ):
56
- user = fields .String ()
57
- instance_id = fields .String (required = True )
56
+ user = fields .String (validate = validate . Length ( max = 64 ) )
57
+ instance_id = fields .String (required = True , validate = validate . Length ( max = 60 ) )
58
58
region = fields .String (validate = aws_region_validator )
59
59
60
60
GetDcvSession = GetDcvSessionSchema (unknown = INCLUDE )
61
61
62
62
63
63
class QueueStatusSchema (Schema ):
64
- user = fields .String ()
65
- instance_id = fields .String (required = True )
64
+ user = fields .String (validate = validate . Length ( max = 64 ) )
65
+ instance_id = fields .String (required = True , validate = validate . Length ( max = 60 ) )
66
66
region = fields .String (required = True , validate = aws_region_validator )
67
67
68
68
QueueStatus = QueueStatusSchema (unknown = INCLUDE )
69
69
70
70
71
71
class ScontrolJobSchema (Schema ):
72
- user = fields .String ()
73
- instance_id = fields .String (required = True )
74
- job_id = fields .String (required = True )
72
+ user = fields .String (validate = validate . Length ( max = 64 ) )
73
+ instance_id = fields .String (required = True , validate = validate . Length ( max = 60 ) )
74
+ job_id = fields .String (required = True , validate = validate . Length ( max = 256 ) )
75
75
region = fields .String (required = True , validate = aws_region_validator )
76
76
77
77
ScontrolJob = ScontrolJobSchema (unknown = INCLUDE )
78
78
79
79
80
80
class CancelJobSchema (Schema ):
81
- user = fields .String ()
82
- instance_id = fields .String (required = True )
83
- job_id = fields .String (required = True )
81
+ user = fields .String (validate = validate . Length ( max = 64 ) )
82
+ instance_id = fields .String (required = True , validate = validate . Length ( max = 60 ) )
83
+ job_id = fields .String (required = True , validate = validate . Length ( max = 256 ) )
84
84
region = fields .String (required = True , validate = aws_region_validator )
85
85
86
86
CancelJob = CancelJobSchema (unknown = INCLUDE )
87
87
88
88
89
89
class SacctSchema (Schema ):
90
- user = fields .String ()
91
- instance_id = fields .String (required = True )
92
- cluster_name = fields .String (required = True , validate = is_alphanumeric_with_hyphen )
90
+ user = fields .String (validate = validate . Length ( max = 64 ) )
91
+ instance_id = fields .String (required = True , validate = validate . Length ( max = 60 ) )
92
+ cluster_name = fields .String (required = True , validate = validate . And ( is_alphanumeric_with_hyphen , validate . Length ( max = 60 )) )
93
93
region = fields .String (required = True , validate = aws_region_validator )
94
94
95
95
Sacct = SacctSchema (unknown = INCLUDE )
96
96
97
97
98
98
class LoginSchema (Schema ):
99
- code = fields .String (required = True )
99
+ code = fields .String (required = True , validate = validate . Length ( max = 128 ) )
100
100
101
101
Login = LoginSchema (unknown = INCLUDE )
102
102
103
103
104
104
class PushLogSchema (Schema ):
105
105
class PushLogEntrySchema (Schema ):
106
106
level = fields .String (required = True , validate = valid_api_log_levels_predicate )
107
- message = fields .String (required = True )
107
+ message = fields .String (required = True , validate = validate . Length ( max = 246000 )) # CW limit is 256k, leaving 1k to extra and level
108
108
extra = fields .Dict ()
109
109
110
110
logs = fields .List (fields .Nested (PushLogEntrySchema ), required = True )
111
111
112
112
PushLog = PushLogSchema (unknown = INCLUDE )
113
113
114
114
class PriceEstimateSchema (Schema ):
115
- cluster_name = fields .String (required = True )
116
- queue_name = fields .String (required = True )
115
+ cluster_name = fields .String (required = True , validate = validate . Length ( max = 60 ) )
116
+ queue_name = fields .String (required = True , validate = validate . Length ( max = 60 ) )
117
117
region = fields .String (validate = aws_region_validator , required = True )
118
118
119
119
PriceEstimate = PriceEstimateSchema (unknown = INCLUDE )
120
120
121
- class PCProxySchema (Schema ):
122
- path = fields .String (required = True )
121
+ class PCProxyArgsSchema (Schema ):
122
+ path = fields .String (required = True , validate = validate . Length ( max = 512 ) )
123
123
124
- PCProxy = PCProxySchema (unknown = INCLUDE )
124
+ PCProxyArgs = PCProxyArgsSchema (unknown = INCLUDE )
125
+
126
+ class PCProxyBodySchema (Schema ):
127
+ def __init__ (self , max_size , ** kwargs ):
128
+ super ().__init__ (** kwargs )
129
+ self .max_size = max_size
130
+ @validates_schema (pass_original = False )
131
+ def request_body_not_exceeding (self , data , ** kwargs ):
132
+ size_not_exceeding (data , self .max_size )
133
+
134
+ PCProxyBody = PCProxyBodySchema (max_size = 8192 ,unknown = INCLUDE )
0 commit comments