async function loadHubSettings()

in tools/awps-tunnel/server/commander.ts [210:236]


async function loadHubSettings(subscriptionId: string | undefined, resourceGroup: string | undefined, endpoint: URL, hub: string): Promise<ServiceConfiguration> {
  let message = "";
  let resourceName = "";
  let eventHandlers: EventHandlerSetting[] | undefined = [];
  if (subscriptionId && resourceGroup) {
    resourceName = endpoint.hostname.split(".")[0];
    if (!resourceName) {
      message = `Unable to get valid resource name from endpoint ${endpoint}, skip fetching hub settings.`;
      printer.warn(message);
    } else {
      // connect to the control plane
      const client = new WebPubSubManagementClient(getCredential(), subscriptionId);
      try {
        const result = await client.webPubSubHubs.get(hub, resourceGroup, resourceName);
        eventHandlers = result.properties.eventHandlers?.map((s) => s as EventHandlerSetting);
      } catch (err) {
        message = `Failed to fetch hub settings: ${err}`;
        printer.warn(message);
      }
    }
  } else {
    message = `Unable to fetch hub settings: subscriptionId and resourceGroup are not specified. Use '-s <subscriptionId> -g <resourceGroup>' to set or call '${name} bind -s <subscriptionId> -g <resourceGroup>' to bind the values.`;
    printer.warn(message);
  }

  return { message, eventHandlers, subscriptionId, resourceGroup, resourceName, loaded: true };
}