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 14
14
# [START functions_slack_setup]
15
15
import hashlib
16
16
import hmac
17
- import json
18
17
import os
19
18
20
- import googleapiclient
19
+ import googleapiclient . discovery
21
20
from flask import jsonify
22
21
23
- with open ('config.json' , 'r' ) as f :
24
- data = f .read ()
25
- config = json .loads (data )
26
-
27
22
28
23
kgsearch = googleapiclient .discovery .build (
29
24
'kgsearch' ,
30
25
'v1' ,
31
- developerKey = os .environ . get ( 'API_KEY' ) or config . get ( ' KG_API_KEY') ,
26
+ developerKey = os .environ [ ' KG_API_KEY'] ,
32
27
cache_discovery = False )
33
28
# [END functions_slack_setup]
34
29
@@ -41,7 +36,7 @@ def verify_signature(request):
41
36
42
37
req = str .encode ('v0:{}:' .format (timestamp )) + request .get_data ()
43
38
request_digest = hmac .new (
44
- str .encode (config ['SLACK_SECRET' ]),
39
+ str .encode (os . environ ['SLACK_SECRET' ]),
45
40
req , hashlib .sha256
46
41
).hexdigest ()
47
42
request_hash = 'v0={}' .format (request_digest )
Original file line number Diff line number Diff line change 13
13
14
14
import json
15
15
16
- import googleapiclient
16
+ import googleapiclient . discovery
17
17
import mock
18
18
import os
19
19
import pytest
20
20
21
21
import main
22
22
23
- with open ('config.json' , 'r' ) as f :
24
- data = f .read ()
25
- config = json .loads (data )
26
23
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 ' ])
30
27
example_response = kg_search .entities ().search (query = 'lion' , limit = 1 ).execute ()
31
28
32
29
@@ -53,7 +50,9 @@ def test_verify_signature_token_incorrect(self):
53
50
54
51
def test_verify_web_hook_valid_request (self ):
55
52
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
+ }
57
56
main .verify_signature (request )
58
57
59
58
def test_format_slack_message (self ):
You can’t perform that action at this time.
0 commit comments