Skip to content

Commit 286b1d6

Browse files
committed
v1.0.4, serializer fix for Cyberduck (S3 Java SDK) compatibility
1 parent 7ae8d6b commit 286b1d6

18 files changed

+187
-26
lines changed

Less3/Api/S3/BucketHandler.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public S3Response Read(S3Request req)
299299
resp.Contents.Add(c);
300300
}
301301

302-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(resp)));
302+
return new S3Response(req, 200, "application/xml", null,
303+
Encoding.UTF8.GetBytes(Common.SerializeXml<ListBucketResult>(resp, false)));
303304
}
304305

305306
/// <summary>
@@ -311,7 +312,8 @@ public S3Response ReadLocation(S3Request req)
311312
{
312313
LocationConstraint resp = new LocationConstraint();
313314
resp.Text = _Settings.Server.RegionString;
314-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(resp)));
315+
return new S3Response(req, 200, "application/xml", null,
316+
Encoding.UTF8.GetBytes(Common.SerializeXml<LocationConstraint>(resp, false)));
315317
}
316318

317319
/// <summary>
@@ -490,7 +492,8 @@ public S3Response ReadAcl(S3Request req)
490492
}
491493
}
492494

493-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(ret)));
495+
return new S3Response(req, 200, "application/xml", null,
496+
Encoding.UTF8.GetBytes(Common.SerializeXml<AccessControlPolicy>(ret, false)));
494497
}
495498

496499
/// <summary>
@@ -546,7 +549,8 @@ public S3Response ReadTags(S3Request req)
546549
}
547550
}
548551

549-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(tags)));
552+
return new S3Response(req, 200, "application/xml", null,
553+
Encoding.UTF8.GetBytes(Common.SerializeXml<Tagging>(tags, false)));
550554
}
551555

552556
/// <summary>
@@ -655,7 +659,8 @@ public S3Response ReadVersions(S3Request req)
655659
}
656660
}
657661

658-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(resp)));
662+
return new S3Response(req, 200, "application/xml", null,
663+
Encoding.UTF8.GetBytes(Common.SerializeXml<ListVersionsResult>(resp, false)));
659664
}
660665

661666
/// <summary>
@@ -704,11 +709,13 @@ public S3Response ReadVersioning(S3Request req)
704709
{
705710
ret.Status = "Enabled";
706711
ret.MfaDelete = "Disabled";
707-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(ret)));
712+
return new S3Response(req, 200, "application/xml", null,
713+
Encoding.UTF8.GetBytes(Common.SerializeXml<VersioningConfiguration>(ret, false)));
708714
}
709715
else
710716
{
711-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(ret)));
717+
return new S3Response(req, 200, "application/xml", null,
718+
Encoding.UTF8.GetBytes(Common.SerializeXml<VersioningConfiguration>(ret, false)));
712719
}
713720
}
714721

Less3/Api/S3/ObjectHandler.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ public S3Response DeleteMultiple(S3Request req)
231231
}
232232
}
233233
}
234-
235-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(resp)));
234+
235+
return new S3Response(req, 200, "application/xml", null,
236+
Encoding.UTF8.GetBytes(Common.SerializeXml<DeleteResult>(resp, false)));
236237
}
237238

238239
/// <summary>
@@ -615,7 +616,8 @@ public S3Response ReadAcl(S3Request req)
615616
}
616617
}
617618

618-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(ret)));
619+
return new S3Response(req, 200, "application/xml", null,
620+
Encoding.UTF8.GetBytes(Common.SerializeXml<AccessControlPolicy>(ret, false)));
619621
}
620622

621623
/// <summary>
@@ -778,7 +780,8 @@ public S3Response ReadTags(S3Request req)
778780
tags.TagSet.Add(currTag);
779781
}
780782
}
781-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(tags)));
783+
return new S3Response(req, 200, "application/xml", null,
784+
Encoding.UTF8.GetBytes(Common.SerializeXml<Tagging>(tags, false)));
782785
}
783786

784787
/// <summary>

Less3/Api/S3/ServiceHandler.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public S3Response ListBuckets(S3Request req)
114114
resp.Buckets.Bucket.Add(b);
115115
}
116116

117-
return new S3Response(req, 200, "application/xml", null, Encoding.UTF8.GetBytes(Common.SerializeXml(resp)));
117+
return new S3Response(req, 200, "application/xml", null,
118+
Encoding.UTF8.GetBytes(Common.SerializeXml<ListAllMyBucketsResult>(resp, false)));
118119
}
119120

