Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5048c8

Browse files
engelkecrwilcox
andauthored
Restore inadvertently deleted folder (GoogleCloudPlatform#4501)
* Restore inadvertently deleted folder * Fixed Py 2.7 appengine_config shim * Removed unneeded import, skip impossible test * Missing import added Co-authored-by: Christopher Wilcox <[email protected]>
1 parent cd7fbcc commit e5048c8

File tree

11 files changed

+127
-16
lines changed

11 files changed

+127
-16
lines changed

appengine/standard/migration/urlfetch/async/appengine_config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from google.appengine.api import apiproxy_stub_map
16-
from google.appengine.api import urlfetch_stub
1715
from google.appengine.ext import vendor
1816

1917
# Add any libraries installed in the "lib" folder.
@@ -24,9 +22,3 @@
2422
# Use the App Engine Requests adapter. This makes sure that Requests uses
2523
# URLFetch.
2624
requests_toolbelt.adapters.appengine.monkeypatch()
27-
28-
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
29-
apiproxy_stub_map.apiproxy.RegisterStub(
30-
'urlfetch',
31-
urlfetch_stub.URLFetchServiceStub()
32-
)

appengine/standard/migration/urlfetch/async/main_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
# limitations under the License.
1414

1515
import main
16+
import pytest
17+
import sys
1618

1719

20+
@pytest.mark.skipif(sys.version_info < (3, 0), reason="no urlfetch adapter in test env")
1821
def test_index():
1922
main.app.testing = True
2023
client = main.app.test_client()

appengine/standard/migration/urlfetch/requests/appengine_config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from google.appengine.api import apiproxy_stub_map
16-
from google.appengine.api import urlfetch_stub
1715
from google.appengine.ext import vendor
1816

1917
# Add any libraries installed in the "lib" folder.
@@ -24,9 +22,3 @@
2422
# Use the App Engine Requests adapter. This makes sure that Requests uses
2523
# URLFetch.
2624
requests_toolbelt.adapters.appengine.monkeypatch()
27-
28-
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
29-
apiproxy_stub_map.apiproxy.RegisterStub(
30-
'urlfetch',
31-
urlfetch_stub.URLFetchServiceStub()
32-
)

appengine/standard/migration/urlfetch/requests/main_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
# limitations under the License.
1414

1515
import main
16+
import pytest
17+
import sys
1618

1719

20+
@pytest.mark.skipif(sys.version_info < (3, 0), reason="no urlfetch adapter in test env")
1821
def test_index():
1922
main.app.testing = True
2023
client = main.app.test_client()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## App Engine to App Engine Request Sample
2+
3+
This sample application shows how an App Engine for Python 3.7 app can make
4+
a request to an App Engine for Python 2.7 app that includes an Authorization
5+
header the receiving app can use to verify the calling app's identity.
6+
7+
This is a way for App Engine app-to-app requests can verify the identity of
8+
the calling applications, replacing the built-in X-Appengine-Inbound-Appid
9+
trustworthy header provided when using `urlfetch` in App Engine for
10+
Python 2.7. It requires the receiving app to validate the incoming request
11+
as shown in the appengine/standard/migration/incoming sample app in this
12+
repository.
13+
14+
This sample app presents users with a form to fill in another App Engine
15+
app's URL. On submission, this app calls the second App Engine app, and
16+
echoes the response, as plain text, to the user.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: python37
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from flask import Flask, render_template, request
16+
from google.auth.transport import requests as reqs
17+
from google.oauth2 import id_token
18+
import requests
19+
20+
app = Flask(__name__)
21+
22+
23+
@app.route('/', methods=['GET'])
24+
def index():
25+
return render_template('index.html')
26+
27+
28+
@app.route('/', methods=['POST'])
29+
def make_request():
30+
url = request.form['url']
31+
token = id_token.fetch_id_token(reqs.Request(), url)
32+
33+
resp = requests.get(
34+
url,
35+
headers={'Authorization': 'Bearer {}'.format(token)}
36+
)
37+
38+
message = 'Response when calling {}:\n\n'.format(url)
39+
message += resp.text
40+
41+
return message, 200, {'Content-type': 'text/plain'}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_index():
19+
main.app.testing = True
20+
client = main.app.test_client()
21+
22+
r = client.get('/')
23+
assert r.status_code == 200
24+
assert 'Make a request' in r.data.decode('utf-8')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest==6.0.1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests==2.24.0
2+
flask==1.1.2
3+
google-auth==1.20.1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Make App-to-app Request</title>
5+
</head>
6+
<body>
7+
8+
<h1>Make App-to-app Request</h1>
9+
10+
<p>
11+
Make a request to another App Engine application, including an
12+
Authorization token identifying the requesting application.
13+
</p>
14+
15+
<form action="" method="post">
16+
<label for="url">URL to call: </label>
17+
<input type="text" name="url" id="url" required />
18+
<input type="submit" value="Make authenticated call" />
19+
</form>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)