[Flask] Exposing bash commands over Rest API with Flask

Shmulik Avramson shmulikav at checkpoint.com
Mon Dec 4 03:47:56 EST 2017

Hi Kelvin,
Thanks for reposing.

Let me clarify myself. the purpose of the XML I posted isn’t for describing my API – it actually implements the API.
As my Flask server starts, I have a parser that pars the XML and register each URL with handler that run exec with the relevant bash command.

Continuing the example bellow, after my Flask parses the XML, the server is ready to accept “https://<IP>/myCommand<https://%3cIP%3e/myCommand>” with its arguments and the handler will run
bash with myCommand and the args from the API call.

I have hundreds of bash commands on my server, and my customers want them to be exposed over rest, with that kind of infrastructure I can easily expose the commands.

What do you think?
Are you familiar with similar existing infrastructure?

Thank you!

From: Kelvin M [mailto:kelvin.malyar at gmail.com]
Sent: Sunday, December 03, 2017 6:31 PM
To: Shmulik Avramson
Cc: flask at python.org
Subject: Re: [Flask] Exposing bash commands over Rest API with Flask

Hi Sam,

It sounds like you're going part of the way in re-inventing the OpenAPI specification for a Bash client.

A quick (and i mean cursory first response) glance shows this: https://github.com/bkryza/bash-swagger-codegen

I would look into that: https://swagger.io/blog/introducing-the-open-api-initiative/

Secondly, I'm not sure how Flask would help you implement bash commands unless you're just running curl commands to different endpoints.  How does that work?  It sounds interesting!


On Sun, Dec 3, 2017 at 11:12 AM, Shmulik Avramson <shmulikav at checkpoint.com<mailto:shmulikav at checkpoint.com>> wrote:
Hi Flask community,

I’m using Flask to expose exiting (propriety) shell commands over Rest API.
Assuming I have “myCommand arg1 arg2 [arg3]” on my server,  I’m exposing new API as below:

URL: https://<IP>/myCommand<https://%3cIP%3e/myCommand>

As I have many commands, I prepared an XML file to automate part of the process.
The XML contains also validation for arguments and aggregate the API under features.

An example:
    <feature name="myFeature">
        <command url="/myCommand">
            <arg key="arg1" type="boolean"/>
            <arg key="arg2" type="int"/>
            <arg key="arg3" type="IP"/>
          <bash output="show/ignore"> myCommand {arg1} {arg2} {?arg3:arg3} </bash>

Now, with the above infrastructure, every person in my company can easily expose his own bash commands.

What do you think on the idea?
Are there any similar functionalities in Flask I can use instead of developing my own?
Assuming the answer is no, do you think it worth contribution?

Thank in advance :)

Flask mailing list
Flask at python.org<mailto:Flask at python.org>

Email secured by Check Point.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20171204/b0f6323a/attachment.html>

More information about the Flask mailing list