120121
#endregion

Less3/Common.cs

+47-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text;
1212
using System.Threading;
1313
using System.Threading.Tasks;
14+
using System.Xml;
1415
using System.Xml.Serialization;
1516
using Newtonsoft.Json;
1617
using Newtonsoft.Json.Linq;
@@ -1023,10 +1024,11 @@ public static T DeserializeXml<T>(string xml)
10231024
}
10241025
}
10251026

1026-
public static string SerializeXml(object obj)
1027+
public static string SerializeXml<T>(object obj, bool pretty)
10271028
{
10281029
if (obj == null) throw new ArgumentNullException(nameof(obj));
10291030

1031+
/*
10301032
XmlSerializer xml = new XmlSerializer(obj.GetType());
10311033
10321034
using (MemoryStream stream = new MemoryStream())
@@ -1047,6 +1049,50 @@ public static string SerializeXml(object obj)
10471049
return ret;
10481050
}
10491051
}
1052+
*/
1053+
1054+
XmlSerializer xmls = new XmlSerializer(typeof(T));
1055+
using (MemoryStream ms = new MemoryStream())
1056+
{
1057+
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
1058+
XmlWriterSettings settings = new XmlWriterSettings();
1059+
1060+
if (pretty)
1061+
{
1062+
settings.Encoding = Encoding.UTF8;
1063+
settings.Indent = true;
1064+
settings.NewLineChars = "\n";
1065+
settings.NewLineHandling = NewLineHandling.None;
1066+
settings.NewLineOnAttributes = false;
1067+
settings.ConformanceLevel = ConformanceLevel.Document;
1068+
// settings.OmitXmlDeclaration = true;
1069+
}
1070+
else
1071+
{
1072+
settings.Encoding = Encoding.UTF8;
1073+
settings.Indent = false;
1074+
settings.NewLineHandling = NewLineHandling.None;
1075+
settings.NewLineOnAttributes = false;
1076+
settings.ConformanceLevel = ConformanceLevel.Document;
1077+
// settings.OmitXmlDeclaration = true;
1078+
}
1079+
1080+
using (XmlWriter writer = XmlTextWriter.Create(ms, settings))
1081+
{
1082+
xmls.Serialize(writer, obj, ns);
1083+
}
1084+
1085+
string xml = Encoding.UTF8.GetString(ms.ToArray());
1086+
1087+
// remove preamble if exists
1088+
string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
1089+
while (xml.StartsWith(byteOrderMarkUtf8, StringComparison.Ordinal))
1090+
{
1091+
xml = xml.Remove(0, byteOrderMarkUtf8.Length);
1092+
}
1093+
1094+
return xml;
1095+
}
10501096
}
10511097

10521098
#endregion

Less3/Less3.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<RepositoryUrl>https://github.com/jchristn/less3</RepositoryUrl>
1616
<RepositoryType>Github</RepositoryType>
1717
<PackageTags>S3 storage blob object storage rest restful</PackageTags>
18-
<PackageReleaseNotes>Added bucket GET location API.</PackageReleaseNotes>
18+
<PackageReleaseNotes>Fix serializer for Cyberduck compatibility</PackageReleaseNotes>
1919
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
20-
<Version>1.0.3</Version>
20+
<Version>1.0.4</Version>
2121
</PropertyGroup>
2222

2323
<ItemGroup>

