Skip to content

Commit

Permalink
feat!: drop Jsonnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
ayakovlenko committed Jun 7, 2024
1 parent b1a354d commit c5633b5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 88 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module zit
go 1.22

require (
github.com/google/go-jsonnet v0.17.0
github.com/mojotx/git-urls v1.0.4
github.com/spf13/afero v1.11.0
github.com/stretchr/testify v1.8.4
Expand All @@ -14,9 +13,11 @@ require (
require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,46 +1,31 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/google/go-jsonnet v0.17.0 h1:/9NIEfhK1NQRKl3sP2536b2+x5HnZMdql7x3yK/l8JY=
github.com/google/go-jsonnet v0.17.0/go.mod h1:sOcuej3UW1vpPTZOr8L7RQimqai1a57bt5j22LzGZCw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mojotx/git-urls v1.0.4 h1:SuaKu7PABynwXFpQ4Sdo4xRqZnPlLTfiH02MZnwPhsU=
github.com/mojotx/git-urls v1.0.4/go.mod h1:3r/CupaM0w80YWMgD/chjQLJWS6cSVHf5fxGwoxyC3g=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
14 changes: 7 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ type HostMap map[string]HostConfig

// HostConfig TODO
type HostConfig struct {
Default *User `json:"default" yaml:"default"`
Overrides []Override `json:"overrides" yaml:"overrides"`
Default *User `yaml:"default"`
Overrides []Override `yaml:"overrides"`
}

// User TODO
type User struct {
Name string `json:"name" yaml:"name"`
Email string `json:"email" yaml:"email"`
Name string `yaml:"name"`
Email string `yaml:"email"`
}

// Override TODO
type Override struct {
Owner string `json:"owner" yaml:"owner"`
Repo string `json:"repo,omitempty" yaml:"repo"`
User User `json:"user" yaml:"user"`
Owner string `yaml:"owner"`
Repo string `yaml:"repo"`
User User `yaml:"user"`
}

type ConfigRoot struct {
Expand Down
29 changes: 0 additions & 29 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ import (
)

func TestLocateConfig(t *testing.T) {
t.Run("get default Jsonnet config if it exists", func(t *testing.T) {
fs := afero.NewMemMapFs()
_, _ = fs.Create("/home/.zit/config.jsonnet")

have, _ := LocateConfFile(fs, "/home", "")
want := "/home/.zit/config.jsonnet"

if have != want {
t.Errorf("want: %s, have: %s", want, have)
}
})

t.Run("get default YAML config if it exists", func(t *testing.T) {
fs := afero.NewMemMapFs()
_, _ = fs.Create("/home/.zit/config.yaml")
Expand Down Expand Up @@ -53,23 +41,6 @@ func TestLoad(t *testing.T) {
}
})

t.Run("simple Jsonnet config", func(t *testing.T) {
config, _ := Load("test_data/config_01.jsonnet")

host, _ := config.Get("github.corp.com")

name := host.Default.Name
email := host.Default.Email

if name != "John Doe" {
t.Errorf("want: John Doe; have: %s", name)
}

if email != "john.doe@corp.com" {
t.Errorf("want: john.doe@corp.com; have: %s", email)
}
})

t.Run("simple YAML config", func(t *testing.T) {
config, _ := Load("test_data/config_01.yaml")

Expand Down
27 changes: 2 additions & 25 deletions internal/config/load.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package config

import (
"encoding/json"
"fmt"
"os"
"path"
"strings"

"github.com/google/go-jsonnet"
"github.com/spf13/afero"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -35,8 +33,7 @@ func Load(filename string) (*ConfigRoot, error) {
}
return parseYaml(contents)
case jsonnetFormat:
fmt.Println("WARN: Jsonnet configs are deprecated and going to be unsupported in future versions. Migrate to YAML format.")
return parseJsonnet(filename)
return nil, fmt.Errorf("zit no longer supports Jsonnet configs since v3")
default:
return nil, fmt.Errorf("something went horribly wrong")
}
Expand All @@ -55,18 +52,13 @@ func formatFromFilename(filename string) string {
func LocateConfFile(fs afero.Fs, userHomeDir, confPathFromEnv string) (string, error) {
var confPath string

jsonnetDefault := path.Join(userHomeDir, ".zit", "config.jsonnet")
yamlDefault := path.Join(userHomeDir, ".zit", "config.yaml")

// if ZIT_CONFIG is not set, try default location
envVarDefined := confPathFromEnv != ""

if !envVarDefined {
if fileExists(fs, jsonnetDefault) {
return jsonnetDefault, nil
} else {
return yamlDefault, nil
}
return yamlDefault, nil
}

if !fileExists(fs, confPathFromEnv) {
Expand All @@ -90,21 +82,6 @@ func fileExists(fs afero.Fs, filename string) bool {
return true
}

func parseJsonnet(filename string) (*ConfigRoot, error) {
vm := jsonnet.MakeVM()
confJSON, err := vm.EvaluateFile(filename)
if err != nil {
return nil, err
}

var Hosts HostMap
if err := json.Unmarshal([]byte(confJSON), &Hosts); err != nil {
return nil, err
}

return &ConfigRoot{Hosts}, nil
}

func parseYaml(contents []byte) (*ConfigRoot, error) {
var config ConfigRoot
if err := yaml.Unmarshal(contents, &config); err != nil {
Expand Down
11 changes: 0 additions & 11 deletions internal/config/test_data/config_01.jsonnet

This file was deleted.

0 comments on commit c5633b5

Please sign in to comment.