/// <inheritdoc /> public string CreateCorpusPath(string adapterPath) { string ghRoot = GithubAdapter.GhRawRoot(); // might not be an adapterPath that we understand. check that first if (!string.IsNullOrEmpty(adapterPath) && adapterPath.StartsWith(ghRoot)) { return(StringUtils.Slice(adapterPath, ghRoot.Length)); } return(null); }
/// <inheritdoc /> public string CreateAdapterPath(string corpusPath) { return($"{GithubAdapter.GhRawRoot()}{corpusPath}"); }
/// <summary> /// Mounts the config JSON to the storage manager/corpus. /// </summary> /// <param name="adapterConfig">The adapters config in JSON.</param> /// <param name="doesReturnErrorList">A boolean value that denotes whether we want to return a list of adapters that were not found.</param> /// <returns>The list of configs for unrecognized adapters.</returns> public List <string> Mount(string adapterConfig, bool doesReturnErrorList = false) { if (string.IsNullOrWhiteSpace(adapterConfig)) { Logger.Error(nameof(StorageManager), this.Ctx, $"Adapter config cannot be null or empty.", "Mount"); return(null); } var adapterConfigJson = JsonConvert.DeserializeObject <JObject>(adapterConfig); if (adapterConfigJson["appId"] != null) { this.Corpus.AppId = adapterConfigJson["appId"].ToString(); } if (adapterConfigJson["defaultNamespace"] != null) { this.DefaultNamespace = adapterConfigJson["defaultNamespace"].ToString(); } var unrecognizedAdapters = new List <string>(); foreach (var item in adapterConfigJson["adapters"]) { string nameSpace; // Check whether the namespace exists. if (item["namespace"] != null) { nameSpace = item["namespace"].ToString(); } else { Logger.Error(nameof(StorageManager), this.Ctx, $"The namespace is missing for one of the adapters in the JSON config."); continue; } JObject configs = null; // Check whether the config exists. if (item["config"] != null) { configs = item["config"] as JObject; } else { Logger.Error(nameof(StorageManager), this.Ctx, $"Missing JSON config for the namespace {nameSpace}."); continue; } if (item["type"] == null) { Logger.Error(nameof(StorageManager), this.Ctx, $"Missing type in the JSON config for the namespace {nameSpace}."); continue; } StorageAdapter adapter = null; switch (item["type"].ToString()) { case LocalAdapter.Type: adapter = new LocalAdapter(); break; case GithubAdapter.Type: adapter = new GithubAdapter(); break; case RemoteAdapter.Type: adapter = new RemoteAdapter(); break; case ADLSAdapter.Type: adapter = new ADLSAdapter(); break; default: unrecognizedAdapters.Add(item.ToString()); break; } if (adapter != null) { adapter.UpdateConfig(configs.ToString()); this.Mount(nameSpace, adapter); } } return(doesReturnErrorList ? unrecognizedAdapters : null); }