Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use feature flagging for schema registry #616

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ require (
github.com/speakeasy-api/openapi-generation/v2 v2.306.3
github.com/speakeasy-api/openapi-overlay v0.4.0
github.com/speakeasy-api/sdk-gen-config v1.10.0
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.4.3
github.com/speakeasy-api/speakeasy-core v0.4.2
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.5.5
github.com/speakeasy-api/speakeasy-core v0.4.4
github.com/speakeasy-api/speakeasy-proxy v0.0.2
github.com/speakeasy-sdks/openai-go-sdk/v4 v4.2.1
github.com/spf13/cobra v1.8.0
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,24 +505,16 @@ github.com/speakeasy-api/huh v0.0.1 h1:zJuyql3bxkxkW8EN+xNuW6B6kmZZldtcKbLBx32Sw
github.com/speakeasy-api/huh v0.0.1/go.mod h1:JVIEq1tlJtFWZ4OACzN0Tj+I3+SdLiMznROo12ZJ1bQ=
github.com/speakeasy-api/openapi-changes v1.0.3 h1:4y0ar2qElQBTSgY957IRTngTntwCgcpTInNo3BE3e6g=
github.com/speakeasy-api/openapi-changes v1.0.3/go.mod h1:dg89cIGQRjrXTytVaWHMRtZmJ5KLrWPdoLh05A+VFXc=
github.com/speakeasy-api/openapi-generation/v2 v2.304.1 h1:AlklIhLBusQkDZsXsCxPUeAE8QuhK61LrHsN7ELa2ic=
github.com/speakeasy-api/openapi-generation/v2 v2.304.1/go.mod h1:hVRNUWDpajfgd+ZQHX0aGsSQb1a8dquWyb173dVihj8=
github.com/speakeasy-api/openapi-generation/v2 v2.305.1 h1:gsW4c9mO81h9yiFgLVoooICcyzHHmAJxtuHPQ3HWmdk=
github.com/speakeasy-api/openapi-generation/v2 v2.305.1/go.mod h1:hVRNUWDpajfgd+ZQHX0aGsSQb1a8dquWyb173dVihj8=
github.com/speakeasy-api/openapi-generation/v2 v2.306.0 h1:Oie6m6yuxkK75Y/RQifxUWFHvMV8sfyJ2v0QhrIF0Z4=
github.com/speakeasy-api/openapi-generation/v2 v2.306.0/go.mod h1:hVRNUWDpajfgd+ZQHX0aGsSQb1a8dquWyb173dVihj8=
github.com/speakeasy-api/openapi-generation/v2 v2.306.2 h1:HcMQi6iW38ZXphhqiVCDp156C5NBxGbCNRyk0a+sCy8=
github.com/speakeasy-api/openapi-generation/v2 v2.306.2/go.mod h1:hVRNUWDpajfgd+ZQHX0aGsSQb1a8dquWyb173dVihj8=
github.com/speakeasy-api/openapi-generation/v2 v2.306.3 h1:20gezu7JpNxOdu4viXSYJGOLFriHcVESYRf3ZgdhGEY=
github.com/speakeasy-api/openapi-generation/v2 v2.306.3/go.mod h1:hVRNUWDpajfgd+ZQHX0aGsSQb1a8dquWyb173dVihj8=
github.com/speakeasy-api/openapi-overlay v0.4.0 h1:FKxopZDhlAIzPS2lKl2X7pfworNvlsxTYjaDwvlY+gw=
github.com/speakeasy-api/openapi-overlay v0.4.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc=
github.com/speakeasy-api/sdk-gen-config v1.10.0 h1:ceaH8+O74G/UzpBkWMjoFta8NuLuIydVH8h3MbAK/GA=
github.com/speakeasy-api/sdk-gen-config v1.10.0/go.mod h1:7FsPqdsh//6Z0OcO/jQPD66l6/m1YVvK5tmt0+KRpdo=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.4.3 h1:W28QJnz/YsggHNt53+mBzhkPprGCETfWjLKk+xQFKhg=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.4.3/go.mod h1:b4fiZ1Wid0JHwwiYqhaPifDwjmC15uiN7A8Cmid+9kw=
github.com/speakeasy-api/speakeasy-core v0.4.2 h1:MsltOFThVMiqVMwygKGnZDyctQ3+eDV4euyJfjRCiok=
github.com/speakeasy-api/speakeasy-core v0.4.2/go.mod h1:/LlFbfieNptr7RUl7+lpQg/1cwPThYEnqCNTTdhLNsA=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.5.5 h1:FRDnEHlfB9trpvdatO+p1WQtMt6SvfS5z3lPhYFvRr8=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.5.5/go.mod h1:b4fiZ1Wid0JHwwiYqhaPifDwjmC15uiN7A8Cmid+9kw=
github.com/speakeasy-api/speakeasy-core v0.4.4 h1:bnkcCSlFEh3NSgDM/abLoUUC7B6AvPiLe2lRDz8h8ok=
github.com/speakeasy-api/speakeasy-core v0.4.4/go.mod h1:FTrob6LGyDsd9lCPEHAf3NKlmjGwqWjsvWyvPBsPK08=
github.com/speakeasy-api/speakeasy-go-sdk v1.8.1 h1:atzohw12oQ5ipaLb1q7ntTu4vvAgKDJsrvaUoOu6sw0=
github.com/speakeasy-api/speakeasy-go-sdk v1.8.1/go.mod h1:XbzaM0sMjj8bGooz/uEtNkOh1FQiJK7RFuNG3LPBSAU=
github.com/speakeasy-api/speakeasy-proxy v0.0.2 h1:u4rQ8lXvuYRCSxiLQGb5JxkZRwNIDlyh+pMFYD6OGjA=
Expand Down
5 changes: 3 additions & 2 deletions internal/api/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package api

import (
"fmt"
"github.com/speakeasy-api/speakeasy/internal/log"
"io"
"os"
"path/filepath"

"github.com/speakeasy-api/speakeasy/internal/log"

"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/operations"
"github.com/speakeasy-api/speakeasy/internal/sdk"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,7 +45,7 @@ func registerSchema(cmd *cobra.Command, args []string) error {
APIID: apiID,
VersionID: versionID,
RequestBody: operations.RegisterSchemaRequestBody{
File: operations.File{
File: operations.RegisterSchemaFile{
Content: data,
FileName: filepath.Base(schemaPath),
},
Expand Down
56 changes: 30 additions & 26 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

sdkGenConfig "github.com/speakeasy-api/sdk-gen-config"
"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared"
"github.com/speakeasy-api/speakeasy/internal/usagegen"

"github.com/speakeasy-api/speakeasy-core/auth"
Expand Down Expand Up @@ -457,7 +458,8 @@ func (w *Workflow) runSource(ctx context.Context, parentStep *WorkflowStep, id s
}
}

if os.Getenv("SPEAKEASY_PUBLISH_ARTIFACT") == "1" {
hasSchemaRegistry, _ := auth.HasWorkspaceFeatureFlag(ctx, shared.FeatureFlagsSchemaRegistry)
if hasSchemaRegistry {
registryStep := rootStep.NewSubstep("Tracking OpenAPI Changes")

registryStep.NewSubstep("Snapshotting OpenAPI Revision")
Expand All @@ -473,38 +475,40 @@ func (w *Workflow) runSource(ctx context.Context, parentStep *WorkflowStep, id s
}

ext := filepath.Ext(outputLocation)
err = memfs.WriteBytes("/openapi/bundle/openapi"+ext, bs, 0644)
err = memfs.WriteBytes("/openapi/bundle/openapi"+ext, bs, 0o644)
if err != nil {
return "", fmt.Errorf("memfs: writebytes: %w", err)
}

pl := bundler.NewPipeline(&bundler.PipelineOptions{})
err = pl.BuildOCIImage(ctx, bundler.NewReadWriteFS(memfs, memfs), &bundler.OCIBuildOptions{
if err = pl.BuildOCIImage(ctx, bundler.NewReadWriteFS(memfs, memfs), &bundler.OCIBuildOptions{
Tags: []string{"latest"},
})
if err != nil {
return "", fmt.Errorf("failed to create openapi bundle: %w", err)
}

serverURL := auth.GetServerURL()
insecurePublish := false
if strings.HasPrefix(serverURL, "http://") {
insecurePublish = true
}

reg := strings.TrimPrefix(serverURL, "http://")
reg = strings.TrimPrefix(reg, "https://")
}); err != nil {
// If the preflight error is caused by lack of feature flag we continue without error
if !errors.Is(err, bundler.ErrAccessGated) {
return "", fmt.Errorf("failed to create openapi bundle: %w", err)
}
} else {
serverURL := auth.GetServerURL()
insecurePublish := false
if strings.HasPrefix(serverURL, "http://") {
insecurePublish = true
}

registryStep.NewSubstep("Storing OpenAPI Revision")
err = pl.PushOCIImage(ctx, memfs, &bundler.OCIPushOptions{
Tags: []string{"latest"},
Registry: reg,
Access: bundler.NewRepositoryAccess(config.GetSpeakeasyAPIKey(), id, bundler.RepositoryAccessOptions{
Insecure: insecurePublish,
}),
})
if err != nil {
return "", fmt.Errorf("failed to publish openapi bundle to registry: %w", err)
reg := strings.TrimPrefix(serverURL, "http://")
reg = strings.TrimPrefix(reg, "https://")

registryStep.NewSubstep("Storing OpenAPI Revision")
_, err = pl.PushOCIImage(ctx, memfs, &bundler.OCIPushOptions{
Tags: []string{"latest"},
Registry: reg,
Access: bundler.NewRepositoryAccess(config.GetSpeakeasyAPIKey(), id, bundler.RepositoryAccessOptions{
Insecure: insecurePublish,
}),
})
if err != nil {
return "", fmt.Errorf("failed to publish openapi bundle to registry: %w", err)
}
}
}

Expand Down
Loading