static async Task <MetabaseApi> InitApi(MetabaseApiSettings apiSettings) { const string filename = "metabase-token.txt"; string GetInitialToken() { try { return(File.ReadAllText(filename)); } catch (Exception e) { return(null); } } // get an existing token if available to work around Metabase throttling // https://github.com/metabase/metabase/issues/4979 var MetabaseInitialToken = GetInitialToken(); var metabaseSession = new MetabaseSessionTokenManager(apiSettings, MetabaseInitialToken); var api = new MetabaseApi(metabaseSession); try { await api.GetAllDashboards(); // attempt an API call to either validate or renew the session token var token = await metabaseSession.CurrentToken(); File.WriteAllText(filename, token); return(api); } catch (Exception e) { throw new Exception("Error initialising Metabase API for " + apiSettings.MetabaseApiUrl, e); } }
public MetabaseApi(MetabaseSessionTokenManager sessionManager) { this.sessionManager = sessionManager; }