├── .gitignore ├── Taskfile.yml ├── go.mod ├── inspector.example.yml ├── ssh.go ├── go.sum ├── README.md ├── main.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /inspector 2 | /inspector.yml 3 | /.ssh -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3' 3 | 4 | tasks: 5 | default: 6 | - goimports -w . 7 | - go mod tidy 8 | - go fmt ./... 9 | - go build . 10 | - go install . 11 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module inspector 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/fatih/color v1.15.0 7 | github.com/pkg/errors v0.9.1 8 | github.com/rodaine/table v1.1.0 9 | golang.org/x/crypto v0.12.0 10 | golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb 11 | gopkg.in/yaml.v2 v2.4.0 12 | ) 13 | 14 | require ( 15 | github.com/mattn/go-colorable v0.1.13 // indirect 16 | github.com/mattn/go-isatty v0.0.19 // indirect 17 | golang.org/x/sys v0.11.0 // indirect 18 | ) 19 | -------------------------------------------------------------------------------- /inspector.example.yml: -------------------------------------------------------------------------------- 1 | aliases: 2 | uptime: uptime 3 | kernel: uname -v 4 | 5 | columns: 6 | - name: Docker 7 | command: docker version -f '{{ .Server.Version }}' 2>/dev/null || echo None 8 | - name: Containers 9 | command: docker ps -a --format '{{ .Names }}' | wc -l 10 | - name: Go 11 | command: go version 2>/dev/null || echo None 12 | 13 | servers: 14 | - docker1 15 | - docker3 16 | - docker4 17 | - docker5 18 | - docker6 19 | - docker7 20 | - docker8 21 | - docker9 22 | -------------------------------------------------------------------------------- /ssh.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "net" 9 | "os" 10 | "path" 11 | "strings" 12 | "unicode" 13 | 14 | "golang.org/x/crypto/ssh" 15 | "golang.org/x/crypto/ssh/agent" 16 | ) 17 | 18 | func sshRun(server string, columns []Column) ([]Column, error) { 19 | config, err := sshConfig() 20 | if err != nil { 21 | return nil, err 22 | } 23 | 24 | client, err := ssh.Dial("tcp", net.JoinHostPort(server, "22"), config) 25 | if err != nil { 26 | return nil, fmt.Errorf("error connecting to remote host: %w", err) 27 | } 28 | defer client.Close() 29 | 30 | socket := os.Getenv("SSH_AUTH_SOCK") 31 | if socket != "" { 32 | if err := agent.ForwardToRemote(client, socket); err != nil { 33 | fmt.Println("[ForwardToRemote] WARN: error setting up agent forwarding:", err) 34 | } 35 | } 36 | 37 | runCommand := func(command string) string { 38 | session, err := client.NewSession() 39 | if err != nil { 40 | return err.Error() 41 | } 42 | defer session.Close() 43 | 44 | // if err := agent.RequestAgentForwarding(session); err != nil { 45 | // fmt.Println("[RequestAgentForwarding] WARN: Can't enable agent forwarding:", err) 46 | // } 47 | 48 | var b bytes.Buffer 49 | session.Stdout = &b 50 | 51 | if err := session.Run(command); err != nil { 52 | isEmpty := b.String() == "" 53 | if !isEmpty { 54 | b.Write([]byte("\n")) 55 | } 56 | b.Write([]byte(err.Error())) 57 | } 58 | return strings.TrimRightFunc(b.String(), unicode.IsSpace) 59 | } 60 | 61 | // columns is already a copy 62 | for k, v := range columns { 63 | columns[k].Value = runCommand(v.Command) 64 | } 65 | return columns, nil 66 | } 67 | 68 | var errKeyNotFound = errors.New("id_rsa file not found") 69 | 70 | func loadSshKey() ([]byte, error) { 71 | locations := []string{ 72 | ".ssh/id_rsa", 73 | path.Join(os.Getenv("HOME"), ".ssh/id_rsa"), 74 | } 75 | var ( 76 | key []byte 77 | err error 78 | ) 79 | for _, loc := range locations { 80 | key, err = ioutil.ReadFile(loc) 81 | if err == nil { 82 | return key, nil 83 | } 84 | } 85 | return key, errKeyNotFound 86 | } 87 | 88 | func sshConfig() (*ssh.ClientConfig, error) { 89 | authMethods := []ssh.AuthMethod{} 90 | 91 | // ssh agent 92 | socket := os.Getenv("SSH_AUTH_SOCK") 93 | conn, err := net.Dial("unix", socket) 94 | if err != nil { 95 | agentClient := agent.NewKeyring() 96 | authMethods = append(authMethods, ssh.PublicKeysCallback(agentClient.Signers)) 97 | } else { 98 | agentClient := agent.NewClient(conn) 99 | authMethods = append(authMethods, ssh.PublicKeysCallback(agentClient.Signers)) 100 | } 101 | 102 | // private key fallback 103 | key, err := loadSshKey() 104 | isKeyNotFound := errors.Is(err, errKeyNotFound) 105 | isKeyFound := !isKeyNotFound 106 | 107 | if isKeyFound { 108 | signer, err := ssh.ParsePrivateKey(key) 109 | if err != nil { 110 | return nil, err 111 | } 112 | 113 | authMethods = append(authMethods, ssh.PublicKeys(signer)) 114 | } 115 | 116 | config := &ssh.ClientConfig{ 117 | User: "root", 118 | Auth: authMethods, 119 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 120 | } 121 | return config, nil 122 | } 123 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 4 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 5 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 6 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 7 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 8 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 9 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 10 | github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= 11 | github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 12 | github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= 13 | github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 14 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 15 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 16 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 17 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 18 | github.com/rodaine/table v1.1.0 h1:/fUlCSdjamMY8VifdQRIu3VWZXYLY7QHFkVorS8NTr4= 19 | github.com/rodaine/table v1.1.0/go.mod h1:Qu3q5wi1jTQD6B6HsP6szie/S4w1QUQ8pq22pz9iL8g= 20 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 21 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 22 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 23 | golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= 24 | golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= 25 | golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= 26 | golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= 27 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 28 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 29 | golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= 30 | golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 31 | golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= 32 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 33 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 34 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 35 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 36 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 37 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inspector 2 | 3 | This is a very basic ssh helper tool to manage a smaller (few 100s up to 4 | a few 1000s) fleet of servers. The main point of inspector is to provide 5 | key insights into system details, for example, so you know which software 6 | you're running, OS and kernel versions, which hosts need upgrades, 7 | performance metrics, and basically whatever you can script into a ssh 8 | command. 9 | 10 | To configure inspector, create `inspector.yml` with: 11 | 12 | - The `aliases` section gives you the ability to create a 13 | shorthand commands, which you can invoke over with the first argument. 14 | Using `run` is a reserved keyword. 15 | - The `columns` section defines output columns for each server. When you 16 | run inspector without arguments, all these values are being retrieved and 17 | a table is printed. 18 | - The `servers` section is a list of remote servers to connect to. 19 | 20 | Example configuration: 21 | 22 | ~~~yaml 23 | aliases: 24 | uptime: uptime 25 | kernel: uname -v 26 | 27 | columns: 28 | - name: Docker 29 | command: docker version -f '{{ .Server.Version }}' 2>/dev/null || echo None 30 | - name: Containers 31 | command: docker ps -a --format '{{ .Names }}' | wc -l 32 | - name: Go 33 | command: go version 2>/dev/null || echo None 34 | 35 | servers: 36 | - docker1 37 | - docker3 38 | - docker4 39 | - docker5 40 | - docker6 41 | - docker7 42 | - docker8 43 | - docker9 44 | ~~~ 45 | 46 | Asuming `inspector` is in your execution path, you can then run: 47 | 48 | - `inspector` - Provides a general overview of your defined servers (columns) 49 | - `inspector uptime` - Runs the `uptime` alias over your servers 50 | - `inspector run uname -r` - Runs `uname -r` on all hosts 51 | 52 | Example output: 53 | 54 | ~~~text 55 | Server Docker Containers Go 56 | docker1 19.03.5 3 None 57 | docker3 18.09.0 4 None 58 | docker4 18.09.0 4 None 59 | docker5 19.03.11 3 None 60 | docker6 18.09.5 14 None 61 | docker7 18.09.5 18 None 62 | docker8 18.09.5 18 None 63 | docker9 18.09.5 19 None 64 | ~~~ 65 | 66 | ## Performance 67 | 68 | Each ssh connection is created in parallel and individual columns are run 69 | serially. This means that the response from your fleet will be available 70 | to you within seconds, not minutes. 71 | 72 | For a fleet of 60 servers, getting the complete info or uptime, just like 73 | defined above, the response takes 2 seconds. If the limitation is the 74 | connection rate itself, then we can asume that we can query 1000 servers 75 | and get the complete response in about 30 seconds. 76 | 77 | - 10 servers about 0.6sec 78 | - 60 servers about 1.8sec 79 | - 1000 severs about 20-25 sec? (estimate) 80 | 81 | > If you have a fleet of 1000s of servers, I'd be interested to know 82 | > how well inspector performs for running `uptime` on all of them. 83 | 84 | ## Other 85 | 86 | The authentication uses SSH Agent, or a PrivateKey which should either be 87 | under `.ssh/id_rsa` or `$HOME/.ssh/id_rsa`. The `root` user is used to 88 | connect to remote hosts. 89 | 90 | ## Ideas 91 | 92 | Depending on our internal usage of inspector, the following features may 93 | be added. If you're using inspector and are familiar with Go, feel free 94 | to open an issue to discuss requirements before submitting a PR. 95 | 96 | - [ ] Ability to sort by column 97 | - [ ] Set non-root user and use sudo 98 | - [x] Output machine readable results (use `--json`) 99 | - [ ] Enable support for `known_hosts` 100 | - [ ] Daemon mode with continous monitoring + prometheus export? 101 | - [ ] A better commands and flags implementation (* Don't bother with this one, we have some ideas and are very particular / peculiar about flag packages) 102 | 103 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "strings" 9 | "sync" 10 | 11 | "github.com/fatih/color" 12 | "github.com/pkg/errors" 13 | "github.com/rodaine/table" 14 | "golang.org/x/exp/slices" 15 | "gopkg.in/yaml.v2" 16 | ) 17 | 18 | type Config struct { 19 | Servers []Server 20 | Aliases map[string]string 21 | Columns []Column 22 | } 23 | 24 | type Server string 25 | 26 | type Column struct { 27 | Name string 28 | Command string 29 | Hide bool 30 | Value string 31 | } 32 | 33 | func columnNames(columns []Column) []string { 34 | result := []string{} 35 | for _, column := range columns { 36 | if !column.Hide { 37 | result = append(result, column.Name) 38 | } 39 | } 40 | return result 41 | } 42 | 43 | func columnValues(columns []Column) []string { 44 | result := []string{} 45 | for _, column := range columns { 46 | if !column.Hide { 47 | result = append(result, column.Value) 48 | } 49 | } 50 | return result 51 | } 52 | 53 | func ReadConfig(filename string) (*Config, error) { 54 | b, err := ioutil.ReadFile(filename) 55 | if err != nil { 56 | return nil, err 57 | } 58 | 59 | config := Config{} 60 | err = yaml.Unmarshal(b, &config) 61 | if err != nil { 62 | return nil, err 63 | } 64 | return &config, nil 65 | } 66 | 67 | func toInterfaceSlice(s1 string, rest []string) []interface{} { 68 | result := make([]interface{}, len(rest)+1) 69 | result[0] = s1 70 | for k, v := range rest { 71 | result[k+1] = v 72 | } 73 | return result 74 | } 75 | 76 | func start() error { 77 | config, err := ReadConfig("inspector.yml") 78 | if err != nil { 79 | return err 80 | } 81 | 82 | var ( 83 | serverWg sync.WaitGroup 84 | serverMutex sync.Mutex 85 | serverResults = make(map[string][]Column) 86 | output = "table" 87 | ) 88 | 89 | args := []string{} 90 | copy(args, os.Args) 91 | 92 | if slices.Contains(os.Args, "--json") { 93 | output = "json" 94 | args = make([]string, 0, len(os.Args)-1) 95 | for _, v := range os.Args { 96 | if v == "--json" { 97 | continue 98 | } 99 | args = append(args, v) 100 | } 101 | } 102 | 103 | if len(args) > 1 { 104 | switch args[1] { 105 | case "run": 106 | commandArgs := args[2:] 107 | if len(commandArgs) == 0 { 108 | return errors.New("No command given") 109 | } 110 | commandString := strings.Join(commandArgs, " ") 111 | config.Columns = []Column{ 112 | Column{ 113 | Name: "Output", 114 | Command: commandString, 115 | }, 116 | } 117 | 118 | default: 119 | if commandString, ok := config.Aliases[args[1]]; ok { 120 | config.Columns = []Column{ 121 | Column{ 122 | Name: "Output", 123 | Command: commandString, 124 | }, 125 | } 126 | break 127 | } 128 | return errors.New("Invalid parameter error, no such command or alias") 129 | } 130 | } 131 | 132 | for _, server := range config.Servers { 133 | serverWg.Add(1) 134 | go func(serverName string) { 135 | defer serverWg.Done() 136 | 137 | columns := make([]Column, len(config.Columns)) 138 | copy(columns, config.Columns[:]) 139 | 140 | columns, err := sshRun(serverName, columns) 141 | if err != nil { 142 | fmt.Printf("Error for %s: %s\n", serverName, err) 143 | } 144 | 145 | // fmt.Printf("%s %#v\n", serverName, columns) 146 | 147 | serverMutex.Lock() 148 | defer serverMutex.Unlock() 149 | serverResults[serverName] = columns 150 | }(string(server)) 151 | } 152 | 153 | serverWg.Wait() 154 | 155 | switch output { 156 | case "table": 157 | headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc() 158 | columnFmt := color.New(color.FgYellow).SprintfFunc() 159 | 160 | tbl := table.New(toInterfaceSlice("Server", columnNames(config.Columns))...) 161 | tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) 162 | 163 | for _, server := range config.Servers { 164 | serverName := string(server) 165 | if columns, ok := serverResults[serverName]; ok { 166 | tbl.AddRow(toInterfaceSlice(serverName, columnValues(columns))...) 167 | } 168 | } 169 | 170 | tbl.Print() 171 | case "json": 172 | b, err := json.MarshalIndent(serverResults, "", " ") 173 | if err != nil { 174 | return err 175 | } 176 | fmt.Println(string(b)) 177 | } 178 | 179 | return nil 180 | } 181 | 182 | func main() { 183 | if err := start(); err != nil { 184 | fmt.Println(err) 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2020 Tit Petric 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------