42
42
43
43
WIDGET_TYPES = ['help' ]
44
44
45
+ _OAUTH_SCOPE_PREFIX = 'https://www.googleapis.com/auth/'
46
+
45
47
46
48
class InvalidName (Exception ):
47
49
pass
@@ -283,15 +285,17 @@ def __init__(self, dictionary):
283
285
self ._k8s_version = dictionary .get ('k8sVersion' , None )
284
286
self ._resources = None
285
287
self ._istio = None
288
+ self ._gcp = None
286
289
287
290
if 'resources' in dictionary :
288
291
resources = dictionary ['resources' ]
289
292
if not isinstance (resources , list ):
290
293
raise InvalidSchema ('clusterConstraints.resources must be a list' )
291
294
self ._resources = [SchemaResourceConstraints (r ) for r in resources ]
292
295
293
- if 'istio' in dictionary :
294
- self ._istio = SchemaIstio (dictionary ['istio' ])
296
+ self ._istio = _maybe_get_and_apply (dictionary , 'istio' ,
297
+ lambda v : SchemaIstio (v ))
298
+ self ._gcp = _maybe_get_and_apply (dictionary , 'gcp' , lambda v : SchemaGcp (v ))
295
299
296
300
@property
297
301
def k8s_version (self ):
@@ -305,6 +309,10 @@ def resources(self):
305
309
def istio (self ):
306
310
return self ._istio
307
311
312
+ @property
313
+ def gcp (self ):
314
+ return self ._gcp
315
+
308
316
309
317
class SchemaResourceConstraints :
310
318
"""Accesses a single resource's constraints."""
@@ -400,6 +408,36 @@ def type(self):
400
408
return self ._type
401
409
402
410
411
+ class SchemaGcp :
412
+ """Accesses top level GCP constraints."""
413
+
414
+ def __init__ (self , dictionary ):
415
+ self ._nodes = _maybe_get_and_apply (dictionary , 'nodes' ,
416
+ lambda v : SchemaNodes (v ))
417
+
418
+ @property
419
+ def nodes (self ):
420
+ return self ._nodes
421
+
422
+
423
+ class SchemaNodes :
424
+ """Accesses GKE cluster node constraints."""
425
+
426
+ def __init__ (self , dictionary ):
427
+ self ._required_oauth_scopes = dictionary .get ('requiredOauthScopes' , [])
428
+ if not isinstance (self ._required_oauth_scopes , list ):
429
+ raise InvalidSchema ('nodes.requiredOauthScopes must be a list' )
430
+ for scope in self ._required_oauth_scopes :
431
+ if not scope .startswith (_OAUTH_SCOPE_PREFIX ):
432
+ raise InvalidSchema (
433
+ 'OAuth scope references must be fully-qualified (start with {})'
434
+ .format (_OAUTH_SCOPE_PREFIX ))
435
+
436
+ @property
437
+ def required_oauth_scopes (self ):
438
+ return self ._required_oauth_scopes
439
+
440
+
403
441
class SchemaImage :
404
442
"""Accesses an image definition."""
405
443
@@ -840,7 +878,7 @@ def _must_contain(value, valid_list, error_msg):
840
878
"""Validates that value in valid_list, or raises InvalidSchema."""
841
879
if value not in valid_list :
842
880
raise InvalidSchema ("{}. Must be one of {}" .format (error_msg ,
843
- ', ' .join (_ISTIO_TYPES )))
881
+ ', ' .join (valid_list )))
844
882
845
883
846
884
def _property_must_have_type (prop , expected_type ):
0 commit comments