1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import time
15+ import json
16+ import os
1617
1718from google .cloud import dlp_v2
1819from google .cloud .dlp_v2 import enums
1920from google .cloud .dlp_v2 .proto import dlp_pb2
2021
2122
2223class TestSystemDlpService (object ):
24+
25+ def _get_project_id (self ):
26+ env_var_name = 'GOOGLE_APPLICATION_CREDENTIALS'
27+ path = os .environ [env_var_name ]
28+ json_data = open (path ).read ()
29+ data = json .loads (json_data )
30+ return data ['project_id' ]
31+
2332 def test_inspect_content (self ):
33+ # get project id from json file
34+ project_id = self ._get_project_id ()
2435
2536 client = dlp_v2 .DlpServiceClient ()
2637 min_likelihood = enums .Likelihood .POSSIBLE
27- inspect_config = {'min_likelihood' : min_likelihood }
28- type_ = 'text/plain'
29- value = 'my phone number is 215-512-1212'
30- items_element = {'type' : type_ , 'value' : value }
31- items = [items_element ]
32- response = client .inspect_content (inspect_config , items )
38+ info_types = [{'name' : 'FIRST_NAME' }, {'name' : 'LAST_NAME' }]
39+ inspect_config = {
40+ 'info_types' : info_types ,
41+ 'min_likelihood' : min_likelihood ,
42+ }
43+ item = {'value' : 'Robert Frost' }
44+ parent = client .project_path (project_id )
45+ response = client .inspect_content (parent , inspect_config , item )
46+
0 commit comments