Been there, done that.
1)
I have not used the python client yet. I wrote my tests using requests
instead.
2)
For setting up a server I edited swagger_server/__main__.py
#!/usr/bin/env python3
import connexion
from .encoder import JSONEncoder
import ssl
from pathlib import Path
from pathlib import PurePath
import os
if __name__ == '__main__':
p = Path('.')
vis_cert = list(p.glob('**/Certificate_VIS*.pem'))
if len(vis_cert) == 0:
print('Error: no Certificate_VIS*.pem found')
vis_key = list(p.glob('**/PrivateKey_VIS*.pem'))
if len(vis_key) == 0:
print('Error: no PrivateKey_VIS*.pem found')
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain(str(vis_cert[0]), str(vis_key[0]))
app = connexion.App(__name__, specification_dir='./swagger/')
app.app.json_encoder = JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'Voyage Information
Service API facing SeaSWIM through SSC exposing interfaces to SeaSWIM
stakeholders'})
app.run(host='ec2-35-157-50-165.eu-central-1.compute.amazonaws.com',
port=443, ssl_context=context)
In this project we are using self signed certificates which brings up a
second problem. The root cert needs to be trusted by signging itself.
#!/bin/bash
sudo mkdir -p /usr/share/ca-certificates/MCtest
sudo cp MCtest/mc-ca-chain.pem /usr/share/ca-certificates/MCtest
sudo ln -s /usr/share/ca-certificates/MCtest/mc-ca-chain.pem /usr/lib/ssl/
certs/dfa402ab.0
The last symbolic links have funny names. They are hashes of the root
certificate DN. If you are using real certificates you do not need this.
For the client to connect to my server I may also need a client
certificate. The connection code looks like this:
from pathlib import Path
p = Path('.')
vis_cert = list(p.glob('**/Certificate_VIS*.pem'))
if len(vis_cert) == 0:
print('Error: no Certificate_VIS*.pem found')
vis_key = list(p.glob('**/PrivateKey_VIS*.pem'))
if len(vis_key) == 0:
print('Error: no PrivateKey_VIS*.pem found')
vis_trust = list(p.glob('**/mc-ca-chain.pem'))
if len(vis_trust) == 0:
print('Error: no mc-ca-chain.pem found')
vis_cert=(str(vis_cert[0]), str(vis_key[0]))
trustchain=str(vis_trust[0])
def test_VIS_001_01(self):
"""
VIS-001-1 - VIS-2: Request (get) voyage plan with chosen UVID from
VIS-1
"""
sub='/voyagePlans'
parameters={
'uvid': newvoyageuvid
}
response=requests.get(url + sub, params=parameters, cert=vis_cert,
verify=trustchain)
self.assert200(response, "Response body is : " + response.text)
But then you still have the problems I am asking in my question.
- I have no way to find out how to get the identity of the client
certificate from swagger generated python server.
- No solution for integrating this with uwsgi as the server is created as a
module.
3)
For models you can use them like this
from swagger_server.models.voyage_plan import VoyagePlan
import json
vp = VoyagePlan()
vp.route = '<route />'
payload=voyageplan
response=requests.post(url, data=payload, cert=vis_cert, verify=trustchain)
perjantai 24. maaliskuuta 2017 0.18.12 UTC+2 dips aws kirjoitti:
>
> Hi,
>
> Just started using swagger and getting familiar to the tools. Had few
> queries:
>
> 1) When i generate the python client from swagger-editor, i notice that it
> names my api as DefaultApi. Is there a way to change this in such a way
> that whenever folks in my team generate other swagger doc to python client
> the same of the base class, i.e DEfaultApi can be kept same..
>
> 2) what paramter do i need to set inorder to verify ssl requests? I tried
> setting verify_ssl to true but i get ssl certificate_verify_failed. I think
> by default it picks up certifi/cacert.pem but it doesn't seem to work.
> tried to set my certificate to varialble ssl_ca_cert in Confguration file
> but no luck.
>
> 3) Do you have an example to on how to use the model files generated for
> the API's by swagger codegen? From what i understand so far, i could just
> have a instance of DefaultApi and call the methods (get,post etc) and then
> play with the reponse data. Now what additional benefit can models provide
> since i already have the response data.
>
> Sorry for being naive..
>
> Appreciate your help.
>
> dips
>
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.