Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from DataDog/jlegrone/copyright
Browse files Browse the repository at this point in the history
Update copyright
  • Loading branch information
jlegrone authored Sep 10, 2021
2 parents 011f820 + 779f518 commit bd41b41
Show file tree
Hide file tree
Showing 27 changed files with 265 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Jacob LeGrone
Copyright (c) 2021 Datadog, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/admin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/db.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/events.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/execution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/namespace.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/plugin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/queue.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package schema

// Version is the SQLite database release version
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/shard.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/task.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/sqlite/typeconv.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
2 changes: 2 additions & 0 deletions internal/common/persistence/sql/sqlplugin/tools/connection.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
Expand Down
3 changes: 3 additions & 0 deletions internal/copyright/header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.

This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
193 changes: 193 additions & 0 deletions internal/copyright/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// The MIT License
//
// Copyright (c) 2021 Datadog, Inc.
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package main

import (
"bufio"
_ "embed"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

type (
// task that adds license header to source
// files, if they don't already exist
addLicenseHeaderTask struct {
license string // license header string to add
config *config // root directory of the project source
}

// command line config params
config struct {
licenseFile string
scanDir string
verifyOnly bool
}
)

var (
//go:embed header.txt
headerText string
headerPrefixes = []string{"The MIT License", "Unless explicitly stated"}
)

var (
// directories to be excluded
dirBlocklist = []string{".gen/", ".git/", ".vscode/", ".idea/"}
// default perms for the newly created files
defaultFilePerms = os.FileMode(0644)
)

// command line utility that adds license header
// to the source files. Usage as follows:
//
// ./cmd/tools/copyright/licensegen.go
func main() {
var cfg config
flag.StringVar(&cfg.scanDir, "scanDir", ".", "directory to scan")
flag.BoolVar(&cfg.verifyOnly, "verifyOnly", false, "don't automatically add headers, just verify all files")
flag.Parse()

task := newAddLicenseHeaderTask(&cfg)
if err := task.run(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

func newAddLicenseHeaderTask(cfg *config) *addLicenseHeaderTask {
return &addLicenseHeaderTask{
config: cfg,
}
}

func (task *addLicenseHeaderTask) run() error {
license, err := commentOutLines(headerText)
if err != nil {
return fmt.Errorf("copyright header failed to comment out lines, err=%v", err.Error())
}
task.license = license

if err := filepath.Walk(task.config.scanDir, task.handleFile); err != nil {
return fmt.Errorf("copyright header check failed, err=%v", err.Error())
}
return nil
}

func (task *addLicenseHeaderTask) handleFile(path string, fileInfo os.FileInfo, err error) error {
if err != nil {
return err
}

if fileInfo.IsDir() {
return nil
}

if !mustProcessPath(path) {
return nil
}

if !strings.HasSuffix(fileInfo.Name(), ".go") {
return nil
}

// Used as part of the cli to write licence headers on files, does not use user supplied input so marked as nosec
// #nosec
f, err := os.Open(path)
if err != nil {
return err
}

scanner := bufio.NewScanner(f)
readLineSucc := scanner.Scan()
if !readLineSucc {
return fmt.Errorf("fail to read first line of file %v", path)
}
firstLine := strings.TrimSpace(scanner.Text())
if err := scanner.Err(); err != nil {
return err
}
f.Close()

for _, prefix := range headerPrefixes {
if strings.Contains(firstLine, prefix) {
return nil // file already has the copyright header
}
}

// at this point, src file is missing the header
if task.config.verifyOnly {
if !isFileAutogenerated(path) {
return fmt.Errorf("%v missing license header", path)
}
}

// Used as part of the cli to write licence headers on files, does not use user supplied input so marked as nosec
// #nosec
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}

return ioutil.WriteFile(path, []byte(task.license+string(data)), defaultFilePerms)
}

func isFileAutogenerated(path string) bool {
return false
}

func mustProcessPath(path string) bool {
for _, d := range dirBlocklist {
if strings.HasPrefix(path, d) {
return false
}
}
return true
}

func commentOutLines(str string) (string, error) {
var lines []string
scanner := bufio.NewScanner(strings.NewReader(str))
for scanner.Scan() {
line := scanner.Text()
if line == "" {
lines = append(lines, "//\n")
} else {
lines = append(lines, fmt.Sprintf("// %s\n", line))
}
}
lines = append(lines, "\n")

if err := scanner.Err(); err != nil {
return "", err
}
return strings.Join(lines, ""), nil
}
4 changes: 4 additions & 0 deletions internal/examples/helloworld/helloworld.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package helloworld

import (
Expand Down
4 changes: 4 additions & 0 deletions internal/liteconfig/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package liteconfig

import (
Expand Down
4 changes: 4 additions & 0 deletions internal/liteconfig/freeport.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package liteconfig

import (
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package main

import (
Expand Down
4 changes: 4 additions & 0 deletions server/options.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package server

import (
Expand Down
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package server

import (
Expand Down
4 changes: 4 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package server_test

import (
Expand Down
4 changes: 4 additions & 0 deletions server/temporaltest/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package temporaltest

import (
Expand Down
4 changes: 4 additions & 0 deletions server/temporaltest/server_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.

package temporaltest_test

import (
Expand Down

0 comments on commit bd41b41

Please sign in to comment.