Less3/bin/Debug/netcoreapp2.2/Less3.deps.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"compilationOptions": {},
77
"targets": {
88
".NETCoreApp,Version=v2.2": {
9-
"Less3/1.0.3": {
9+
"Less3/1.0.4": {
1010
"dependencies": {
1111
"AWSSDK.S3": "3.3.104.17",
1212
"Newtonsoft.Json": "12.0.2",
@@ -167,7 +167,7 @@
167167
}
168168
},
169169
"libraries": {
170-
"Less3/1.0.3": {
170+
"Less3/1.0.4": {
171171
"type": "project",
172172
"serviceable": false,
173173
"sha512": ""
512 Bytes
Binary file not shown.

Less3/bin/Release/netcoreapp2.2/Less3.deps.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"compilationOptions": {},
77
"targets": {
88
".NETCoreApp,Version=v2.2": {
9-
"Less3/1.0.2": {
9+
"Less3/1.0.4": {
1010
"dependencies": {
1111
"AWSSDK.S3": "3.3.104.17",
1212
"Newtonsoft.Json": "12.0.2",
@@ -167,7 +167,7 @@
167167
}
168168
},
169169
"libraries": {
170-
"Less3/1.0.2": {
170+
"Less3/1.0.4": {
171171
"type": "project",
172172
"serviceable": false,
173173
"sha512": ""
512 Bytes
Binary file not shown.

Less3/obj/Debug/Less3.1.0.4.nuspec

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>Less3</id>
5+
<version>1.0.4</version>
6+
<authors>Joel Christner</authors>
7+
<owners>Joel Christner</owners>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<licenseUrl>https://github.com/jchristn/less3/blob/master/LICENSE.txt</licenseUrl>
10+
<projectUrl>https://github.com/jchristn/less3</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/jchristn/less3/master/assets/icon.ico</iconUrl>
12+
<description>&lt;3 Less3 is S3-compatible object storage that you can run on your laptop, server, or anywhere you like.</description>
13+
<releaseNotes>Fix serializer for Cyberduck compatibility</releaseNotes>
14+
<copyright>(c)2019 Joel Christner</copyright>
15+
<tags>S3 storage blob object storage rest restful</tags>
16+
<repository type="Github" url="https://github.com/jchristn/less3" />
17+
<dependencies>
18+
<group targetFramework=".NETCoreApp2.2">
19+
<dependency id="AWSSDK.S3" version="3.3.104.17" exclude="Build,Analyzers" />
20+
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
21+
<dependency id="S3ServerInterface" version="1.5.1.6" exclude="Build,Analyzers" />
22+
<dependency id="SqliteHelper" version="1.0.13" exclude="Build,Analyzers" />
23+
<dependency id="SyslogLogging" version="1.2.0" exclude="Build,Analyzers" />
24+
<dependency id="Watson" version="2.1.6" exclude="Build,Analyzers" />
25+
<dependency id="XmlToPox" version="1.0.2" exclude="Build,Analyzers" />
26+
</group>
27+
</dependencies>
28+
</metadata>
29+
<files>
30+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Debug\netcoreapp2.2\Less3.runtimeconfig.json" target="lib\netcoreapp2.2\Less3.runtimeconfig.json" />
31+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Debug\netcoreapp2.2\Less3.dll" target="lib\netcoreapp2.2\Less3.dll" />
32+
</files>
33+
</package>

Less3/obj/Debug/netcoreapp2.2/Less3.AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
[assembly: System.Reflection.AssemblyCopyrightAttribute("(c)2019 Joel Christner")]
1717
[assembly: System.Reflection.AssemblyDescriptionAttribute("<3 Less3 is S3-compatible object storage that you can run on your laptop, server," +
1818
" or anywhere you like.")]
19-
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.3.0")]
20-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.3")]
19+
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.4.0")]
20+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.4")]
2121
[assembly: System.Reflection.AssemblyProductAttribute("Less3")]
2222
[assembly: System.Reflection.AssemblyTitleAttribute("Less3")]
23-
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.3.0")]
23+
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.4.0")]
2424

2525
// Generated by the MSBuild WriteCodeFragment class.
2626

512 Bytes
Binary file not shown.

Less3/obj/Release/Less3.1.0.3.nuspec

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>Less3</id>
5+
<version>1.0.3</version>
6+
<authors>Joel Christner</authors>
7+
<owners>Joel Christner</owners>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<licenseUrl>https://github.com/jchristn/less3/blob/master/LICENSE.txt</licenseUrl>
10+
<projectUrl>https://github.com/jchristn/less3</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/jchristn/less3/master/assets/icon.ico</iconUrl>
12+
<description>&lt;3 Less3 is S3-compatible object storage that you can run on your laptop, server, or anywhere you like.</description>
13+
<releaseNotes>Added bucket GET location API.</releaseNotes>
14+
<copyright>(c)2019 Joel Christner</copyright>
15+
<tags>S3 storage blob object storage rest restful</tags>
16+
<repository type="Github" url="https://github.com/jchristn/less3" />
17+
<dependencies>
18+
<group targetFramework=".NETCoreApp2.2">
19+
<dependency id="AWSSDK.S3" version="3.3.104.17" exclude="Build,Analyzers" />
20+
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
21+
<dependency id="S3ServerInterface" version="1.5.1.6" exclude="Build,Analyzers" />
22+
<dependency id="SqliteHelper" version="1.0.13" exclude="Build,Analyzers" />
23+
<dependency id="SyslogLogging" version="1.2.0" exclude="Build,Analyzers" />
24+
<dependency id="Watson" version="2.1.6" exclude="Build,Analyzers" />
25+
<dependency id="XmlToPox" version="1.0.2" exclude="Build,Analyzers" />
26+
</group>
27+
</dependencies>
28+
</metadata>
29+
<files>
30+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Release\netcoreapp2.2\Less3.runtimeconfig.json" target="lib\netcoreapp2.2\Less3.runtimeconfig.json" />
31+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Release\netcoreapp2.2\Less3.dll" target="lib\netcoreapp2.2\Less3.dll" />
32+
</files>
33+
</package>

Less3/obj/Release/Less3.1.0.4.nuspec

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>Less3</id>
5+
<version>1.0.4</version>
6+
<authors>Joel Christner</authors>
7+
<owners>Joel Christner</owners>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<licenseUrl>https://github.com/jchristn/less3/blob/master/LICENSE.txt</licenseUrl>
10+
<projectUrl>https://github.com/jchristn/less3</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/jchristn/less3/master/assets/icon.ico</iconUrl>
12+
<description>&lt;3 Less3 is S3-compatible object storage that you can run on your laptop, server, or anywhere you like.</description>
13+
<releaseNotes>Fix serializer for Cyberduck compatibility</releaseNotes>
14+
<copyright>(c)2019 Joel Christner</copyright>
15+
<tags>S3 storage blob object storage rest restful</tags>
16+
<repository type="Github" url="https://github.com/jchristn/less3" />
17+
<dependencies>
18+
<group targetFramework=".NETCoreApp2.2">
19+
<dependency id="AWSSDK.S3" version="3.3.104.17" exclude="Build,Analyzers" />
20+
<dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
21+
<dependency id="S3ServerInterface" version="1.5.1.6" exclude="Build,Analyzers" />
22+
<dependency id="SqliteHelper" version="1.0.13" exclude="Build,Analyzers" />
23+
<dependency id="SyslogLogging" version="1.2.0" exclude="Build,Analyzers" />
24+
<dependency id="Watson" version="2.1.6" exclude="Build,Analyzers" />
25+
<dependency id="XmlToPox" version="1.0.2" exclude="Build,Analyzers" />
26+
</group>
27+
</dependencies>
28+
</metadata>
29+
<files>
30+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Release\netcoreapp2.2\Less3.runtimeconfig.json" target="lib\netcoreapp2.2\Less3.runtimeconfig.json" />
31+
<file src="C:\Code\KVPbase\Less3\Less3\bin\Release\netcoreapp2.2\Less3.dll" target="lib\netcoreapp2.2\Less3.dll" />
32+
</files>
33+
</package>

Less3/obj/Release/netcoreapp2.2/Less3.AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
[assembly: System.Reflection.AssemblyCopyrightAttribute("(c)2019 Joel Christner")]
1717
[assembly: System.Reflection.AssemblyDescriptionAttribute("<3 Less3 is S3-compatible object storage that you can run on your laptop, server," +
1818
" or anywhere you like.")]
19-
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.2.0")]
20-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.2")]
19+
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.4.0")]
20+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.4")]
2121
[assembly: System.Reflection.AssemblyProductAttribute("Less3")]
2222
[assembly: System.Reflection.AssemblyTitleAttribute("Less3")]
23-
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.2.0")]
23+
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.4.0")]
2424

2525
// Generated by the MSBuild WriteCodeFragment class.
2626

512 Bytes
Binary file not shown.

Less3/obj/project.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@
12081208
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
12091209
},
12101210
"project": {
1211-
"version": "1.0.3",
1211+
"version": "1.0.4",
12121212
"restore": {
12131213
"projectUniqueName": "C:\\Code\\KVPbase\\Less3\\Less3\\Less3.csproj",
12141214
"projectName": "Less3",

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Core use cases for Less3:
1919

2020
v1.0.x
2121

22+
- Added bucket location API
23+
- Changed serializer to remove pretty print for Cyberduck compatibility (S3 Java SDK compatibility)
24+
- Added ACL APIs
25+
- Authentication header support for both v2 and v4
26+
- Chunked transfer support
2227
- Initial release; please see supported APIs below.
2328

2429
## Help and Feedback

0 commit comments

Comments
 (0)