potiuk commented on a change in pull request #9333: URL: https://github.com/apache/airflow/pull/9333#discussion_r441440378
########## File path: airflow/providers/hashicorp/hooks/vault.py ########## @@ -0,0 +1,546 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Hook for HashiCorp Vault""" +from typing import List, Optional, Tuple + +import hvac +from cached_property import cached_property +from hvac.exceptions import InvalidPath, VaultError +from requests import Response + +from airflow.hooks.base_hook import BaseHook +from airflow.utils.log.logging_mixin import LoggingMixin + +DEFAULT_KUBERNETES_JWT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token' +DEFAULT_KV_ENGINE_VERSION = 2 + + +VALID_KV_VERSIONS: List[int] = [1, 2] +VALID_AUTH_TYPES: List[str] = [ + 'approle', + 'github', + 'gcp', + 'kubernetes', + 'ldap', + 'token', + 'userpass' +] + + +class _VaultClient(LoggingMixin): # pylint: disable=too-many-instance-attributes + """ + Retrieves Authenticated client from Hashicorp Vault. This is purely internal class promoting + authentication code reuse between the Hook an Secret, it should not be used directly in + Airflow DAGs. Use VaultBackend for backend integration and Hook in case you want to communicate + with VaultHook using standard Airflow Connection definition. + + :param url: Base URL for the Vault instance being addressed. + :type url: str + :param auth_type: Authentication Type for Vault. Default is ``token``. Available values are in + :py:const:`airflow.providers.hashicorp.hooks.vault.VALID_AUTH_TYPES`. + :type auth_type: str + :param mount_point: The "path" the secret engine was mounted on. Default is "secret". Note that + this mount_point is not used for authentication if authentication is done via a + different engine. + :type mount_point: str + :param kv_engine_version: Selects the version of the engine to run (``1`` or ``2``, default: ``2``). + :type kv_engine_version: int + :param token: Authentication token to include in requests sent to Vault + (for ``token`` and ``github`` auth_type). + :type token: str + :param username: Username for Authentication (for ``ldap`` and ``userpass`` auth_types). + :type username: str + :param password: Password for Authentication (for ``ldap`` and ``userpass`` auth_types). + :type password: str + :param secret_id: Secret ID for Authentication (for ``approle`` auth_type). + :type secret_id: str + :param role_id: Role ID for Authentication (for ``approle`` auth_type). + :type role_id: str + :param kubernetes_role: Role for Authentication (for ``kubernetes`` auth_type). + :type kubernetes_role: str + :param kubernetes_jwt_path: Path for kubernetes jwt token (for ``kubernetes`` auth_type, default: + ``/var/run/secrets/kubernetes.io/serviceaccount/token``). + :type kubernetes_jwt_path: str + :param gcp_key_path: Path to GCP Credential JSON file (for ``gcp`` auth_type). + :type gcp_key_path: str + :param gcp_scopes: Comma-separated string containing GCP scopes (for ``gcp`` auth_type). + :type gcp_scopes: str + """ + def __init__( # pylint: disable=too-many-arguments + self, + url: Optional[str] = None, + auth_type: str = 'token', + mount_point: str = "secret", + kv_engine_version: Optional[int] = None, + token: Optional[str] = None, + username: Optional[str] = None, + password: Optional[str] = None, + secret_id: Optional[str] = None, + role_id: Optional[str] = None, + kubernetes_role: Optional[str] = None, + kubernetes_jwt_path: Optional[str] = '/var/run/secrets/kubernetes.io/serviceaccount/token', + gcp_key_path: Optional[str] = None, + gcp_scopes: Optional[str] = None, + **kwargs + ): + super().__init__(**kwargs) Review comment: Good catch! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org