-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gcp secret manger support for DVT (#704)
* adding support for secret manger [GCP] * adding support for secret manger [GCP] * adding support for secret manger [GCP] * adding support for secret manger [GCP] * Revert "adding support for secret manger [GCP]" This reverts commit b959cda. * adding support for secret manger [GCP] * Merge remote-tracking branch 'origin/develop' into secret-manager # Conflicts: # docs/connections.md * Merge remote-tracking branch 'origin/develop' into secret-manager # Conflicts: # docs/connections.md * code review fixes - fix manger typo to manager - rename argument description - add google-cloud-secret-manager to requirement file * code review fixes - revert the naming of variables connections.md * code review fixes - revert the naming of variables connections.md * code review fixes - revert the naming of variables connections.md * code review fixes - revert the naming of variables connections.md * code review fixes - add test cases for secret manager class * code review fixes - revert the naming of variables connections.md * code review fixes - move secret manager testcases * code review fixes - revert the naming of variables connections.md
- Loading branch information
Showing
13 changed files
with
223 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# 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. | ||
|
||
import logging | ||
|
||
|
||
class SecretManagerBuilder: | ||
def build(self, client_type): | ||
""" | ||
:param client_type: | ||
:return: secret manager instance currently support gcp secret manager | ||
""" | ||
if client_type.lower() == "gcp": | ||
return GCPSecretManager() | ||
else: | ||
raise Exception(f"{client_type} is not supported yet.") | ||
|
||
|
||
class GCPSecretManager: | ||
""" | ||
GCPSecretManager: client to access secrets stored at GCP secret manager | ||
""" | ||
|
||
def __init__(self): | ||
# Import the Secret Manager client library. | ||
from google.cloud import secretmanager | ||
|
||
# Create the Secret Manager client. | ||
self.client = secretmanager.SecretManagerServiceClient() | ||
|
||
def maybe_secret(self, project_id, secret_id, version_id="latest"): | ||
""" | ||
Get information about the given secret. | ||
:return String value with the secret value or the secret id if the secret value if not exists | ||
""" | ||
try: | ||
# Build the resource name of the secret. | ||
name = f"projects/{project_id}/secrets/{secret_id}/versions/{version_id}" | ||
# Access the secret version. | ||
response = self.client.access_secret_version(name=name) | ||
# Return the decoded payload. | ||
payload = response.payload.data.decode("UTF-8") | ||
return payload | ||
except Exception as e: | ||
logging.warning(f"{secret_id} : {e}") | ||
return secret_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.