Skip to content

Commit

Permalink
feat: use new schema endpoint (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored Nov 8, 2024
1 parent f1839a0 commit 88e4ac6
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 1,313 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,4 @@ $RECYCLE.BIN/
# Project specific

./go-api-schemas
*.json
24 changes: 23 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
version: "3"

tasks:
curlSpec:
cmds:
- curl -so service_types.json https://api.aiven.io/v1/service_types
curlSpecSensitive:
requires:
vars:
- AIVEN_TOKEN
- AIVEN_PROJECT_NAME
cmds:
- for: [integration_types, integration_endpoint_types]
cmd: 'curl -so {{.ITEM}}.json https://api.aiven.io/v1/project/{{.AIVEN_PROJECT_NAME}}/{{.ITEM}} --header "Authorization: aivenv1 {{.AIVEN_TOKEN}}"'
silent: true
generate:
cmds:
- go run main.go service_types.json integration_types.json integration_endpoint_types.json
run:
cmds:
- go run main.go
- task: curlSpec
- task: curlSpecSensitive
- task: generate
build:
cmds:
- go build
test:
cmds:
- go test -v ./...
curlDist:
desc: During the development, the diff might change multiple times. Downloads files from main
cmds:
- for: [service_types, integration_types, integration_endpoint_types]
cmd: "curl -so ./pkg/dist/{{.ITEM}}.yml https://raw.githubusercontent.com/aiven/go-api-schemas/refs/heads/main/pkg/dist/{{.ITEM}}.yml"
37 changes: 7 additions & 30 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
package cmd

import (
"context"
"errors"
"os"
"strings"

"github.com/aiven/aiven-go-client/v2"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -22,21 +20,14 @@ import (
// logger is the logger of the application.
var logger = &util.Logger{}

// env is a map of environment variables.
var env = util.EnvMap{
util.EnvAivenProjectName: "",
}

// client is a pointer to the Aiven client.
var client = &aiven.Client{}

// NewCmdRoot returns a pointer to the root command.
func NewCmdRoot(l *util.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "go-api-schemas",
Use: "go-api-schemas foo.json bar.json baz.json",
Short: "go-api-schemas is a tool for generating and persisting user configuration option schemas from " +
"Aiven APIs.",
Run: run,
Run: run,
Args: cobra.MinimumNArgs(1),
}

cmd.Flags().StringP("output-dir", "o", "", "the output directory for the generated files")
Expand Down Expand Up @@ -94,20 +85,10 @@ func setup(flags *pflag.FlagSet) {
}

logger.Info.Println("setting up environment variables")

if err := util.SetupEnv(env); err != nil {
logger.Error.Fatalf("error setting up environment variables: %s", err)
}

logger.Info.Println("setting up client")

if err := util.SetupClient(client); err != nil {
logger.Error.Fatalf("error setting up client: %s", err)
}
}

// run is the function that is called when the rootCmd is executed.
func run(cmd *cobra.Command, _ []string) {
func run(cmd *cobra.Command, args []string) {
flags := cmd.Flags()

setup(flags)
Expand All @@ -117,11 +98,9 @@ func run(cmd *cobra.Command, _ []string) {
logger.Error.Fatalf("error getting regeneration flag: %s", err)
}

ctx := context.Background()

logger.Info.Println("generating")

gr, err := gen.Run(ctx, logger, env, client)
gr, err := gen.Run(args...)
if err != nil {
logger.Error.Fatalf("error generating: %s", err)
}
Expand All @@ -131,22 +110,20 @@ func run(cmd *cobra.Command, _ []string) {
if !shouldRegenerate {
logger.Info.Println("reading files")

rr, err = reader.Run(ctx, logger, flags)
rr, err = reader.Run(logger, flags)
if err != nil && !os.IsNotExist(err) {
logger.Error.Fatalf("error reading files: %s", err)
}
}

logger.Info.Println("diffing")

dr, err := diff.Run(rr, gr)
if err != nil {
logger.Error.Fatalf("error diffing: %s", err)
}

logger.Info.Println("writing files")

if err = writer.Run(ctx, logger, flags, dr); err != nil {
if err = writer.Run(logger, flags, dr); err != nil {
logger.Error.Fatalf("error writing files: %s", err)
}

Expand Down
9 changes: 1 addition & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ module github.com/aiven/go-api-schemas
go 1.22

require (
github.com/aiven/aiven-go-client/v2 v2.30.0
github.com/google/go-cmp v0.6.0
github.com/mitchellh/copystructure v1.2.0
github.com/huandu/xstrings v1.5.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
golang.org/x/net v0.30.0
golang.org/x/sync v0.8.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)
39 changes: 2 additions & 37 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
github.com/aiven/aiven-go-client/v2 v2.30.0 h1:dj1nRuO1XglnwH2IwKmqEl3SGaqKebDoxnd+SRjxQRg=
github.com/aiven/aiven-go-client/v2 v2.30.0/go.mod h1:Eyxa+fNgayObmUBW94uJuEkyOe1646cEpjFzhm/NETY=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
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/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand All @@ -42,18 +18,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM=
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 88e4ac6

Please sign in to comment.