Skip to content

Commit 01c433a

Browse files
committed
Merge pull request #561 from elasticsearch/feature/assembly-signing
Feature/assembly signing
2 parents 895b8be + e7d2ad7 commit 01c433a

File tree

219 files changed

+2641
-1343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+2641
-1343
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,25 @@ _ReSharper*/
3434
_NCrunch*/
3535
[Tt]est[Rr]esult*
3636

37+
keypair.snk
38+
private.snk
39+
*.snk
3740
build/keys/private.snk
3841
build/keys/keypair.snk
3942
build/*
4043
!build/tools
4144
build/tools/*
4245
!build/tools/sn
4346
!build/tools/ilmerge
47+
!build/*.fsx
48+
!build/*.fsx
49+
!build/*.ps1
50+
!build/*.nuspec
51+
4452
/dep/Newtonsoft.Json.4.0.2
4553
!new_docs/build
4654
new_docs/node_modules
55+
doc/Help
4756

4857
/src/Nest.Tests.Unit/*.ncrunchproject
4958
*.ncrunchproject
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>Elasticsearch.Net.Connection.Thrift</id>
5+
<version>1.0.0-beta1</version>
6+
<title>Elasticsearch.Net.Connection.Thrift - Thrift support for Elasticsearch.Net</title>
7+
<authors>Martijn Laarman and contributors</authors>
8+
<owners>Martijn Laarman</owners>
9+
<iconUrl>http://nest.azurewebsites.net/images/elasticsearch-net-nuget-icon.png</iconUrl>
10+
<licenseUrl>http://mpdreamz.mit-license.org/</licenseUrl>
11+
<projectUrl>https://github.com/Mpdreamz/NEST</projectUrl>
12+
<summary>An IConnection implementation that utilizes Apache Thrift to talk with elasticsearch</summary>
13+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
14+
<description>An IConnection implementation that utilizes Apache Thrift to talk with elasticsearch</description>
15+
<dependencies>
16+
<dependency id="Elasticsearch.Net" version="1.0.0-beta1"/>
17+
<dependency id="NetReflector" />
18+
</dependencies>
19+
<tags>elasticsearch elastic search lucene thrift nest</tags>
20+
</metadata>
21+
<files>
22+
<file src="output\Elasticsearch.Net.Connection.Thrift\Elasticsearch.Net.Connection.Thrift.dll" target="lib"/>
23+
<file src="output\Elasticsearch.Net.Connection.Thrift\Elasticsearch.Net.Connection.Thrift.pdb" target="lib"/>
24+
<file src="output\Elasticsearch.Net.Connection.Thrift\Elasticsearch.Net.Connection.Thrift.XML" target="lib"/>
25+
</files>
26+
</package>

build/Elasticsearch.Net.nuspec

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>Elasticsearch.Net</id>
5+
<version>1.0.0-beta1</version>
6+
<title>Elasticsearch.Net - official low level elasticsearch client</title>
7+
<authors>Martijn Laarman and contributors</authors>
8+
<owners>Martijn Laarman</owners>
9+
<iconUrl>http://nest.azurewebsites.net/images/elasticsearch-net-nuget-icon.png</iconUrl>
10+
<licenseUrl>http://mpdreamz.mit-license.org/</licenseUrl>
11+
<projectUrl>https://github.com/elasticsearch/elasticsearch-net</projectUrl>
12+
<summary>Exposes all the api endpoints but leaves you in control of building the request and response bodies. Comes with built in cluster failover/connection pooling support.
13+
</summary>
14+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
15+
<description>Exposes all the api endpoints but leaves you in control of building the request and response bodies. Comes with built in cluster failover/connection pooling support.
16+
</description>
17+
<tags>elasticsearch elastic search lucene nest</tags>
18+
</metadata>
19+
<files>
20+
<file src="output\Elasticsearch.Net\Elasticsearch.Net.dll" target="lib"/>
21+
<file src="output\Elasticsearch.Net\Elasticsearch.Net.pdb" target="lib"/>
22+
<file src="output\Elasticsearch.Net\Elasticsearch.Net.XML" target="lib"/>
23+
<file src="output\Elasticsearch.Net\init.ps1" target="tools"/>
24+
</files>
25+
</package>

build/InheritDoc.fsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#r "System.Xml.Linq.dll"
2+
open System.Xml
3+
open System.Xml.XPath
4+
open System.Linq
5+
open System.Xml.Linq
6+
open System.Text.RegularExpressions
7+
8+
let PatchXmlDoc = fun (file: string) ->
9+
let xml = XDocument.Load file
10+
let nodes = xml.XPathSelectElements("//inheritdoc")
11+
|> Seq.map (fun n ->
12+
let methodName = n.Parent.Attribute(XName.Get("name")).Value
13+
let interfaceName = Regex.Replace(methodName, @"\.([^.]+\.[^.]+\()", ".I$1")
14+
let interfaceNode = xml.XPathSelectElement (sprintf "//member[@name='%s']" interfaceName)
15+
(n.Parent, interfaceNode)
16+
)
17+
|> Seq.filter (fun (implementationElement, interfaceElement) ->
18+
interfaceElement <> null && implementationElement.HasElements && interfaceElement.HasElements
19+
)
20+
let nodesReplace = nodes
21+
|> Seq.iter (fun (implementationElement, interfaceElement) ->
22+
implementationElement.Add (interfaceElement.Descendants().ToList())
23+
)
24+
25+
xml.Save file

build/NEST.nuspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>NEST</id>
5-
<version>0.0.0.1</version>
5+
<version>1.0.0-beta1</version>
66
<title>NEST - Elasticsearch Client</title>
77
<authors>Martijn Laarman and contributors</authors>
88
<owners>Martijn Laarman</owners>
@@ -13,7 +13,7 @@
1313
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1414
<description>Elasticsearch client, strongly typed interface to Elasticsearch. Fluent request builder, mapped responses and powerful query dsl. Uses and exposes Elasticsearch.Net</description>
1515
<dependencies>
16-
<dependency id="Elasticsearch.Net" />
16+
<dependency id="Elasticsearch.Net" version="1.0.0-beta1"/>
1717
<dependency id="Newtonsoft.Json" version="6.0.1" />
1818
</dependencies>
1919
<tags>elasticsearch elastic search lucene nest</tags>
@@ -22,5 +22,6 @@
2222
<file src="output\Nest\Nest.dll" target="lib"/>
2323
<file src="output\Nest\Nest.pdb" target="lib"/>
2424
<file src="output\Nest\Nest.XML" target="lib"/>
25+
<file src="output\Nest\init.ps1" target="tools"/>
2526
</files>
2627
</package>

build/build.fsx

Lines changed: 127 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// include Fake lib
22
#r @"tools/FAKE/tools/FakeLib.dll"
3+
#load @"InheritDoc.fsx"
34
open Fake
45
open System
6+
open InheritDoc
7+
open SemVerHelper
8+
open AssemblyInfoFile
9+
510

611
// Properties
712
let buildDir = "build/output/"
@@ -14,11 +19,34 @@ Target "Clean" (fun _ ->
1419
CleanDir buildDir
1520
)
1621

22+
23+
1724
Target "BuildApp" (fun _ ->
25+
let binDirs = !! "src/**/bin/**"
26+
|> Seq.map DirectoryName
27+
|> Seq.distinct
28+
|> Seq.filter (fun f -> (f.EndsWith("Debug") || f.EndsWith("Release")) && not (f.Contains "CodeGeneration"))
29+
30+
CleanDirs binDirs
31+
32+
//Override the prebuild event because it just calls a fake task BuildApp depends on anyways
33+
let msbuildProperties = [
34+
("Configuration","Release");
35+
("PreBuildEvent","ECHO");
36+
]
37+
1838
//Compile each csproj and output it seperately in build/output/PROJECTNAME
1939
!! "src/**/*.csproj"
2040
|> Seq.map(fun f -> (f, buildDir + directoryInfo(f).Name.Replace(".csproj", "")))
21-
|> Seq.iter(fun (f,d) -> MSBuildRelease d "Build" (seq { yield f }) |> ignore)
41+
|> Seq.iter(fun (f,d) -> MSBuild d "Build" msbuildProperties (seq { yield f }) |> ignore)
42+
43+
//Scan for xml docs and patch them to replace <inheritdoc /> with the documentation
44+
//from their interfaces
45+
!! "build/output/Nest/Nest.xml" |> Seq.iter(fun f -> PatchXmlDoc f)
46+
47+
CopyFile "build/output/Nest/init.ps1" "build/nest-init.ps1"
48+
CopyFile "build/output/Elasticsearch.Net/init.ps1" "build/elasticsearch-init.ps1"
49+
2250
)
2351

