I'm designing an API to enable remote clients to execute PowerShell scripts against a remote server.
To execute the commands effectively, the application needs to create a unique runspace for the remote client (so it can initialise the runspace with an appropriate host and command set for that client). Every time the client makes a request, the API will need to ensure the request is executed within the correct runspace.
An (over-simplified) view of the flow might look like this:
- Client connects to Web API, POSTs credentials for the backend application
- Web API passes these credentials through to the backend app, which uses them to create a RunSpace uniquely configured for that client
- Web API and app "agree" on a linked
session-runspace
ID - Web API either informs client of
session-runspace
ID or holds it in memory - Client makes request: e.g.
"GET http://myapiserver/api/backup-status/"
- Web API passes request through to backend app function
- Backend app returns results: e.g. "JSON {this is the current status of backup for user/client x}"
- Web API passes these results through to remote client
- Either timeout or logout request ends 'session' and RunSpace is disposed
(In reality, the PowerShell App might just be a custom controller/model within the Web API, or it could be an IIS snap-in or similar - I'm open to design suggestions here...).
My concern is, in order to create a unique RunSpace for each remote client, I need to give that client a unique "session" ID so the API can pass requests through to the app correctly. This feels like I'm breaking the stateless rule.
In truth, the API is still stateless, just the back-end app is not, but it does need to create a session (RunSpace) for each client and then dispose of the RunSpace after a timeout/end-session request.
QUESTIONS
- Should I hack into the Authentication mechanism in ASP.NET MVC to spin-up the RunSpace?
- Should I admit defeat and just hack up a session variable?
- Is there a better SOA that I should consider? (Web API feels very neat and tidy for this though - particularly if I want to have web, mobile and what-have-you clients)