Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/secretmanager_v1beta1/__init__.py: 89%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

9 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16import sys 

17 

18import google.api_core as api_core 

19 

20from google.cloud.secretmanager_v1beta1 import gapic_version as package_version 

21 

22__version__ = package_version.__version__ 

23 

24if sys.version_info >= (3, 8): # pragma: NO COVER 

25 from importlib import metadata 

26else: # pragma: NO COVER 

27 # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove 

28 # this code path once we drop support for Python 3.7 

29 import importlib_metadata as metadata 

30 

31from .services.secret_manager_service import ( 

32 SecretManagerServiceAsyncClient, 

33 SecretManagerServiceClient, 

34) 

35from .types.resources import Replication, Secret, SecretPayload, SecretVersion 

36from .types.service import ( 

37 AccessSecretVersionRequest, 

38 AccessSecretVersionResponse, 

39 AddSecretVersionRequest, 

40 CreateSecretRequest, 

41 DeleteSecretRequest, 

42 DestroySecretVersionRequest, 

43 DisableSecretVersionRequest, 

44 EnableSecretVersionRequest, 

45 GetSecretRequest, 

46 GetSecretVersionRequest, 

47 ListSecretsRequest, 

48 ListSecretsResponse, 

49 ListSecretVersionsRequest, 

50 ListSecretVersionsResponse, 

51 UpdateSecretRequest, 

52) 

53 

54if hasattr(api_core, "check_python_version") and hasattr( 

55 api_core, "check_dependency_versions" 

56): # pragma: NO COVER 

57 api_core.check_python_version("google.cloud.secretmanager_v1beta1") # type: ignore 

58 api_core.check_dependency_versions("google.cloud.secretmanager_v1beta1") # type: ignore 

59else: # pragma: NO COVER 

60 # An older version of api_core is installed which does not define the 

61 # functions above. We do equivalent checks manually. 

62 try: 

63 import sys 

64 import warnings 

65 

66 _py_version_str = sys.version.split()[0] 

67 _package_label = "google.cloud.secretmanager_v1beta1" 

68 if sys.version_info < (3, 9): 

69 warnings.warn( 

70 "You are using a non-supported Python version " 

71 + f"({_py_version_str}). Google will not post any further " 

72 + f"updates to {_package_label} supporting this Python version. " 

73 + "Please upgrade to the latest Python version, or at " 

74 + f"least to Python 3.9, and then update {_package_label}.", 

75 FutureWarning, 

76 ) 

77 if sys.version_info[:2] == (3, 9): 

78 warnings.warn( 

79 f"You are using a Python version ({_py_version_str}) " 

80 + f"which Google will stop supporting in {_package_label} in " 

81 + "January 2026. Please " 

82 + "upgrade to the latest Python version, or at " 

83 + "least to Python 3.10, before then, and " 

84 + f"then update {_package_label}.", 

85 FutureWarning, 

86 ) 

87 

88 def parse_version_to_tuple(version_string: str): 

89 """Safely converts a semantic version string to a comparable tuple of integers. 

90 Example: "4.25.8" -> (4, 25, 8) 

91 Ignores non-numeric parts and handles common version formats. 

92 Args: 

93 version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" 

94 Returns: 

95 Tuple of integers for the parsed version string. 

96 """ 

97 parts = [] 

98 for part in version_string.split("."): 

99 try: 

100 parts.append(int(part)) 

101 except ValueError: 

102 # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here. 

103 # This is a simplification compared to 'packaging.parse_version', but sufficient 

104 # for comparing strictly numeric semantic versions. 

105 break 

106 return tuple(parts) 

107 

108 def _get_version(dependency_name): 

109 try: 

110 version_string: str = metadata.version(dependency_name) 

111 parsed_version = parse_version_to_tuple(version_string) 

112 return (parsed_version, version_string) 

113 except Exception: 

114 # Catch exceptions from metadata.version() (e.g., PackageNotFoundError) 

115 # or errors during parse_version_to_tuple 

116 return (None, "--") 

117 

118 _dependency_package = "google.protobuf" 

119 _next_supported_version = "4.25.8" 

120 _next_supported_version_tuple = (4, 25, 8) 

121 _recommendation = " (we recommend 6.x)" 

122 (_version_used, _version_used_string) = _get_version(_dependency_package) 

123 if _version_used and _version_used < _next_supported_version_tuple: 

124 warnings.warn( 

125 f"Package {_package_label} depends on " 

126 + f"{_dependency_package}, currently installed at version " 

127 + f"{_version_used_string}. Future updates to " 

128 + f"{_package_label} will require {_dependency_package} at " 

129 + f"version {_next_supported_version} or higher{_recommendation}." 

130 + " Please ensure " 

131 + "that either (a) your Python environment doesn't pin the " 

132 + f"version of {_dependency_package}, so that updates to " 

133 + f"{_package_label} can require the higher version, or " 

134 + "(b) you manually update your Python environment to use at " 

135 + f"least version {_next_supported_version} of " 

136 + f"{_dependency_package}.", 

137 FutureWarning, 

138 ) 

139 except Exception: 

140 warnings.warn( 

141 "Could not determine the version of Python " 

142 + "currently being used. To continue receiving " 

143 + "updates for {_package_label}, ensure you are " 

144 + "using a supported version of Python; see " 

145 + "https://devguide.python.org/versions/" 

146 ) 

147 

148__all__ = ( 

149 "SecretManagerServiceAsyncClient", 

150 "AccessSecretVersionRequest", 

151 "AccessSecretVersionResponse", 

152 "AddSecretVersionRequest", 

153 "CreateSecretRequest", 

154 "DeleteSecretRequest", 

155 "DestroySecretVersionRequest", 

156 "DisableSecretVersionRequest", 

157 "EnableSecretVersionRequest", 

158 "GetSecretRequest", 

159 "GetSecretVersionRequest", 

160 "ListSecretVersionsRequest", 

161 "ListSecretVersionsResponse", 

162 "ListSecretsRequest", 

163 "ListSecretsResponse", 

164 "Replication", 

165 "Secret", 

166 "SecretManagerServiceClient", 

167 "SecretPayload", 

168 "SecretVersion", 

169 "UpdateSecretRequest", 

170)