2452
Target "Test" (fun _ ->
@@ -31,85 +59,130 @@ Target "Test" (fun _ ->
3159
)
3260

3361
let keyFile = "build/keys/keypair.snk"
34-
let validateSignedAssembly = fun name ->
62+
63+
let createKeys = fun _ ->
3564
let sn = "build/tools/sn/sn.exe"
3665
ExecProcess(fun p ->
3766
p.FileName <- sn
38-
p.Arguments <- sprintf @"-v build\output\%s.dll" name
39-
) (TimeSpan.FromMinutes 5.0)
40-
41-
let signAssembly = fun name ->
42-
let ilmerge = "build/tools/ilmerge/ILMerge.exe"
43-
let platform = @"/targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
44-
let i = sprintf "build\\output\\%s\\%s" name name
45-
let o = sprintf "build\\output\\%s" name
67+
p.Arguments <- sprintf @"-k %s" keyFile
68+
) (TimeSpan.FromMinutes 5.0) |> ignore
69+
70+
ExecProcess(fun p ->
71+
p.FileName <- sn
72+
p.Arguments <- sprintf @"-p %s %s" keyFile "build/keys/public.snk"
73+
) (TimeSpan.FromMinutes 5.0) |> ignore
74+
75+
Target "CreateKeysIfAbsent" (fun _ ->
76+
if not (fileExists keyFile) then createKeys()
77+
)
78+
79+
let validateSignedAssembly = fun name ->
80+
let sn = "build/tools/sn/sn.exe"
81+
let out = (ExecProcessAndReturnMessages(fun p ->
82+
p.FileName <- sn
83+
p.Arguments <- sprintf @"-v build\output\%s\%s.dll" name name
84+
) (TimeSpan.FromMinutes 5.0))
4685

