-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetItemPropertiesAction.cs
76 lines (66 loc) · 2.26 KB
/
SetItemPropertiesAction.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using Inedo.BuildMaster;
using Inedo.BuildMaster.Extensibility.Actions;
using Inedo.BuildMaster.Web;
namespace Inedo.BuildMasterExtensions.Artifactory
{
[ActionProperties(
"Set Item Properties",
"Recursively sets properties on items in the specified location.")]
[Tag("Artifactory")]
[CustomEditor(typeof(SetItemPropertiesActionEditor))]
public class SetItemPropertiesAction : ArtifactoryActionBase
{
[Persistent]
public string ItemName {get;set;}
[Persistent]
public string Properties { get; set; }
public override string ToString()
{
return string.Format("Set properties for {0} in repository {1}", this.ItemName, this.RepositoryKey);
}
public SetItemPropertiesAction()
{
this.UsesRepositoryKey = true;
}
internal string Test()
{
return ProcessRemoteCommand(null, null);
}
protected override void Execute()
{
this.ExecuteRemoteCommand(null);
}
protected override string ProcessRemoteCommand(string name, string[] args)
{
return MakeRequest();
}
internal string MakeRequest()
{
StringBuilder url = new StringBuilder();
url.Append(this.Server.EndsWith("/") ? this.Server : this.Server + "/" +
"api/storage/{0}/{1}");
if(!string.IsNullOrEmpty(this.Properties))
{
url.Append("?properties=");
foreach(var p in this.Properties.ParseNameValue())
{
url.AppendFormat("{0}={1}|",p.Key, p.Value);
}
url.Remove(url.Length - 1, 1);
}
var resp = Request(RequestType.Put,null,url.ToString(),this.RepositoryKey, this.ItemName);
if (HttpStatusCode.NoContent != resp.StatusCode)
{
LogError("Error setting properties for {0} in repository {1}. Error code is {2}", this.ItemName, this.RepositoryKey, resp.StatusCode);
return null;
}
return "OK";
}
}
}