用于Google云平台上的app引擎的SAML2协议的Python实现

时间:2016-11-17 14:32:56

标签: python-2.7 google-app-engine ctypes saml-2.0

我在谷歌云平台上尝试了pysaml2和python-saml库,但两者都在内部使用了一些库,这些库在C库上使用C扩展或python包装,这与app引擎不兼容,因为app引擎阻止了其生态环境中的c实现库系统。 是否有人使用python在appengine中实现了saml2协议?

pysaml2文档表明它是一个纯python实现,但它也使用像pycrytodome或cryptodome这样需要_ctype库的库。

以下是错误:

File "/home/***/anaconda2/lib/python2.7/ctypes/_init_.py", line 10, in <module> 
  from _ctypes import Union, Structure, Array  
File "/home/***/sdks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module 
  raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes

如果可能,请提供其他一些方法。

1 个答案:

答案 0 :(得分:0)

I figured out what to do if you want to use c libraries in the app engine environment.
First of all you have to use app engine flexible environment instead of standard environment there also use the custom runtime. A sample yaml file is posted below.

的app.yaml

runtime: custom  
env: flex  
api_version: 1

handlers:  
- url: /.*  
  script: main.app

The second thing which you need to do is choose a proper base image to build from and install the necessary libraries.

示例dockerfile

FROM gcr.io/google_appengine/python-compat-multicore  
RUN apt-get update -y  
RUN apt-get install -y python-pip build-essential libssl-dev libffi-dev python-dev libxml2-dev libxslt1-dev xmlsec1

RUN apt-get install -y curl unzip  
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz  
RUN mkdir -p /usr/local/gcloud  
RUN tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz  
RUN /usr/local/gcloud/google-cloud-sdk/install.sh  

RUN curl https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.40.zip > /tmp/google_appengine_1.9.40.zip  
RUN unzip /tmp/google_appengine_1.9.40.zip -d /usr/local/gae

ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin  
ENV PATH $PATH:/usr/local/gae/google_appengine/  
COPY . /app  
WORKDIR /app  

ENV MODULE_YAML_PATH app.yaml

RUN pip install -r requirements.txt