File tree Expand file tree Collapse file tree 3 files changed +10
-16
lines changed
Expand file tree Collapse file tree 3 files changed +10
-16
lines changed Original file line number Diff line number Diff line change 1414# [START functions_slack_setup]
1515import hashlib
1616import hmac
17- import json
1817import os
1918
20- import googleapiclient
19+ import googleapiclient . discovery
2120from flask import jsonify
2221
23- with open ('config.json' , 'r' ) as f :
24- data = f .read ()
25- config = json .loads (data )
26-
2722
2823kgsearch = googleapiclient .discovery .build (
2924 'kgsearch' ,
3025 'v1' ,
31- developerKey = os .environ . get ( 'API_KEY' ) or config . get ( ' KG_API_KEY') ,
26+ developerKey = os .environ [ ' KG_API_KEY'] ,
3227 cache_discovery = False )
3328# [END functions_slack_setup]
3429
@@ -41,7 +36,7 @@ def verify_signature(request):
4136
4237 req = str .encode ('v0:{}:' .format (timestamp )) + request .get_data ()
4338 request_digest = hmac .new (
44- str .encode (config ['SLACK_SECRET' ]),
39+ str .encode (os . environ ['SLACK_SECRET' ]),
4540 req , hashlib .sha256
4641 ).hexdigest ()
4742 request_hash = 'v0={}' .format (request_digest )
Original file line number Diff line number Diff line change 1313
1414import json
1515
16- import googleapiclient
16+ import googleapiclient . discovery
1717import mock
1818import os
1919import pytest
2020
2121import main
2222
23- with open ('config.json' , 'r' ) as f :
24- data = f .read ()
25- config = json .loads (data )
2623
27-
28- kg_search = googleapiclient . discovery . build ( 'kgsearch' , 'v1' ,
29- developerKey = os .environ ['API_KEY ' ])
24+ kg_search = googleapiclient . discovery . build (
25+ 'kgsearch' , 'v1' ,
26+ developerKey = os .environ ['KG_API_KEY ' ])
3027example_response = kg_search .entities ().search (query = 'lion' , limit = 1 ).execute ()
3128
3229
@@ -53,7 +50,9 @@ def test_verify_signature_token_incorrect(self):
5350
5451 def test_verify_web_hook_valid_request (self ):
5552 request = Request ()
56- request .headers = {'X-Slack-Signature' : os .environ ['SLACK_TEST_SIGNATURE' ]}
53+ request .headers = {
54+ 'X-Slack-Signature' : os .environ ['SLACK_TEST_SIGNATURE' ]
55+ }
5756 main .verify_signature (request )
5857
5958 def test_format_slack_message (self ):
You can’t perform that action at this time.
0 commit comments