1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515#
16-
17- from .logger import setup_logger , get_logger , get_child
1816from .common import CertificateRequest , CommonConnection , RevocationRequest , ZoneConfig , CertField , KeyType , \
1917 CustomField , Authentication , SCOPE_CM , SCOPE_PM , SCOPE_SSH , CSR_ORIGIN_LOCAL , CSR_ORIGIN_PROVIDED , \
20- CSR_ORIGIN_SERVICE , CHAIN_OPTION_FIRST , CHAIN_OPTION_IGNORE , CHAIN_OPTION_LAST
18+ CSR_ORIGIN_SERVICE , CHAIN_OPTION_FIRST , CHAIN_OPTION_IGNORE , CHAIN_OPTION_LAST , VenafiPlatform
2119from .connection_cloud import CloudConnection
2220from .connection_tpp import TPPConnection
2321from .connection_tpp_token import TPPTokenConnection
2422from .connection_fake import FakeConnection
23+ from .errors import VenafiError
24+ from .logger import setup_logger , get_logger , get_child
2525from .pem import Certificate
26- from .ssh_utils import SSHCertRequest , SSHKeyPair , write_ssh_files
26+ from .ssh_utils import SSHCertRequest , SSHKeyPair , write_ssh_files , SSHCATemplateRequest , SSHConfig
2727from .tpp_utils import IssuerHint
2828
2929setup_logger ()
@@ -54,7 +54,7 @@ def Connection(url=None, token=None, user=None, password=None, fake=False, http_
5454
5555
5656def venafi_connection (url = None , api_key = None , user = None , password = None , access_token = None , refresh_token = None ,
57- fake = False , http_request_kwargs = None ):
57+ fake = False , http_request_kwargs = None , platform = None ):
5858 """
5959 Return connection based on credentials list.
6060 Venafi Platform (TPP) requires URL and access_token (or user and password for getting a new access_token)
@@ -68,14 +68,26 @@ def venafi_connection(url=None, api_key=None, user=None, password=None, access_t
6868 :param str refresh_token: TPP refresh token (optional)
6969 :param bool fake: Use fake connection
7070 :param dict[str, Any] http_request_kwargs: Option for specifying trust bundle or to operate insecurely.
71+ :param VenafiPlatform platform: The platform to be used with the Connector
7172 :rtype CommonConnection:
7273 """
73- if fake :
74- return FakeConnection ()
75- if url and (access_token or refresh_token or (user and password )):
76- return TPPTokenConnection (url = url , user = user , password = password , access_token = access_token ,
77- refresh_token = refresh_token , http_request_kwargs = http_request_kwargs )
78- if api_key :
79- return CloudConnection (token = api_key , url = url , http_request_kwargs = http_request_kwargs )
74+ if platform :
75+ if platform == VenafiPlatform .FAKE :
76+ return FakeConnection ()
77+ elif platform == VenafiPlatform .TPP :
78+ return TPPTokenConnection (url = url , user = user , password = password , access_token = access_token ,
79+ refresh_token = refresh_token , http_request_kwargs = http_request_kwargs )
80+ elif platform == VenafiPlatform .VAAS :
81+ return CloudConnection (token = api_key , url = url , http_request_kwargs = http_request_kwargs )
82+ else :
83+ raise VenafiError ("Invalid Platform: %s. Cannot instantiate a Connector." % platform )
8084 else :
81- raise Exception ("Bad credentials list" )
85+ if fake :
86+ return FakeConnection ()
87+ if url and (access_token or refresh_token or (user and password )):
88+ return TPPTokenConnection (url = url , user = user , password = password , access_token = access_token ,
89+ refresh_token = refresh_token , http_request_kwargs = http_request_kwargs )
90+ if api_key :
91+ return CloudConnection (token = api_key , url = url , http_request_kwargs = http_request_kwargs )
92+ else :
93+ raise VenafiError ("Bad credentials list" )
0 commit comments