diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2015-07-01 17:46:09 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2015-07-01 17:46:09 +0300 |
commit | d3f3615abdba7f2d55590e1724e384e280ff3b04 (patch) | |
tree | 8afa05c01b830c998717c935d495eb5af94cac6a /Duplicati/Library/Backend | |
parent | 55818d407cae5646d740f431b63b8bb79d40c524 (diff) |
Added support for HubiC.
This closes #1351.
Diffstat (limited to 'Duplicati/Library/Backend')
4 files changed, 154 insertions, 0 deletions
diff --git a/Duplicati/Library/Backend/HubiC/Duplicati.Library.Backend.HubiC.csproj b/Duplicati/Library/Backend/HubiC/Duplicati.Library.Backend.HubiC.csproj new file mode 100644 index 000000000..9de54bb16 --- /dev/null +++ b/Duplicati/Library/Backend/HubiC/Duplicati.Library.Backend.HubiC.csproj @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.30703</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{D60AD540-0E7D-40CE-83AE-D26E01FFE9B8}</ProjectGuid> + <OutputType>Library</OutputType> + <RootNamespace>Duplicati.Library.Backend.HubiC</RootNamespace> + <AssemblyName>Duplicati.Library.Backend.HubiC</AssemblyName> + <SignAssembly>true</SignAssembly> + <AssemblyOriginatorKeyFile>Duplicati.snk</AssemblyOriginatorKeyFile> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>full</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="HubiCBackend.cs" /> + <Compile Include="Strings.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <ProjectReference Include="..\..\Interface\Duplicati.Library.Interface.csproj"> + <Project>{C5899F45-B0FF-483C-9D38-24A9FCAAB237}</Project> + <Name>Duplicati.Library.Interface</Name> + </ProjectReference> + <ProjectReference Include="..\OAuthHelper\Duplicati.Library.OAuthHelper.csproj"> + <Project>{D4C37C33-5E73-4B56-B2C3-DC4A6BAA36BB}</Project> + <Name>Duplicati.Library.OAuthHelper</Name> + </ProjectReference> + <ProjectReference Include="..\OpenStack\Duplicati.Library.Backend.OpenStack.csproj"> + <Project>{D9E4E686-423C-48EC-A392-404E7C00860C}</Project> + <Name>Duplicati.Library.Backend.OpenStack</Name> + </ProjectReference> + <ProjectReference Include="..\..\Localization\Duplicati.Library.Localization.csproj"> + <Project>{B68F2214-951F-4F78-8488-66E1ED3F50BF}</Project> + <Name>Duplicati.Library.Localization</Name> + </ProjectReference> + <ProjectReference Include="..\..\Utility\Duplicati.Library.Utility.csproj"> + <Project>{DE3E5D4C-51AB-4E5E-BEE8-E636CEBFBA65}</Project> + <Name>Duplicati.Library.Utility</Name> + </ProjectReference> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/Duplicati/Library/Backend/HubiC/HubiCBackend.cs b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs new file mode 100644 index 000000000..36fcabc27 --- /dev/null +++ b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs @@ -0,0 +1,26 @@ +// Copyright (C) 2015, The Duplicati Team
+// http://www.duplicati.com, info@duplicati.com
+//
+// 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 Duplicati.Library.Interface;
using Duplicati.Library;
using Duplicati.Library.Backend.OpenStack;
using System.Collections.Generic;
+
+namespace Duplicati.Library.Backend.HubiC
+{
+ public class HubiCBackend : IBackend, IStreamingBackend
+ {
private const string AUTHID_OPTION = "authid";
private const string HUBIC_API_URL = "https://api.hubic.com/1.0/";
private const string HUBIC_API_CREDENTIAL_URL = HUBIC_API_URL + "account/credentials";
private OpenStackStorage m_openstack;
private class HubiCAuthResponse
{
public string token { get; set; }
public string endpoint { get; set; }
public DateTime? expires { get; set;}
}
private class OpenStackHelper : OpenStackStorage
{
private OAuthHelper m_helper;
private HubiCAuthResponse m_token;
public OpenStackHelper(string authid, string url)
: base(url, MockOptions())
{
m_helper = new OAuthHelper(authid, "hubic") { AutoAuthHeader = true };
}
private static Dictionary<string, string> MockOptions()
{
var res = new Dictionary<string, string>();
res["openstack-authuri"] = "invalid://dont-use";
res["openstack-apikey"] = "invalid";
res["auth-username"] = "invalid";
return res;
}
private HubiCAuthResponse AuthToken
{
get
{
if (m_token == null || (m_token.expires != null && (m_token.expires.Value - DateTime.UtcNow).TotalSeconds < 30))
m_token = m_helper.ReadJSONResponse<HubiCAuthResponse>(HUBIC_API_CREDENTIAL_URL);
return m_token;
}
}
protected override string AccessToken
{
get { return AuthToken.token; }
}
protected override string SimpleStorageEndPoint
{
get { return AuthToken.endpoint; }
}
}
public HubiCBackend()
+ {
}
+
public HubiCBackend(string url, Dictionary<string, string> options)
{
string authid = null;
if (options.ContainsKey(AUTHID_OPTION))
authid = options[AUTHID_OPTION];
m_openstack = new OpenStackHelper(authid, url);
}
#region IStreamingBackend implementation
public void Put(string remotename, System.IO.Stream stream)
{
m_openstack.Put(remotename, stream);
}
public void Get(string remotename, System.IO.Stream stream)
{
m_openstack.Get(remotename, stream);
}
#endregion
#region IBackend implementation
public List<IFileEntry> List()
{
return m_openstack.List();
}
public void Put(string remotename, string filename)
{
m_openstack.Put(remotename, filename);
}
public void Get(string remotename, string filename)
{
m_openstack.Get(remotename, filename);
}
public void Delete(string remotename)
{
m_openstack.Delete(remotename);
}
public void Test()
{
m_openstack.Test();
}
public void CreateFolder()
{
m_openstack.CreateFolder();
}
public string DisplayName
{
get
{
return Strings.HubiC.DisplayName;
}
}
public string ProtocolKey
{
get
{
return "hubic";
}
}
public System.Collections.Generic.IList<ICommandLineArgument> SupportedCommands
{
get {
return new List<ICommandLineArgument>(new ICommandLineArgument[] {
new CommandLineArgument(AUTHID_OPTION, CommandLineArgument.ArgumentType.Password, Strings.HubiC.AuthidShort, Strings.HubiC.AuthidLong(OAuthHelper.OAUTH_LOGIN_URL("hubic"))),
});
}
}
public string Description
{
get
{
return Strings.HubiC.Description;
}
}
#endregion
#region IDisposable implementation
public void Dispose()
{
if (m_openstack != null)
{
m_openstack.Dispose();
m_openstack = null;
}
}
#endregion
}
+}
+
diff --git a/Duplicati/Library/Backend/HubiC/Properties/AssemblyInfo.cs b/Duplicati/Library/Backend/HubiC/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5a3721064 --- /dev/null +++ b/Duplicati/Library/Backend/HubiC/Properties/AssemblyInfo.cs @@ -0,0 +1,43 @@ +// Copyright (C) 2015, The Duplicati Team
+// http://www.duplicati.com, info@duplicati.com
+//
+// 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.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("Duplicati.Library.Backend.HubiC")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("kenneth")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/Duplicati/Library/Backend/HubiC/Strings.cs b/Duplicati/Library/Backend/HubiC/Strings.cs new file mode 100644 index 000000000..ce5cb5b1f --- /dev/null +++ b/Duplicati/Library/Backend/HubiC/Strings.cs @@ -0,0 +1,20 @@ +// Copyright (C) 2015, The Duplicati Team
+// http://www.duplicati.com, info@duplicati.com
+//
+// 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 Duplicati.Library.Localization.Short;
+namespace Duplicati.Library.Backend.Strings
+{
+ internal static class HubiC {
public static string Description { get { return LC.L(@"This backend can read and write data to HubiC. Supported format is ""hubic://container/folder""."); } }
public static string DisplayName { get { return LC.L(@"HubiC"); } }
public static string MissingAuthID(string url) { return LC.L(@"You need an AuthID, you can get it from: {0}"); }
public static string AuthidShort { get { return LC.L(@"The authorization code"); } }
public static string AuthidLong(string url) { return LC.L(@"The authorization token retrieved from {0}", url); }
}
}
+
|