Skip to content

Commit

Permalink
feat: use feature flagging for schema registry (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert authored and LukeHagar committed Jun 13, 2024
1 parent 786366f commit a2f5b5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
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.5.5
github.com/speakeasy-api/speakeasy-core v0.4.3
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ github.com/speakeasy-api/sdk-gen-config v1.10.0 h1:ceaH8+O74G/UzpBkWMjoFta8NuLuI
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.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.3 h1:SIewsju3o8C1QhwCgGs7ikWuAQUalLXIhC/Uvou/jhw=
github.com/speakeasy-api/speakeasy-core v0.4.3/go.mod h1:/LlFbfieNptr7RUl7+lpQg/1cwPThYEnqCNTTdhLNsA=
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
54 changes: 29 additions & 25 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 @@ -488,7 +489,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 @@ -510,32 +512,34 @@ func (w *Workflow) runSource(ctx context.Context, parentStep *WorkflowStep, id s
}

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 "", nil, 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 "", nil, 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 "", nil, 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 "", nil, fmt.Errorf("failed to publish openapi bundle to registry: %w", err)
}
}
}

Expand Down

0 comments on commit a2f5b5f

Please sign in to comment.