47-
let dll = i + ".dll"
48-
let outdll = o + ".dll"
49-
let pdb = o + ".pdb"
50-
51-
let signExitCode = (
52-
ExecProcess(fun p ->
53-
p.FileName <- ilmerge
54-
p.Arguments <- (sprintf "%s /keyfile:%s /out:%s %s"
55-
dll keyFile outdll platform)
56-
) (TimeSpan.FromMinutes 5.0)
57-
)
86+
let valid = (out.ExitCode, out.Messages.FindIndex(fun s -> s.Contains("is valid")))
87+
88+
match valid with
89+
| (0, i) when i >= 0 -> trace (sprintf "%s was signed correctly" name)
90+
| (_, _) -> failwithf "{0} was not validly signed"
91+
92+
let out = (ExecProcessAndReturnMessages(fun p ->
93+
p.FileName <- sn
94+
p.Arguments <- sprintf @"-T build\output\%s\%s.dll" name name
95+
) (TimeSpan.FromMinutes 5.0))
96+
97+
let tokenMessage = (out.Messages.Find(fun s -> s.Contains("Public key token is")));
98+
let token = (tokenMessage.Replace("Public key token is", "")).Trim();
5899

59-
let validateExitCode = validateSignedAssembly name
60-
match (signExitCode, validateExitCode) with
61-
| (0,0) ->
62-
MoveFile (DirectoryName dll) outdll
63-
MoveFile (DirectoryName dll) pdb
64-
| _ ->
65-
failwithf "Failed to sign {0}" name
100+
let valid = (out.ExitCode, token)
101+
let oficialToken = "96c599bbe3e70f5d"
102+
match valid with
103+
| (0, t) when t = oficialToken ->
104+
trace (sprintf "%s was signed with official key token %s" name t)
105+
| (_, t) -> traceFAKE "%s was not signed with the official token: %s but %s" name oficialToken t
66106

67107
let nugetPack = fun name ->
68-
108+
let fileVersion = (getBuildParamOrDefault "version" "0.1.0")
69109
CreateDir nugetOutDir
70-
110+
let package = (sprintf @"build\%s.nuspec" name)
111+
let packageContents = ReadFileAsString package
112+
let re = @"(?<start>\<version\>|""(Elasticsearch.Net|Nest)"" version="")[^""><]+(?<end>\<\/version\>|"")"
113+
let replacedContents = regex_replace re (sprintf "${start}%s${end}" fileVersion) packageContents
114+
WriteStringToFile false package replacedContents
115+
71116
let dir = sprintf "%s/%s/" buildDir name
72-
let version = "1.0.0-c2"
73117
NuGetPack (fun p ->
74118
{p with
75-
Version = version
119+
Version = fileVersion
76120
WorkingDir = dir
77121
OutputPath = dir
78122
})
79-
(sprintf @"build\%s.nuspec" name)
123+
package
80124

81-
MoveFile nugetOutDir (buildDir + (sprintf "%s/%s.%s.nupkg" name name version))
125+
MoveFile nugetOutDir (buildDir + (sprintf "%s/%s.%s.nupkg" name name fileVersion))
82126

