Skip to content

Commit

Permalink
Assert now takes into consideration the license. (elastic#7855)
Browse files Browse the repository at this point in the history
- License headers for both Elastic and ASL2 are now accessible by
  code using the licenses package.
      ```
      licenses.Elastic
      licenses.ASL2
      ```
  - Added a generator to take care of syncing the files in the licenses/
  directory.
  - Added `LICENSE` as a variable for the makefile to configure the
  go-licenser this is useful if a beat as a different license.
  • Loading branch information
ph authored and ruflin committed Aug 8, 2018
1 parent a539786 commit 437a62a
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 24 deletions.
15 changes: 12 additions & 3 deletions dev-tools/cmd/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ import (
"os"

"github.com/elastic/beats/libbeat/asset"
"github.com/elastic/beats/licenses"
)

var (
pkg string
input string
output string
pkg string
input string
output string
license = "ASL2"
)

func init() {
flag.StringVar(&pkg, "pkg", "", "Package name")
flag.StringVar(&input, "in", "-", "Source of input. \"-\" means reading from stdin")
flag.StringVar(&output, "out", "-", "Output path. \"-\" means writing to stdout")
flag.StringVar(&license, "license", "ASL2", "License header for generated file.")
}

func main() {
Expand Down Expand Up @@ -82,11 +85,17 @@ func main() {
os.Exit(1)
}

licenseHeader, err := licenses.Find(license)
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid license: %s\n", err)
os.Exit(1)
}
var buf bytes.Buffer
asset.Template.Execute(&buf, asset.Data{
Beat: beatName,
Name: file,
Data: encData,
License: licenseHeader,
Package: pkg,
})

Expand Down
96 changes: 96 additions & 0 deletions dev-tools/cmd/license/license_generate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions libbeat/asset/asset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### VARIABLE SETUP ###
### Application using libbeat may override the following variables in their Makefile
BEAT_NAME?=libbeat## @packaging Name of the binary
LICENSE?=ASL2
BEAT_TITLE?=${BEAT_NAME}## @packaging Title of the application
BEAT_PATH?=github.com/elastic/beats/${BEAT_NAME}
BEAT_PACKAGE_NAME?=${BEAT_NAME}
Expand Down Expand Up @@ -123,14 +124,14 @@ check: check-headers python-env prepare-tests ## @build Checks project and sourc
check-headers:
ifndef CHECK_HEADERS_DISABLED
@go get github.com/elastic/go-licenser
@go-licenser -d
@go-licenser -d -license ${LICENSE}
endif

.PHONY: add-headers
add-headers:
ifndef CHECK_HEADERS_DISABLED
@go get github.com/elastic/go-licenser
@go-licenser
@go-licenser -license ${LICENSE}
endif

.PHONY: fmt
Expand Down Expand Up @@ -332,7 +333,7 @@ endif

ifneq ($(shell [[ $(BEAT_NAME) == libbeat || $(BEAT_NAME) == metricbeat ]] && echo true ),true)
mkdir -p include
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -pkg include -in fields.yml -out include/fields.go $(BEAT_NAME)
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -pkg include -in fields.yml -out include/fields.go $(BEAT_NAME)
endif

ifneq ($(shell [[ $(BEAT_NAME) == libbeat ]] && echo true ),true)
Expand Down
16 changes: 16 additions & 0 deletions licenses/APACHE-LICENSE-2.0-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
3 changes: 3 additions & 0 deletions licenses/ELASTIC-LICENSE-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
20 changes: 20 additions & 0 deletions licenses/license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package licenses

//go:generate go run ../dev-tools/cmd/license/license_generate.go
58 changes: 58 additions & 0 deletions licenses/license_header.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions metricbeat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ test-module: python-env update metricbeat.test
assets:
go run ${ES_BEATS}/metricbeat/scripts/assets/assets.go ${ES_BEATS}/metricbeat/module
mkdir -p include/fields
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -pkg include -in ${ES_BEATS}/metricbeat/_meta/fields.common.yml -out include/fields.go $(BEAT_NAME)
go run ${ES_BEATS}/libbeat/scripts/cmd/global_fields/main.go -es_beats_path ${ES_BEATS} -beat_path ${PWD} | go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -out ./include/fields/fields.go -pkg include ${ES_BEATS}/libbeat/fields.yml $(BEAT_NAME)
go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -license ${LICENSE} -pkg include -in ${ES_BEATS}/metricbeat/_meta/fields.common.yml -out include/fields.go $(BEAT_NAME)
go run ${ES_BEATS}/libbeat/scripts/cmd/global_fields/main.go -es_beats_path ${ES_BEATS} -beat_path ${PWD} | go run ${ES_BEATS}/dev-tools/cmd/asset/asset.go -license ${LICENSE} -out ./include/fields/fields.go -pkg include ${ES_BEATS}/libbeat/fields.yml $(BEAT_NAME)
2 changes: 2 additions & 0 deletions metricbeat/scripts/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/elastic/beats/libbeat/asset"
"github.com/elastic/beats/libbeat/generator/fields"
"github.com/elastic/beats/licenses"
)

func main() {
Expand Down Expand Up @@ -69,6 +70,7 @@ func main() {

var buf bytes.Buffer
asset.Template.Execute(&buf, asset.Data{
License: licenses.ASL2,
Beat: "metricbeat",
Name: module,
Data: encData,
Expand Down

0 comments on commit 437a62a

Please sign in to comment.