forked from splunk/splunk-sdk-csharp-pcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.cs
248 lines (206 loc) · 9.38 KB
/
Application.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* Copyright 2014 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
using System.ComponentModel;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using Splunk.Client.Entities;
using Splunk.Client.Syndication;
using BooleanConverter = Splunk.Client.Converters.BooleanConverter;
[assembly: InternalsVisibleTo("Splunk.Client.UnitTests")]
//// TODO:
//// [O] Contracts
//// [O] Documentation
namespace Splunk.Client
{
/// <summary>
/// Provides a class for managing Splunk applications.
/// </summary>
/// <remarks>
/// <para><b>References:</b></para>
/// <list type="number">
/// <item><description>
/// <a href="http://goo.gl/OsgrYx">Apps and add-ons: an introduction</a>.
/// </description></item>
/// <item><description>
/// <a href="http://goo.gl/1txQUG">Package your app or add-on</a>.
/// </description></item>
/// <item><description>
/// <a href="http://goo.gl/a7HqRp">REST API Reference: Applications</a>.
/// </description></item>
/// </list>
/// </remarks>
/// <seealso cref="T:Splunk.Client.Entity{Splunk.Client.Resource}"/>
/// <seealso cref="T:Splunk.Client.IApplication"/>
public class Application : Entity<Resource>, IApplication
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Application"/> class.
/// </summary>
/// <param name="service">
/// An object representing a root Splunk service endpoint.
/// </param>
/// <param name="name">
/// An object identifying a Splunk resource within
/// <paramref name= "service"/>.<see cref="Namespace"/>.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="service"/> is <c>null</c>.
/// </exception>
protected internal Application(Service service, string name)
: this(service.Context, service.Namespace, name) => Contract.Requires<ArgumentNullException>(service != null);
/// <summary>
/// Initializes a new instance of the <see cref="Application"/> class.
/// </summary>
/// <param name="context">
/// An object representing a Splunk server session.
/// </param>
/// <param name="feed">
/// A Splunk response atom feed.
/// </param>
protected internal Application(Context context, AtomFeed feed) => this.Initialize(context, feed);
/// <summary>
/// Initializes a new instance of the <see cref="Application"/> class.
/// </summary>
/// <param name="context">
/// An object representing a Splunk server session.
/// </param>
/// <param name="ns">
/// An object identifying a Splunk services namespace.
/// </param>
/// <param name="name">
/// The name of the <see cref="Application"/>.
/// </param>
protected internal Application(Context context, Namespace ns, string name)
: base(context, ns, ApplicationCollection.ClassResourceName, name)
{ }
/// <summary>
/// Infrastructure. Initializes a new instance of the
/// <see cref= "Application"/> class.
/// </summary>
/// <remarks>
/// This API supports the Splunk client infrastructure and is not intended to
/// be used directly from your code.
/// </remarks>
public Application()
{ }
#endregion
#region Properties
/// <inheritdoc/>
public virtual string ApplicationAuthor => this.Content.GetValue("Author", StringConverter.Instance);
/// <inheritdoc/>
public virtual string Author => this.GetValue("Author", StringConverter.Instance);
/// <inheritdoc/>
public virtual bool CheckForUpdates => this.Content.GetValue("CheckForUpdates", BooleanConverter.Instance);
/// <inheritdoc/>
public virtual bool Configured => this.Content.GetValue("Configured", BooleanConverter.Instance);
/// <inheritdoc/>
public virtual string Description => this.Content.GetValue("Description", StringConverter.Instance);
/// <inheritdoc/>
public virtual bool Disabled => this.Content.GetValue("Disabled", BooleanConverter.Instance);
/// <inheritdoc/>
public virtual Eai Eai => this.Content.GetValue("Eai", Eai.Converter.Instance);
/// <inheritdoc/>
public virtual string Label => this.Content.GetValue("Label", StringConverter.Instance);
/// <summary>
/// Gets the links.
/// </summary>
/// <value>
/// The links.
/// </value>
/// <seealso cref="P:Splunk.Client.IApplication.Links"/>
public virtual IReadOnlyDictionary<string, Uri> Links => this.Snapshot.GetValue("Links");
/// <inheritdoc/>
public virtual bool Refresh => this.Content.GetValue("Refresh", BooleanConverter.Instance);
/// <inheritdoc/>
public virtual bool StateChangeRequiresRestart => this.Content.GetValue("StateChangeRequiresRestart", BooleanConverter.Instance);
/// <inheritdoc/>
public virtual string Version => this.Content.GetValue("Version", StringConverter.Instance);
/// <inheritdoc/>
public virtual bool Visible => this.Content.GetValue("Visible", BooleanConverter.Instance);
#endregion
#region Methods
/// <inheritdoc/>
public virtual async Task DisableAsync()
{
var resourceName = new ResourceName(this.ResourceName, "disable");
using var response = await this.Context.PostAsync(this.Namespace, resourceName).ConfigureAwait(false);
await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);
}
/// <inheritdoc/>
public virtual async Task EnableAsync()
{
var resourceName = new ResourceName(this.ResourceName, "enable");
using var response = await this.Context.PostAsync(this.Namespace, resourceName).ConfigureAwait(false);
await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);
}
/// <inheritdoc/>
public virtual async Task<ApplicationSetupInfo> GetSetupInfoAsync()
{
var resourceName = new ResourceName(this.ResourceName, "setup");
using var response = await this.Context.GetAsync(this.Namespace, resourceName).ConfigureAwait(false);
await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);
var resource = await BaseResource.CreateAsync<ApplicationSetupInfo>(response).ConfigureAwait(false);
return resource;
}
/// <inheritdoc/>
public virtual async Task<ApplicationUpdateInfo> GetUpdateInfoAsync()
{
var resourceName = new ResourceName(this.ResourceName, "update");
using var response = await this.Context.GetAsync(this.Namespace, resourceName).ConfigureAwait(false);
await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);
var resource = await BaseResource.CreateAsync<ApplicationUpdateInfo>(response).ConfigureAwait(false);
return resource;
}
/// <inheritdoc/>
public virtual async Task<ApplicationArchiveInfo> PackageAsync()
{
var resourceName = new ResourceName(this.ResourceName, "package");
using var response = await this.Context.GetAsync(this.Namespace, resourceName).ConfigureAwait(false);
await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);
var resource = await BaseResource.CreateAsync<ApplicationArchiveInfo>(response).ConfigureAwait(false);
return resource;
}
/// <inheritdoc/>
public virtual async Task<bool> UpdateAsync(ApplicationAttributes attributes, bool checkForUpdates = false)
{
var updateArgs = new UpdateArgs { CheckForUpdates = checkForUpdates };
return await this.UpdateAsync(updateArgs.AsEnumerable().Concat(attributes)).ConfigureAwait(false);
}
#endregion
#region Types
/// <summary>
/// Arguments for update.
/// </summary>
/// <seealso cref="T:Splunk.Client.Args{Splunk.Client.Application.UpdateArgs}"/>
private class UpdateArgs : Args<UpdateArgs>
{
/// <summary>
/// Gets or sets a value that indicates whether Splunk should check
/// Splunkbase for updates to an <see cref="Application"/>.
/// </summary>
/// <value>
/// <c>true</c> if check for updates, <c>false</c> if not.
/// </value>
[DataMember(Name = "check_for_updates", EmitDefaultValue = false)]
[DefaultValue(false)]
public bool CheckForUpdates
{ get; set; }
}
#endregion
}
}