MiamiOH / foreman_teamdynamix

A Foreman Plugin for TeamDynamix
GNU General Public License v3.0
1 stars 1 forks source link

Re-use TD api auth token #14

Closed nipendar closed 6 years ago

nipendar commented 6 years ago

In order to reuse the authentication token to TeamDynamix Api

edestecd commented 6 years ago

Maybe we don't need this. DO we really need to store it in the session, since its stored in the model?

nipendar commented 6 years ago

api auth token is separate from teamdynamix_asset_id saved in model. It would save a trip to get auth token before get/post call to create asset or get asset data every time we add a host (or multiple hosts if running rake task). If we save it to the session we can manage it as we manage user login session.

Another way to achieve this would be to have singleton TeamdynamixApi object shared across all host model instances and keep API auth token as an attribute to TemdynamixApi instance.

Thoughts?

nipendar commented 6 years ago

Estimate is 8-12 hours

edestecd commented 6 years ago

It is stored in an instance variable in the model. That's what I meant. So as long as the host instance is around it is preserved. That is usually one web page request. So without storing it in the session we login to TD once per Foreman page request.

If we store it in the session, which Foreman stores in the db table sessions, then a TD login is saved for many Foreman page requests until it times out...

I'm not sure what the savings or efficiency of one extra login TD api call is per page request. How much time is saved? Maybe not that much. We can see once we start using it. I'd put this issue off until then. If its not a noticeable lag then we may choose not to do this.

nipendar commented 6 years ago

Current code does not allow reuse of token.

Let's consider this scenario, user clicks on a host from the list of hosts under host#show. Host Controller gets a new instance of host model, i.e a new instance of Teamdynamix Api i.e a new Auth token. This would happen each time user looks at a host or creates a host.

As I suggested earlier, an alternate way to allow the reuse of auth token and in fact TeamdynamixApi class is to make it a singleton class. This will allow auth_token to be reused across all the controller actions and for all the hosts. That would also be a lot simpler than session management.

I will give that a try.

nipendar commented 6 years ago

I tested this real quick and I think singleton DI would work best. I have updated issue description for the same. work estimate 4 hours

edestecd commented 6 years ago

Resolved by #22