Getting project UserSource separately

Is there a way to get UserSources and their Failover Source for each project on the gateway separately ?

Not easily/not in a supported manner. You have to reach into each project and pull out a specific "global props" resource, which requires some care.

Before we get into all the "how", though, can you tell us more about the "why" you're looking for this info?

To manage users, I need to retrieve the user source based on the selected project. This will allow the admin to control which project users have access to the project view.

I'll point out for posterity that our current license agreement doesn't allow "multi-tenant" hosted Ignition outside of specific scenarios, but I'm also not a lawyer and that may not be what you're doing at all.

As for the question at hand: basically, you're diving head first into deep waters. The way to do this is literally going to be the same way we do it in our code, but is also going to be subject to change at any moment - this is not a part of our public API contract so once you start doing this, you cannot expect your project to seamlessly upgrade between major versions. I can explicitly guarantee that any code you write to handle this in 8.1 will not work on 8.3.0 once it's released around the end of this year.

All that aside:

  • You'll want to run this code on the gateway.
  • You need a reference to the gateway context. Examples are all over the forum. This is your first step off the safe beach into the "you could break your whole project" waters.
  • From that GatewayContext, you'll retrieve an instance of the ProjectManager class. As the name implies, this houses all your projects.
  • Next, you'll retrieve your project(s) by name, then retrieve the global props singleton resource by ResourcePath.
  • Then you'll use ResourceUtil to deserialize the resource data into a useful Java object - an instance of the GlobalProps class.
  • Then you'll extract the user source name from that class instance.
1 Like

While we are supposed to use the gateway api to access the ProjectManager, why doesn't it work in the major upgrade? it means gateway api will change in every major upgrade?

Within minor versions (8.1.x to 8.1.y), APIs are consistent on a "best effort" basis, to reduce pain for our module development partners and third parties.

Major versions (8.x to 8.y) are explicitly used to give us an opportunity to break APIs and make more sweeping changes. I can guarantee anything you do in this area will break because we're expanding the resource system used for projects to include all gateway config, more or less. This will involve, at minimum, renaming packages and classes involved.

2 Likes

If this happens, all third-party modules must be upgraded to the new version ?

Yes. IA does not guarantee any APIs in its SDK. IA's past practice is as Paul described, where some of my modules worked unchanged across major upgrades and other modules broke all over the place.

That just the way it is. If your environment suffers from that, stay on a single LTS version as long as you can.

1 Like

Just like Android apps with new versions.