Reusing external API tokens between requests #2169
Unanswered
guillomovitch
asked this question in
Q&A
Replies: 1 comment
-
Since the url and creds come from the config (and not a user session), could it work to establish Net::BigIP as a helper in the app?
If the token stored in your
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.
I'm using Mojolicious for a small prototype of data visualisation. This implies using F5 Networks API to request load balancer state every X seconds (10 by default) from javascript code, in order to refresh display.
A naive implementation creates a new throw-away Net::BigIP object for each request in my controller:
package Net::BigIP::NetworkMap::Controller;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub update_map($self) {
...
my $bigip = Net::BigIP->new(
url => $config->{bigip}->{url},
)->create_session(
username => $config->{bigip}->{username},
password => $config->{bigip}->{password}
);
...
}
However, the number of concurrent active API sessions quickly reach maximum allowed:
user foobar has reached maximum active login tokens
I could either stay with throw-away objects, closing the session before discarding it, or try to reuse them between requests. However, I'm facing difficulties to do it properly.
I initially thought of making those Net::BigIP objects attributes of my controller class. However, there doen't seem to be an easy way to automatically run code at controller instance creation/destruction. Moreover, whereas they are explicitly instanciated when needed, it isn't obvious to me if this instance is ever reused between requests, or discarded immediatly, in which case the problem would stay the same.
Implementing a persistant connection pool at application level, like database connections are usually handled, seems quite difficult technically. Moreover, keeping the session alive would require performing useless API requests every 10 minutes, which seems a waste of resources.
It should probably get implemented at Mojolicious session level. However, this would requires managing cookies from javascript code on client side, which seems painful. There seem to be at least one plugin, Mojolicious::Plugin::ServerSession, to manage server-side sessions, but I wondered if I missed something obvious before trying this solution.
Regards
Beta Was this translation helpful? Give feedback.
All reactions