[Flask] Exposing bash commands over Rest API with Flask

Shmulik Avramson shmulikav at checkpoint.com
Tue Dec 12 16:36:17 EST 2017


Hi again,
Does anyone can think of an existing similar infrastructure?
Do you think it is worth contribution to Flask?

Thank you!

Sam

From: Shmulik Avramson
Sent: Monday, December 04, 2017 11:16 PM
To: 'Kelvin M'
Cc: flask at python.org
Subject: RE: [Flask] Exposing bash commands over Rest API with Flask

Hi,
Ansible works over SSH and I need rest API.

Sam

From: Kelvin M [mailto:kelvin.malyar at gmail.com]
Sent: Monday, December 04, 2017 5:05 PM
To: Shmulik Avramson
Cc: flask at python.org<mailto:flask at python.org>
Subject: Re: [Flask] Exposing bash commands over Rest API with Flask

Hi Sam,

I see.

I haven't seen anything like that.  We use Ansible (and write our own plugins for whatever we need that doesn't have a module already written).  I'm still not completely clear on the use case. :)   Keep me posted on how it goes.

Regards,
Kelvin

On Mon, Dec 4, 2017 at 3:47 AM, Shmulik Avramson <shmulikav at checkpoint.com<mailto:shmulikav at checkpoint.com>> wrote:
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!
Sam

From: Kelvin M [mailto:kelvin.malyar at gmail.com<mailto:kelvin.malyar at gmail.com>]
Sent: Sunday, December 03, 2017 6:31 PM
To: Shmulik Avramson
Cc: flask at python.org<mailto: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!

regards,
Kelvin

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>
json:
{
                "arg1":”<value>”,
                "arg2":”<value>”,
"arg3":”<value>”
}

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">
      <commands>
        <command url="/myCommand">
          <must-args>
            <arg key="arg1" type="boolean"/>
            <arg key="arg2" type="int"/>
          </must-args>
          <opt-args>
            <arg key="arg3" type="IP"/>
          </opt-args>
          <bash output="show/ignore"> myCommand {arg1} {arg2} {?arg3:arg3} </bash>
        </command>
      </commands>
    </feature>

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 :)
Sam



_______________________________________________
Flask mailing list
Flask at python.org<mailto:Flask at python.org>
https://mail.python.org/mailman/listinfo/flask



Email secured by Check Point.



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


More information about the Flask mailing list