@@ -79,12 +79,26 @@ def __init__(self):
7979
8080
8181class AbstractTPPConnection (CommonConnection ):
82+ def __init__ (self ):
83+ CommonConnection .__init__ (self )
84+
85+ ARG_URL = 'url'
86+ ARG_PARAMS = 'params'
87+ ARG_CHECK_TOKEN = 'check_token' # nosec
88+ ARG_INCLUDE_TOKEN_HEADER = 'include_token_header' # nosec
89+ ARG_DATA = 'data'
90+
91+ def auth (self ):
92+ raise NotImplementedError
8293
8394 def request_cert (self , request , zone ):
84- request_data = {'PolicyDN' : self ._normalize_zone (zone ),
85- 'ObjectName' : request .friendly_name ,
86- 'DisableAutomaticRenewal' : "true"
87- }
95+ request_data = {
96+ 'PolicyDN' : self ._normalize_zone (zone ),
97+ 'ObjectName' : request .friendly_name ,
98+ 'DisableAutomaticRenewal' : "true"
99+ }
100+ zone_config = self .read_zone_conf (zone )
101+ request .update_from_zone_config (zone_config )
88102
89103 if request .csr_origin == CSR_ORIGIN_LOCAL :
90104 request .build_csr ()
@@ -143,8 +157,11 @@ def request_cert(self, request, zone):
143157 else :
144158 request_data ['CustomFields' ] = [custom_field_json ]
145159
146-
147- status , data = self ._post (URLS .CERTIFICATE_REQUESTS , data = request_data )
160+ args = {
161+ self .ARG_URL : URLS .CERTIFICATE_REQUESTS ,
162+ self .ARG_DATA : request_data
163+ }
164+ status , data = self .post (args )
148165 if status == HTTPStatus .OK :
149166 request .id = data ['CertificateDN' ]
150167 request .cert_guid = data ['Guid' ]
@@ -321,6 +338,18 @@ def revoke_cert(self, request):
321338 def import_cert (self , request ):
322339 raise NotImplementedError
323340
341+ def read_zone_conf (self , tag ):
342+ args = {
343+ self .ARG_URL : URLS .ZONE_CONFIG ,
344+ self .ARG_DATA : {
345+ 'PolicyDN' : self ._normalize_zone (tag )
346+ }
347+ }
348+ status , data = self .post (args = args )
349+ if status != HTTPStatus .OK :
350+ raise ServerUnexptedBehavior ("Server returns %d status on reading zone configuration." % status )
351+ return self ._parse_zone_data_to_object (data )
352+
324353 def get_policy (self , zone ):
325354 # get policy spec from name
326355 policy_name = self ._normalize_zone (zone )
@@ -630,12 +659,6 @@ def retrieve_ssh_config(self, ca_request):
630659 raise ServerUnexptedBehavior ("Server returns %d status on requesting SSH CA Public Key Data for %s = %s."
631660 % (status , key , value ))
632661
633- ARG_URL = 'url'
634- ARG_PARAMS = 'params'
635- ARG_CHECK_TOKEN = 'check_token' # nosec
636- ARG_INCLUDE_TOKEN_HEADER = 'include_token_header' # nosec
637- ARG_DATA = 'data'
638-
639662 def get (self , args ):
640663 """
641664
@@ -725,22 +748,13 @@ def _reset_policy_attr(self, zone, attr_name):
725748 return status , response
726749
727750 def _reset_policy (self , zone ):
728- self ._reset_policy_attr (zone , SPA .TPP_DOMAIN_SUFFIX_WHITELIST )
729- self ._reset_policy_attr (zone , SPA .TPP_PROHIBIT_WILDCARD )
730- self ._reset_policy_attr (zone , SPA .TPP_CERT_AUTHORITY )
731- self ._reset_policy_attr (zone , SPA .TPP_ORGANIZATION )
732- self ._reset_policy_attr (zone , SPA .TPP_ORG_UNIT )
733- self ._reset_policy_attr (zone , SPA .TPP_CITY )
734- self ._reset_policy_attr (zone , SPA .TPP_STATE )
735- self ._reset_policy_attr (zone , SPA .TPP_COUNTRY )
736- self ._reset_policy_attr (zone , SPA .TPP_KEY_ALGORITHM )
737- self ._reset_policy_attr (zone , SPA .TPP_KEY_BIT_STR )
738- self ._reset_policy_attr (zone , SPA .TPP_ELLIPTIC_CURVE )
739- self ._reset_policy_attr (zone , SPA .TPP_MANUAL_CSR )
740- self ._reset_policy_attr (zone , SPA .TPP_PROHIBITED_SAN_TYPES )
741- self ._reset_policy_attr (zone , SPA .TPP_ALLOWED_PRIVATE_KEY_REUSE )
742- self ._reset_policy_attr (zone , SPA .TPP_WANT_RENEWAL )
743- self ._reset_policy_attr (zone , SPA .TPP_MANAGEMENT_TYPE )
751+ atrr_list = [SPA .TPP_DOMAIN_SUFFIX_WHITELIST , SPA .TPP_PROHIBIT_WILDCARD , SPA .TPP_CERT_AUTHORITY ,
752+ SPA .TPP_ORGANIZATION , SPA .TPP_ORG_UNIT , SPA .TPP_CITY , SPA .TPP_STATE , SPA .TPP_COUNTRY ,
753+ SPA .TPP_KEY_ALGORITHM , SPA .TPP_KEY_BIT_STR , SPA .TPP_ELLIPTIC_CURVE , SPA .TPP_MANUAL_CSR ,
754+ SPA .TPP_PROHIBITED_SAN_TYPES , SPA .TPP_ALLOWED_PRIVATE_KEY_REUSE , SPA .TPP_WANT_RENEWAL ,
755+ SPA .TPP_MANAGEMENT_TYPE ]
756+ for attr in atrr_list :
757+ self ._reset_policy_attr (zone , attr )
744758
745759 @staticmethod
746760 def _parse_attr_response (response ):
@@ -873,6 +887,7 @@ def _parse_zone_data_to_object(data):
873887 key_type = KeyType (KeyType .ECDSA , data ['Policy' ]['KeyPair' ]['EllipticCurve' ]['Value' ])
874888 else :
875889 key_type = None
890+
876891 z = ZoneConfig (
877892 organization = CertField (s ['Organization' ]['Value' ], locked = s ['Organization' ]['Locked' ]),
878893 organizational_unit = CertField (ou , locked = s ['OrganizationalUnit' ]['Locked' ]),
@@ -884,12 +899,6 @@ def _parse_zone_data_to_object(data):
884899 )
885900 return z
886901
887- def read_zone_conf (self , tag ):
888- status , data = self ._post (URLS .ZONE_CONFIG , {'PolicyDN' : self ._normalize_zone (tag )})
889- if status != HTTPStatus .OK :
890- raise ServerUnexptedBehavior ("Server returns %d status on reading zone configuration." % status )
891- return self ._parse_zone_data_to_object (data )
892-
893902 def _get_certificate_details (self , cert_guid ):
894903 status , data = self ._get (URLS .CERTIFICATE_SEARCH + cert_guid )
895904 if status != HTTPStatus .OK :
0 commit comments