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

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

10 statements  

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

2# Copyright 2026 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 

24from importlib import metadata 

25 

26from .services.secret_manager_service import ( 

27 SecretManagerServiceAsyncClient, 

28 SecretManagerServiceClient, 

29) 

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

31from .types.service import ( 

32 AccessSecretVersionRequest, 

33 AccessSecretVersionResponse, 

34 AddSecretVersionRequest, 

35 CreateSecretRequest, 

36 DeleteSecretRequest, 

37 DestroySecretVersionRequest, 

38 DisableSecretVersionRequest, 

39 EnableSecretVersionRequest, 

40 GetSecretRequest, 

41 GetSecretVersionRequest, 

42 ListSecretsRequest, 

43 ListSecretsResponse, 

44 ListSecretVersionsRequest, 

45 ListSecretVersionsResponse, 

46 UpdateSecretRequest, 

47) 

48 

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

50 api_core, "check_dependency_versions" 

51): # pragma: NO COVER 

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

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

54else: # pragma: NO COVER 

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

56 # functions above. We do equivalent checks manually. 

57 try: 

58 import warnings 

59 

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

61 _package_label = "google.cloud.secretmanager_v1beta1" 

62 if sys.version_info < (3, 10): 

63 warnings.warn( 

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

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

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

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

68 + f"least to Python 3.10, and then update {_package_label}.", 

69 FutureWarning, 

70 ) 

71 

72 def parse_version_to_tuple(version_string: str): 

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

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

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

76 Args: 

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

78 Returns: 

79 Tuple of integers for the parsed version string. 

80 """ 

81 parts = [] 

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

83 try: 

84 parts.append(int(part)) 

85 except ValueError: 

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

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

88 # for comparing strictly numeric semantic versions. 

89 break 

90 return tuple(parts) 

91 

92 def _get_version(dependency_name): 

93 try: 

94 version_string: str = metadata.version(dependency_name) 

95 parsed_version = parse_version_to_tuple(version_string) 

96 return (parsed_version, version_string) 

97 except Exception: 

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

99 # or errors during parse_version_to_tuple 

100 return (None, "--") 

101 

102 _dependency_package = "google.protobuf" 

103 _next_supported_version = "4.25.8" 

104 _next_supported_version_tuple = (4, 25, 8) 

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

106 (_version_used, _version_used_string) = _get_version(_dependency_package) 

107 if _version_used and _version_used < _next_supported_version_tuple: 

108 warnings.warn( 

109 f"Package {_package_label} depends on " 

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

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

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

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

114 + " Please ensure " 

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

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

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

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

119 + f"least version {_next_supported_version} of " 

120 + f"{_dependency_package}.", 

121 FutureWarning, 

122 ) 

123 except Exception: 

124 warnings.warn( 

125 "Could not determine the version of Python " 

126 + "currently being used. To continue receiving " 

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

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

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

130 ) 

131 

132__all__ = ( 

133 "SecretManagerServiceAsyncClient", 

134 "AccessSecretVersionRequest", 

135 "AccessSecretVersionResponse", 

136 "AddSecretVersionRequest", 

137 "CreateSecretRequest", 

138 "DeleteSecretRequest", 

139 "DestroySecretVersionRequest", 

140 "DisableSecretVersionRequest", 

141 "EnableSecretVersionRequest", 

142 "GetSecretRequest", 

143 "GetSecretVersionRequest", 

144 "ListSecretVersionsRequest", 

145 "ListSecretVersionsResponse", 

146 "ListSecretsRequest", 

147 "ListSecretsResponse", 

148 "Replication", 

149 "Secret", 

150 "SecretManagerServiceClient", 

151 "SecretPayload", 

152 "SecretVersion", 

153 "UpdateSecretRequest", 

154)