async Task CanConstructConfigurationStanza() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ConfigurationStanza.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedConfigurationSettingNames = new string[] { "_name", "command", "hostname", "inline", "maxresults", "maxtime", "track_alert", "ttl" }; var configurationStanza = new ConfigurationStanza(context, feed); Assert.Equal(expectedConfigurationSettingNames, from setting in configurationStanza select setting.Title); Assert.Equal(expectedConfigurationSettingNames.Length, configurationStanza.Count); for (int i = 0; i < configurationStanza.Count; i++) { Assert.Equal(expectedConfigurationSettingNames[i], configurationStanza[i].Title); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Id; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Links; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Updated; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Value; }); } } }
/// <summary> /// Asynchronously removes a configuration stanza. /// </summary> /// <param name="fileName"> /// Name of a configuration file. /// </param> /// <param name="stanzaName"> /// Name of a configuration stanza in <see cref="fileName"/> to be /// removed. /// </param> /// <remarks> /// This method uses the <a href="http://goo.gl/dpbuhQ">DELETE /// configs/conf-{file}/{name}</a> endpoint to remove the configuration /// identified by <see cref="stanzaName"/>. /// </remarks> public async Task RemoveConfigurationStanzaAsync(string fileName, string stanzaName) { var entity = new ConfigurationStanza(this.Context, this.Namespace, fileName, stanzaName); await entity.RemoveAsync(); }
/// <summary> /// Adds or updates a list of settings in a configuration stanza. /// </summary> /// <param name="fileName"> /// Name of a configuration file. /// </param> /// <param name="stanzaName"> /// Name of a stanza within the configuration file identified by <see /// cref="fileName"/>. /// <param name="settings"> /// A variable-length list of objects representing the settings to be /// added or updated. /// <remarks> /// This method uses the <a href="http://goo.gl/w742jw">POST /// properties/{file_name}/{stanza_name}</a> endpoint to update <see /// cref="settings"/> in the stanza identified by <see cref= /// "fileName"/> and <see cref="stanzaName"/>. /// </remarks> public async Task UpdateConfigurationSettingsAsync(string fileName, string stanzaName, params Argument[] settings) { ConfigurationStanza stanza = new ConfigurationStanza(this.Context, this.Namespace, fileName, stanzaName); await stanza.UpdateAsync(settings); }
/// <summary> /// Asynchronously retrieves a configuration stanza. /// </summary> /// <returns> /// An object representing the configuration stanza. /// </returns> /// <remarks> /// This method uses the <a href="http://goo.gl/sM63fa">GET /// properties/{file_name}/{stanza_name}</a> endpoint/> to construct /// the <see cref="ConfigurationStanza"/> it returns. /// </remarks> public async Task<ConfigurationStanza> GetConfigurationStanzaAsync(string fileName, string stanzaName) { var collection = new ConfigurationStanza(this.Context, this.Namespace, fileName, stanzaName); await collection.GetAsync(); return collection; }
/// <summary> /// Asynchronously creates a new stanza in a configuration file. /// </summary> /// <param name="fileName"> /// Name of a configuration file. /// </param> /// <param name="fileName"> /// Name of the configuration stanza to create. /// </param> /// <remarks> /// This method uses the <a href="http://goo.gl/jae44k">POST /// properties/{file_name></a> endpoint to create the <see cref= /// "ConfigurationStanza"/> identified by <see cref="fileName"/> and /// <see cref="stanzaName"/>. /// </remarks> public async Task<ConfigurationStanza> CreateConfigurationStanzaAsync(string fileName, string stanzaName) { var entity = new ConfigurationStanza(this.Context, this.Namespace, fileName, stanzaName); await entity.CreateAsync(); return entity; }
async Task CanConstructConfigurationStanza() { var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ConfigurationStanza.GetAsync.xml")); using (var context = new Context(Scheme.Https, "localhost", 8089)) { var expectedConfigurationSettingNames = new string[] { "_name", "command", "hostname", "inline", "maxresults", "maxtime", "track_alert", "ttl" }; var configurationStanza = new ConfigurationStanza(context, feed); Assert.Equal(expectedConfigurationSettingNames, from setting in configurationStanza select setting.Title); Assert.Equal(expectedConfigurationSettingNames.Length, configurationStanza.Count); for (int i = 0; i < configurationStanza.Count; i++) { Assert.Equal(expectedConfigurationSettingNames[i], configurationStanza[i].Title); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Id; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Links; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Updated; }); Assert.DoesNotThrow(() => { var value = configurationStanza[i].Value; }); } } }
public void ConfCRUD() { Service service; string app = "sdk-tests"; string owner = "nobody"; // Create a fresh app to use as the container for confs that we will // create in this test. There is no way to delete a conf once it's // created so we make sure to create in the context of this test app // and then we delete the app when we are done to make everything go // away. this.CreateApp(app); service = this.Connect(); var apps = service.GetApplicationsAsync().Result; Assert.True(apps.Any(a => a.ResourceName.Title == app), assertRoot + "#8"); Namespace ns = new Namespace(owner, app); // Create an app specific service instance //Args args = new Args(this.SetUp().Opts); //args.Add("app", app); //args.Add("owner", owner); service = this.Connect(ns); //service = Service.Connect(args); //Context context = new Context(Scheme.Https, this.SetUp().Host, this.SetUp().Port); //service = new Service(context); //service.LoginAsync(this.SetUp().Username, this.SetUp().Password).Wait(); //service = this.Connect(); ConfigurationCollection confs = service.GetConfigurationsAsync().Result; //if below failed, remove the file C:\Program Files\Splunk\etc\system\local\testconf.conf, serverInfo should provide home path etc? Assert.False(confs.Any(a => a.Name == "testconf"), assertRoot + "#9"); Configuration testconf = service.CreateConfigurationAsync("testconf").Result; confs.GetAsync().Wait(); Assert.True(confs.Any(a => a.Name == "testconf"), assertRoot + "#10"); testconf = service.GetConfigurationAsync("testconf").Result; //ConfigurationStanza stanzas = service.GetConfigurationStanzaAsync("testconf", "stanza1").Result; //Assert.Equal(0, stanzas.Count); service.CreateConfigurationStanzaAsync("testconf", "stanza1").Wait(); service.CreateConfigurationStanzaAsync("testconf", "stanza2").Wait(); service.CreateConfigurationStanzaAsync("testconf", "stanza3").Wait(); testconf.GetAsync().Wait(); Assert.Equal(4, testconf.Count); Assert.NotNull(testconf.GetStanzaAsync("stanza1").Result.Name); Assert.NotNull(testconf.GetStanzaAsync("stanza2").Result.Name); Assert.NotNull(testconf.GetStanzaAsync("stanza3").Result.Name); //EntityCollection<Entity> stanzas = confs.Get("testconf"); //// Grab the new stanza and check its content ConfigurationStanza stanza1 = testconf.GetStanzaAsync("stanza1").Result; //Assert.False(stanza1.Any(), "Expected stanza1 to be non-empty"); //Assert.Equal(5, stanza1.Count);//, "Expected stanza1 to have 5 elements"); //Assert.Equal("nobody", stanza1.GetSettingAsync("eai:userName").Result.Name); //Assert.Equal(app, stanza1.GetSettingAsync("eai:appName").Result.Name); //Assert.False(stanza1.ContainsKey("key1"), assertRoot + "#18"); //Assert.False(stanza1.ContainsKey("key2"), assertRoot + "#19"); //Assert.False(stanza1.ContainsKey("key3"), assertRoot + "#20"); // Add a couple of properties Argument args = new Argument("key1", "value1"); Argument args1 = new Argument("key2", "42"); stanza1.UpdateAsync(args, args1).Wait(); stanza1 = testconf.GetStanzaAsync("stanza1").Result; // Make sure the properties showed up ConfigurationSetting x = stanza1.GetSettingAsync("key1").Result; // Assert.Equal("value1", stanza1.GetSettingAsync("key1").Result.Value); Assert.Equal("42", stanza1.GetSettingAsync("key2").Result.Value); //Assert.False(stanza1.ContainsKey("key3"), assertRoot + "#23"); //// Update an existing property args = new Argument("key1", "value2"); stanza1.UpdateAsync(args, args1).Wait(); // Make sure the updated property shows up (and no other changes). Assert.Equal("value2", stanza1.GetSettingAsync("key1").Result.Value); Assert.Equal("42", stanza1.GetSettingAsync("key2").Result.Value); //Assert.False(stanza1.ContainsKey("key3"), assertRoot + "#26"); //Assert.True(stanza1.ContainsValue("value2"), "Expected stanza1 to contain the value value2"); //Assert.True(stanza1.ContainsValue("42"), "Expected stanza1 to contain the value 42"); // Delete the stanzas testconf.RemoveStanzaAsync("stanza3").Wait(); Assert.Equal(3, testconf.Count); //Assert.True(stanzas.ContainsKey("stanza1"), assertRoot + "#28"); //Assert.True(stanzas.ContainsKey("stanza2"), assertRoot + "#29"); //Assert.False(stanzas.ContainsKey("stanza3"), assertRoot + "#30"); //stanzas.Remove("stanza2"); //Assert.Equal(1, stanzas.Size, assertRoot + "#31"); //Assert.True(stanzas.ContainsKey("stanza1"), assertRoot + "#32"); //Assert.False(stanzas.ContainsKey("stanza2"), assertRoot + "#33"); //Assert.False(stanzas.ContainsKey("stanza3"), assertRoot + "#34"); //stanzas.Remove("stanza1"); //Assert.Equal(0, stanzas.Size, assertRoot + "#35"); //Assert.False(stanzas.ContainsKey("stanza1"), assertRoot + "#36"); //Assert.False(stanzas.ContainsKey("stanza2"), assertRoot + "#37"); //Assert.False(stanzas.ContainsKey("stanza3"), assertRoot + "#38"); // Cleanup after ourselves this.RemoveApp(app); }
public async Task Configuration() { const string app = "sdk-tests"; // Provides a removable jail for the configuration changes we'll make using (var service = await SdkHelper.CreateService()) { await service.Applications.RecreateAsync(app); await service.Server.RestartAsync(2 * 60 * 1000); } using (var service = await SdkHelper.CreateService(new Namespace(user: "******", app: app))) { ConfigurationCollection confs = service.Configurations; await confs.GetAllAsync(); //// If this assesrt fails, remove the file C:\Program Files\Splunk\etc\system\local\testconf.conf. Assert.False(confs.Any(a => a.Name == "testconf")); Configuration testconf = await confs.CreateAsync("testconf"); testconf = await confs.GetOrNullAsync("testconf"); Assert.NotNull(testconf); ConfigurationStanza stanza1 = await testconf.CreateAsync("stanza1"); ConfigurationStanza stanza2 = await testconf.CreateAsync("stanza2"); ConfigurationStanza stanza3 = await testconf.CreateAsync("stanza3"); await testconf.GetAllAsync(); Assert.Equal(4, testconf.Count); Assert.NotNull(testconf.SingleOrDefault(conf => conf.Name == "default")); Assert.NotNull(testconf.SingleOrDefault(conf => conf.Name == stanza1.Name)); Assert.NotNull(testconf.SingleOrDefault(conf => conf.Name == stanza2.Name)); Assert.NotNull(testconf.SingleOrDefault(conf => conf.Name == stanza3.Name)); //// Grab one of the new stanzas and check its content stanza1 = await testconf.GetAsync("stanza1"); // Add a couple of properties await stanza1.UpdateAsync( new Argument("key1", "string"), new Argument("key2", (byte)2), new Argument("key3", 'c'), new Argument("key4", 4.00M), new Argument("key5", 5.0), new Argument("key6", 6.0F), new Argument("key7", 7), new Argument("key8", 8L), new Argument("key9", stanza1), new Argument("key10", (sbyte)10), new Argument("key11", (uint)11), new Argument("key12", (ulong)12)); stanza1 = await testconf.GetAsync("stanza1"); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key1" && setting.Value == "string")); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key2" && setting.Value == ((byte)2).ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key3" && setting.Value == 'c'.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key4" && setting.Value == 4.00M.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key5" && setting.Value == 5.0.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key6" && setting.Value == 6.0F.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key7" && setting.Value == 7.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key8" && setting.Value == 8L.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key9" && setting.Value == stanza1.ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key10" && setting.Value == ((sbyte)10).ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key11" && setting.Value == ((uint)11).ToString())); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key12" && setting.Value == ((ulong)12).ToString())); string value; value = await stanza1.GetAsync("key1"); Assert.Equal("string", value); value = await stanza1.GetAsync("key2"); Assert.Equal(((byte)2).ToString(), value); value = await stanza1.GetAsync("key3"); Assert.Equal('c'.ToString(), value); value = await stanza1.GetAsync("key4"); Assert.Equal(4.00M.ToString(), value); value = await stanza1.GetAsync("key5"); Assert.Equal(5.0.ToString(), value); value = await stanza1.GetAsync("key6"); Assert.Equal(6.0F.ToString(), value); value = await stanza1.GetAsync("key7"); Assert.Equal(7.ToString(), value); value = await stanza1.GetAsync("key8"); Assert.Equal(8L.ToString(), value); value = await stanza1.GetAsync("key9"); Assert.Equal(stanza1.ToString(), value); value = await stanza1.GetAsync("key10"); Assert.Equal(((sbyte)10).ToString(), value); value = await stanza1.GetAsync("key11"); Assert.Equal(((uint)11).ToString(), value); value = await stanza1.GetAsync("key12"); Assert.Equal(((ulong)12).ToString(), value); //// Update an existing setting bool updatedSnapshot = await stanza1.UpdateAsync(new Argument("key1", "value2")); Assert.False(updatedSnapshot); await stanza1.GetAsync(); Assert.NotNull(stanza1.SingleOrDefault(setting => setting.Title == "key1" && setting.Value == "value2")); value = await stanza1.GetAsync("key1"); Assert.Equal("value2", value); value = await stanza1.GetAsync("key1"); Assert.Equal("value2", value); //// Remove the stanzas // Stanza 1 await stanza1.RemoveAsync(); await testconf.GetAllAsync(); // because remove gives no data back Assert.Equal(3, testconf.Count); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "default")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza1")); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "stanza2")); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "stanza3")); // Stanza 2 await stanza2.RemoveAsync(); await testconf.GetAllAsync(); // because remove gives no data back Assert.Equal(2, testconf.Count); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "default")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza1")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza2")); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "stanza3")); // Stanza 3 await stanza3.RemoveAsync(); await testconf.GetAllAsync(); // because remove gives no data back Assert.Equal(1, testconf.Count); Assert.NotNull(testconf.SingleOrDefault(stanza => stanza.Name == "default")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza1")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza2")); Assert.Null(testconf.SingleOrDefault(stanza => stanza.Name == "stanza3")); } using (var service = await SdkHelper.CreateService()) { Assert.True(await service.Applications.RemoveAsync(app)); await service.Server.RestartAsync(2 * 60 * 1000); } }