2015-01-20 21:44:52 +01:00
// Copyright (C) 2015, The Duplicati Team
2014-07-15 15:42:15 +02:00
2015-01-20 21:44:52 +01:00
// http://www.duplicati.com, info@duplicati.com
2014-07-15 15:42:15 +02:00
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System ;
using System.Collections.Generic ;
using System.Linq ;
using Duplicati.Library.Interface ;
namespace Duplicati.Library.Backend
{
public class S3Config : IWebModule
{
private const ConfigType DEFAULT_CONFIG_TYPE = ConfigType . Providers ;
private static readonly string DEFAULT_CONFIG_TYPE_STR = Enum . GetName ( typeof ( ConfigType ), DEFAULT_CONFIG_TYPE );
private const string KEY_CONFIGTYPE = "s3-config" ;
public enum ConfigType
{
Providers ,
Regions ,
2015-11-18 20:38:27 +01:00
RegionHosts ,
StorageClasses
2014-07-15 15:42:15 +02:00
}
public S3Config ()
{
}
#region IWebModule implementation
public IDictionary < string , string > Execute ( IDictionary < string , string > options )
{
string k ;
options . TryGetValue ( KEY_CONFIGTYPE , out k );
if ( string . IsNullOrWhiteSpace ( k ))
k = DEFAULT_CONFIG_TYPE_STR ;
ConfigType ct ;
if (! Enum . TryParse < ConfigType >( k , true , out ct ))
ct = DEFAULT_CONFIG_TYPE ;
switch ( ct )
{
case ConfigType . RegionHosts :
2019-09-17 11:16:09 +02:00
return S3 . DEFAULT_S3_LOCATION_BASED_HOSTS ;
2014-07-15 15:42:15 +02:00
case ConfigType . Regions :
2019-09-17 11:16:09 +02:00
return S3 . KNOWN_S3_LOCATIONS ;
2015-11-18 20:38:27 +01:00
case ConfigType . StorageClasses :
2019-09-17 11:16:09 +02:00
return S3 . KNOWN_S3_STORAGE_CLASSES ;
2014-07-15 15:42:15 +02:00
default :
2019-09-17 11:16:09 +02:00
return S3 . KNOWN_S3_PROVIDERS ;
2014-07-15 15:42:15 +02:00
}
}
public string Key { get { return "s3-getconfig" ; } }
public string DisplayName { get { return "S3 configuration module" ; } }
public string Description { get { return "Exposes S3 configuration as a web module" ; } }
public IList < ICommandLineArgument > SupportedCommands
{
get
{
return new List < ICommandLineArgument >( new ICommandLineArgument [] {
new CommandLineArgument ( KEY_CONFIGTYPE , CommandLineArgument . ArgumentType . Enumeration , "The config to get" , "Provides different config values" , DEFAULT_CONFIG_TYPE_STR , Enum . GetNames ( typeof ( ConfigType )))
});
}
}
#endregion
}
}