83127
let buildDocs = fun action ->
84128
let node = @"build\tools\Node.js\node.exe"
85129
let wintersmith = @"..\build\tools\node_modules\wintersmith\bin\wintersmith"
86130
ExecProcess (fun p ->
87-
p.WorkingDirectory <- "new_docs"
88-
p.FileName <- node
89-
p.Arguments <- sprintf "\"%s\" %s" wintersmith action
90-
) (TimeSpan.FromMinutes (if action = "preview" then 300.0 else 5.0))
91-
131+
p.WorkingDirectory <- "new_docs"
132+
p.FileName <- node
133+
p.Arguments <- sprintf "\"%s\" %s" wintersmith action
134+
)
135+
(TimeSpan.FromMinutes (if action = "preview" then 300.0 else 5.0))
136+
92137
Target "Version" (fun _ ->
93-
let v = (getBuildParamOrDefault "version" "0.1.0")
94-
let version = SemVerHelper.parse v
95-
let assemblyVersion = sprintf "%i.%i.0.0" version.Major version.Minor
96-
97-
trace (sprintf "%s %s" v assemblyVersion)
98-
138+
let fileVersion = (getBuildParamOrDefault "version" "0.1.0")
139+
let version = SemVerHelper.parse fileVersion
140+
141+
let suffix = fun (prerelease: PreRelease) -> sprintf "-%s%i" prerelease.Name prerelease.Number.Value
142+
let assemblySuffix = if version.PreRelease.IsSome then suffix version.PreRelease.Value else "";
143+
let assemblyVersion = sprintf "%i.0.0%s" version.Major assemblySuffix
144+
145+
match (assemblySuffix, version.Minor, version.Patch) with
146+
| (s, m, p) when s <> "" && (m <> 0 || p <> 0) -> failwithf "Cannot create prereleases for minor or major builds!"
147+
| ("", _, _) -> traceFAKE "Building fileversion %s for asssembly version %s" fileVersion assemblyVersion
148+
| _ -> traceFAKE "Building prerelease %s for major assembly version %s " fileVersion assemblyVersion
149+
150+
let assemblyDescription = fun (f: string) ->
151+
let name = f
152+
match f.ToLowerInvariant() with
153+
| f when f = "elasticsearch.net" -> "Elasticsearch.Net - oficial low level elasticsearch client"
154+
| f when f = "nest" -> "NEST - oficial high level elasticsearch client"
155+
| f when f = "elasticsearch.net.connection.thrift" -> "Elasticsearc.Net.Connection.Thrift - Add thrift support to elasticsearch."
156+
| _ -> sprintf "%s" name
157+
158+
!! "src/**/AssemblyInfo.cs"
159+
|> Seq.iter(fun f ->
160+
let name = (directoryInfo f).Parent.Parent.Name
161+
CreateCSharpAssemblyInfo f [
162+
Attribute.Title name
163+
Attribute.Copyright (sprintf "Elasticsearch %i" DateTime.UtcNow.Year)
164+
Attribute.Description (assemblyDescription name)
165+
Attribute.Company "Elasticsearch"
166+
Attribute.Configuration "Release"
167+
Attribute.Version assemblyVersion
168+
Attribute.FileVersion fileVersion
169+
Attribute.InformationalVersion fileVersion
170+
]
171+
)
99172
)
100173

174+
101175
Target "Release" (fun _ ->
102176
if not <| fileExists keyFile
103177
then failwithf "{0} does not exist to sign the assemblies" keyFile
104178

105-
//signAssembly("Elasticsearch.Net")
106-
//signAssembly("Elasticsearch.Net.Connection.Thrift")
107-
//signAssembly("Nest")
108-
109179
nugetPack("Elasticsearch.Net")
110180
nugetPack("Elasticsearch.Net.Connection.Thrift")
111181
nugetPack("Nest")
112182

183+
validateSignedAssembly("Elasticsearch.Net")
184+
validateSignedAssembly("Elasticsearch.Net.Connection.Thrift")
185+
validateSignedAssembly("Nest")
113186
)
114187

115188
Target "Docs" (fun _ -> buildDocs "build" |> ignore)
@@ -120,14 +193,19 @@ Target "DocsPreview" (fun _ ->
120193

121194
// Dependencies
122195
"Clean"
196+
==> "CreateKeysIfAbsent"
197+
=?> ("Version", hasBuildParam "version")
123198
==> "BuildApp"
124199
==> "Test"
125200
==> "Build"
126201

127202
"Build"
203+
==> "Docs"
128204
==> "Release"
129205

130206
"DocsPreview"
207+
"BuildApp"
208+
"CreateKeysIfAbsent"
131209
"Version"
132210
// start build
133211
RunTargetOrDefault "Build"

build/elasticsearch-init.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$DTE.ItemOperations.Navigate("http://nest.azurewebsites.net/elasticsearch-net/quick-start.html")

build/keys/public.snk

-160 Bytes
Binary file not shown.

build/nest-init.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$DTE.ItemOperations.Navigate("http://nest.azurewebsites.net/nest/quick-start.html")

doc/Help/Documentation.chm

-10.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)