2015-10-06 19:14:35 -04:00
|
|
|
// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-10-06 19:14:35 -04:00
|
|
|
using System.Collections.Generic;
|
2015-10-06 19:14:35 -04:00
|
|
|
using System.Text;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace NuGet.Test.TestExtensions.TestablePluginCredentialProvider
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
static int Main(string[] args)
|
2015-10-06 19:14:35 -04:00
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
Console.OutputEncoding = Encoding.UTF8;
|
|
|
|
|
|
|
|
|
|
if (!VerifyInput(args))
|
|
|
|
|
{
|
|
|
|
|
//We were not passed the correct input arguments so exit with an error.
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-10-06 19:14:35 -04:00
|
|
|
|
|
|
|
|
var responseDelaySeconds = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponseDelaySeconds);
|
|
|
|
|
var responseShouldThrow = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponseShouldThrow);
|
2015-10-06 19:14:35 -04:00
|
|
|
var responseAbortMessage = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponseMessage);
|
2015-10-06 19:14:35 -04:00
|
|
|
var responseExitCode = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponseExitCode);
|
|
|
|
|
var responseUsername = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponseUserName);
|
|
|
|
|
var responsePassword = Environment.GetEnvironmentVariable(TestCredentialResponse.ResponsePassword);
|
|
|
|
|
|
2015-10-06 19:14:35 -04:00
|
|
|
System.Threading.Thread.Sleep(ToInt(responseDelaySeconds) * 1000);
|
2015-10-06 19:14:35 -04:00
|
|
|
|
|
|
|
|
if (ToBool(responseShouldThrow))
|
|
|
|
|
{
|
|
|
|
|
throw new ApplicationException("Throwing test exception");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dynamic response = new TestCredentialResponse
|
|
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
Message = responseAbortMessage,
|
2015-10-06 19:14:35 -04:00
|
|
|
Password = responsePassword,
|
|
|
|
|
Username = responseUsername
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(JsonConvert.SerializeObject(response));
|
|
|
|
|
|
|
|
|
|
return ToInt(responseExitCode);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 19:14:35 -04:00
|
|
|
private static bool VerifyInput(IReadOnlyList<string> args)
|
2015-10-06 19:14:35 -04:00
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
var isValid = true;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < args.Count && isValid; i++)
|
2015-10-06 19:14:35 -04:00
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
var flag = args[i];
|
|
|
|
|
switch (flag.ToLower())
|
2015-10-06 19:14:35 -04:00
|
|
|
{
|
2015-10-06 19:14:35 -04:00
|
|
|
case "-uri":
|
|
|
|
|
if (i + 1 == args.Count)
|
|
|
|
|
{
|
|
|
|
|
// We have a case were we can't grab 2 items so we either have a flag
|
|
|
|
|
// without a value or a space in the value either way call this an error
|
|
|
|
|
isValid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
var value = args[++i];
|
2015-11-12 17:14:51 -05:00
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
2015-10-06 19:14:35 -04:00
|
|
|
{
|
|
|
|
|
isValid = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "-isretry":
|
|
|
|
|
break;
|
|
|
|
|
case "-noninteractive":
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
isValid = false;
|
|
|
|
|
break;
|
2015-10-06 19:14:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-06 19:14:35 -04:00
|
|
|
return isValid;
|
2015-10-06 19:14:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool ToBool(string s)
|
|
|
|
|
{
|
|
|
|
|
bool b;
|
|
|
|
|
bool.TryParse(s, out b);
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int ToInt(string s)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int.TryParse(s, out i);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|