Skip to content

Commit

Permalink
- Use username/password from Url
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Oct 30, 2021
1 parent 54ab07b commit 5f08d02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/OpenDirectoryDownloader/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,22 @@ public static Stream GetEmbeddedResourceStream(Assembly assembly, string resourc

return null;
}

public static bool GetUriCredentials(Uri uri, out string username, out string password)
{
username = null;
password = null;

if (uri.UserInfo?.Contains(':') == true)
{
string[] splitted = uri.UserInfo.Split(':');

username = WebUtility.UrlDecode(splitted.First());
password = WebUtility.UrlDecode(splitted.Last());
return true;
}

return false;
}
}
}
10 changes: 10 additions & 0 deletions src/OpenDirectoryDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ static async Task<int> Main(string[] args)
openDirectoryIndexerSettings.Username = openDirectoryIndexerSettings.CommandLineOptions.Username;
openDirectoryIndexerSettings.Password = openDirectoryIndexerSettings.CommandLineOptions.Password;

if (string.IsNullOrEmpty(openDirectoryIndexerSettings.Username) && string.IsNullOrEmpty(openDirectoryIndexerSettings.Password))
{
if (Library.GetUriCredentials(new Uri(url), out string username, out string password))
{
Console.WriteLine($"Using username '{username}' and password '{password}'");
openDirectoryIndexerSettings.Username = username;
openDirectoryIndexerSettings.Password = password;
}
}

// FTP
if (openDirectoryIndexerSettings.Url?.StartsWith(Constants.UriScheme.Ftp) == true || openDirectoryIndexerSettings.Url?.StartsWith(Constants.UriScheme.Ftps) == true)
{
Expand Down

0 comments on commit 5f08d02

Please sign in to comment.