Skip to content

Commit

Permalink
feat: reads yaml simple schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdeenen committed Dec 8, 2021
1 parent 1e5dbe4 commit faacee4
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ dstrm
*.json
*.tar.gz
s3.json
config.yaml
/*.yaml
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/strmprivacy/api-definitions-go/v2 v2.1.0 // indirect
github.com/strmprivacy/api-definitions-go/v2 v2.1.0
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
google.golang.org/grpc v1.39.0
google.golang.org/protobuf v1.27.1
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
sigs.k8s.io/yaml v1.3.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,5 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
2 changes: 1 addition & 1 deletion pkg/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"net"
"net/http"
"os"
"strings"
"strmprivacy/strm/pkg/common"
"strmprivacy/strm/pkg/entity"
"strings"
)

var Auth = Authenticator{}
Expand Down
5 changes: 2 additions & 3 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ var ConfigPath string
// For example, --api-host is bound to STRM_API_HOST
const EnvPrefix = "STRM"


const ClientIdFlag = "client-id"
const ClientSecretFlag = "client-secret"
const ClientIdFlag = "client-id"
const ClientSecretFlag = "client-secret"
const DefaultConfigFilename = "config"
const DefaultConfigFileSuffix = ".yaml"

Expand Down
2 changes: 1 addition & 1 deletion pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"io/fs"
"io/ioutil"
"path"
"strings"
"strmprivacy/strm/pkg/auth"
"strmprivacy/strm/pkg/common"
"strings"
)

type configuration struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/jedib0t/go-pretty/v6/list"
"github.com/spf13/cobra"
"os"
"strings"
"strmprivacy/strm/pkg/common"
"strmprivacy/strm/pkg/util"
"strings"
)

var printer util.Printer
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"strmprivacy/strm/pkg/common"
"strings"
"strmprivacy/strm/pkg/common"
)

func SetupGrpc(host string, token *string) (*grpc.ClientConn, context.Context) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/schema/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func CreateCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
}
flags := createCmd.Flags()
flags.String(definitionFlag, "", "filename of the definition")
flags.String(definitionFlag, "", "filename of the definition (either Simple Schema, Avro or Json)")
_ = createCmd.MarkFlagRequired(definitionFlag)
flags.String(schemaTypeFlag, "AVRO", "type of schema")
flags.Bool(publicFlag, false, "should the schema become public")
Expand Down
10 changes: 9 additions & 1 deletion pkg/entity/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"strings"

"sigs.k8s.io/yaml"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/strmprivacy/api-definitions-go/v2/api/entities/v1"
Expand Down Expand Up @@ -117,9 +119,15 @@ func create(cmd *cobra.Command, args *string) {
IsPublic: isPublic,
},
}
// try yaml
convertedToJson, err := yaml.YAMLToJSON(definition)
if err == nil {
definition = convertedToJson
}
// try json
err = protojson.Unmarshal(definition, simple)
if err == nil {
// it's a simple message
// it's a simple schema
req.Schema.SimpleSchema = simple
} else {
req.Schema.Definition = string(definition)
Expand Down
2 changes: 1 addition & 1 deletion pkg/entity/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"google.golang.org/grpc"
"regexp"
"strconv"
"strings"
"strmprivacy/strm/pkg/auth"
"strmprivacy/strm/pkg/common"
"strmprivacy/strm/pkg/util"
"strings"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/kafkaconsumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"log"
"os"
"os/signal"
"strings"
"strmprivacy/strm/pkg/auth"
"strmprivacy/strm/pkg/common"
"strmprivacy/strm/pkg/entity/kafka_exporter"
"strmprivacy/strm/pkg/util"
"strings"
"sync"
"syscall"
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"os"
"os/exec"
"regexp"
"strmprivacy/strm/pkg/util"
"strings"
"strmprivacy/strm/pkg/util"
"testing"
)

Expand Down

0 comments on commit faacee4

Please sign in to comment.