This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DataDog/jlegrone/copyright
Update copyright
- Loading branch information
Showing
27 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/sqlite/cluster_metadata.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/sqlite/execution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/sqlite/execution_maps.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/sqlite/namespace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
internal/common/persistence/sql/sqlplugin/sqlite/schema/version.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/sqlite/visibility.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
internal/common/persistence/sql/sqlplugin/tools/connection.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters