Skip to content

Commit

Permalink
Implemented proxy support via $(proxycfg). Issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Jul 22, 2018
1 parent 7bebfe4 commit 23e6489
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ ngserver | NuGet server.
ngpackages | List of packages. Use it first if defined, otherwise find via ngconfig | v1.0+ *empty*
ngpath | Common path for all packages. | v1.0+ `packages`
wpath |`v1.4+` To define working directory. | v1.4+ *The absolute path of the directory where the GetNuTool is located.*
proxycfg | `v1.6.2+` To configure connection via proxy. | v1.6.2+ *empty*. Format: [usr[:pwd]@]host[:port]

Samples:

```bash
> msbuild gnt.core /p:ngpath="special-packages/new"
msbuild gnt.core /p:ngpath="special-packages/new"
```
```bash
> msbuild gnt.core /p:ngconfig=".nuget/packages.config" /p:ngpath="../packages"
msbuild gnt.core /p:ngconfig=".nuget/packages.config" /p:ngpath="../packages"
```
```bash
gnt /p:ngpackages="Conari" /p:proxycfg="guest:1234@10.0.2.15:7428"
```

#### Format of packages list
Expand Down
30 changes: 26 additions & 4 deletions logic.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PrepareList config="$(ngconfig)" plist="$(ngpackages)" wpath="$(wpath)">
<Output PropertyName="plist" TaskParameter="Result" />
</PrepareList>
<NGDownload plist="$(plist)" url="$(ngserver)" wpath="$(wpath)" defpath="$(ngpath)" debug="$(debug)" />
<NGDownload plist="$(plist)" url="$(ngserver)" wpath="$(wpath)" defpath="$(ngpath)" proxy="$(proxycfg)" debug="$(debug)" />
</Target>
<Target Name="pack" DependsOnTargets="header">
<NGPack dir="$(ngin)" dout="$(ngout)" wpath="$(wpath)" vtool="$(GetNuTool)" debug="$(debug)" />
Expand Down Expand Up @@ -121,6 +121,7 @@
<url ParameterType="System.String" Required="true" />
<wpath ParameterType="System.String" />
<defpath ParameterType="System.String" />
<proxy ParameterType="System.String" />
<debug ParameterType="System.Boolean" />
</ParameterGroup>

Expand All @@ -145,7 +146,23 @@
Console.WriteLine(s, p);
}
};
Func<string, WebProxy> getProxy = delegate(string cfg)
{
var auth = cfg.Split('@');
if(auth.Length <= 1) {
return new WebProxy(auth[0], false);
}
var login = auth[0].Split(':');
return new WebProxy(auth[1], false) {
Credentials = new NetworkCredential(
login[0],
(login.Length > 1) ? login[1] : null
)
};
};
Func<string, string> loc = delegate(string p) {
return Path.Combine(wpath, p ?? "");
};
Expand All @@ -160,8 +177,13 @@
Console.Write("Getting `{0}` ... ", link);
var tmp = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
using(var l = new WebClient()) {
try {
using(var l = new WebClient())
{
try
{
if(proxy != null) {
l.Proxy = getProxy(proxy);
}
l.Headers.Add("User-Agent", "GetNuTool");
l.UseDefaultCredentials = true;
l.DownloadFile(url + link, tmp);
Expand Down

0 comments on commit 23e6489

Please sign in to comment.