Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion cli/azd/extensions/extension.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"capabilities": {
"type": "array",
"title": "Capabilities",
"description": "List of capabilities provided by the extension. Supported values: custom-commands, lifecycle-events, mcp-server, service-target-provider, framework-service-provider, provisioning-provider, metadata. Select one or more from the allowed list. Each value must be unique. Not required for extension packs, which declare dependencies instead and have no executable.",
"description": "List of capabilities provided by the extension. Supported values: custom-commands, lifecycle-events, mcp-server, service-target-provider, framework-service-provider, provisioning-provider, validation-provider, metadata. Select one or more from the allowed list. Each value must be unique. Not required for extension packs, which declare dependencies instead and have no executable.",
"minItems": 1,
Comment thread
JeffreyCA marked this conversation as resolved.
"uniqueItems": true,
"items": {
Expand Down Expand Up @@ -153,6 +153,12 @@
"title": "Provisioning Provider",
"description": "Provisioning provider enables extensions to provide a custom infrastructure provisioning experience."
},
{
"type": "string",
"const": "validation-provider",
"title": "Validation Provider",
"description": "Validation provider enables extensions to contribute checks to azd validation pipelines."
},
{
"type": "string",
"const": "metadata",
Expand Down
12 changes: 8 additions & 4 deletions cli/azd/extensions/microsoft.azd.demo/ci-test.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Write-Host "Run test command(s) here..."

# Exit 0 for success, nonzero exit for failure
exit 0
Write-Host "Running unit tests..."
go test ./... -count=1

if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

exit 0
151 changes: 80 additions & 71 deletions cli/azd/extensions/microsoft.azd.demo/internal/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,77 +28,8 @@ func newListenCommand() *cobra.Command {
}
defer azdClient.Close()

host := azdext.NewExtensionHost(azdClient).
WithServiceTarget("demo", func() azdext.ServiceTargetProvider {
return project.NewDemoServiceTargetProvider(azdClient)
}).
WithFrameworkService("rust", func() azdext.FrameworkServiceProvider {
return project.NewDemoFrameworkServiceProvider(azdClient)
}).
WithProvisioningProvider("demo", func() azdext.ProvisioningProvider {
return project.NewDemoProvisioningProvider(azdClient)
}).
WithValidationCheck(azdext.ValidationCheckRegistration{
// Bicep-only check: runs during BicepProvider preflight and
// receives the Bicep snapshot / ARM template context. It is
// skipped gracefully when no snapshot is available (e.g. a
// non-Bicep provider), but is not dead code for Bicep.
CheckType: azdext.ValidationCheckTypeLocalPreflight,
RuleID: "demo_warning",
Factory: func() azdext.ValidationCheckProvider {
return project.NewDemoValidationCheck()
},
}).
WithValidationCheck(azdext.ValidationCheckRegistration{
// Provider-agnostic check: runs before provisioning for every
// provider (Bicep, Terraform, and extension providers such as
// this demo provider). Receives the lean provision context.
CheckType: azdext.ValidationCheckTypeProvision,
RuleID: "demo_provision_warning",
Factory: func() azdext.ValidationCheckProvider {
return project.NewDemoProvisionValidationCheck()
},
}).
WithProjectEventHandler("preprovision", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithProjectEventHandler("predeploy", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important predeploy project work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithProjectEventHandler("postdeploy", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important postdeploy project work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithServiceEventHandler("prepackage", func(ctx context.Context, args *azdext.ServiceEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("Service: %s, Artifacts: %d\n", args.Service.Name, len(args.ServiceContext.Package))
time.Sleep(250 * time.Millisecond)
}

return nil
}, nil).
WithServiceEventHandler("postpackage", func(ctx context.Context, args *azdext.ServiceEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("Service: %s, Artifacts: %d\n", args.Service.Name, len(args.ServiceContext.Package))
time.Sleep(250 * time.Millisecond)
}

return nil
}, nil)
host := azdext.NewExtensionHost(azdClient)
configureExtensionHost(host)

// Start listening for events
// This is a blocking call and will not return until the server connection is closed.
Expand All @@ -112,3 +43,81 @@ func newListenCommand() *cobra.Command {

return cmd
}

// configureExtensionHost wires the demo extension's providers and event handlers onto
// the supplied host, so tests can verify the registrations against extension.yaml.
func configureExtensionHost(host *azdext.ExtensionHost) {
azdClient := host.Client()

host.
WithServiceTarget("demo", func() azdext.ServiceTargetProvider {
return project.NewDemoServiceTargetProvider(azdClient)
}).
WithFrameworkService("rust", func() azdext.FrameworkServiceProvider {
return project.NewDemoFrameworkServiceProvider(azdClient)
}).
WithProvisioningProvider("demo", func() azdext.ProvisioningProvider {
return project.NewDemoProvisioningProvider(azdClient)
}).
WithValidationCheck(azdext.ValidationCheckRegistration{
// Bicep-only check: runs during BicepProvider preflight and
// receives the Bicep snapshot / ARM template context. It is
// skipped gracefully when no snapshot is available (e.g. a
// non-Bicep provider), but is not dead code for Bicep.
CheckType: azdext.ValidationCheckTypeLocalPreflight,
RuleID: "demo_warning",
Factory: func() azdext.ValidationCheckProvider {
return project.NewDemoValidationCheck()
},
}).
WithValidationCheck(azdext.ValidationCheckRegistration{
// Provider-agnostic check: runs before provisioning for every
// provider (Bicep, Terraform, and extension providers such as
// this demo provider). Receives the lean provision context.
CheckType: azdext.ValidationCheckTypeProvision,
RuleID: "demo_provision_warning",
Factory: func() azdext.ValidationCheckProvider {
return project.NewDemoProvisionValidationCheck()
},
}).
WithProjectEventHandler("preprovision", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithProjectEventHandler("predeploy", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important predeploy project work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithProjectEventHandler("postdeploy", func(ctx context.Context, args *azdext.ProjectEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("%d. Doing important postdeploy project work in extension...\n", i)
time.Sleep(250 * time.Millisecond)
}

return nil
}).
WithServiceEventHandler("prepackage", func(ctx context.Context, args *azdext.ServiceEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("Service: %s, Artifacts: %d\n", args.Service.Name, len(args.ServiceContext.Package))
time.Sleep(250 * time.Millisecond)
}

return nil
}, nil).
WithServiceEventHandler("postpackage", func(ctx context.Context, args *azdext.ServiceEventArgs) error {
for i := 1; i <= 20; i++ {
fmt.Printf("Service: %s, Artifacts: %d\n", args.Service.Name, len(args.ServiceContext.Package))
time.Sleep(250 * time.Millisecond)
}

return nil
}, nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package cmd

import (
"path/filepath"
"testing"

"github.com/azure/azure-dev/cli/azd/pkg/azdext"
"github.com/stretchr/testify/require"
)

// TestConfigureExtensionHostMatchesManifest verifies that the providers this
// extension registers match those declared in its extension.yaml.
func TestConfigureExtensionHostMatchesManifest(t *testing.T) {
manifestPath := filepath.Join("..", "..", "extension.yaml")
require.NoError(t, azdext.VerifyProvidersMatchManifest(configureExtensionHost, manifestPath))
}
1 change: 1 addition & 0 deletions cli/azd/extensions/registry.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"service-target-provider",
"framework-service-provider",
"provisioning-provider",
"validation-provider",
"metadata"
]
}
Expand Down
13 changes: 13 additions & 0 deletions cli/azd/pkg/azdext/extension_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"os"
"slices"
"strconv"
"sync"

Expand Down Expand Up @@ -127,6 +128,18 @@ func (er *ExtensionHost) Client() *AzdClient {
return er.client
}

// ServiceTargets returns a copy of the service target providers registered so far,
// letting tests and tooling introspect registrations without invoking Run.
func (er *ExtensionHost) ServiceTargets() []ServiceTargetRegistration {
return slices.Clone(er.serviceTargets)
}

// ProvisioningProviders returns a copy of the provisioning providers registered so
// far. See [ExtensionHost.ServiceTargets].
func (er *ExtensionHost) ProvisioningProviders() []ProvisioningProviderRegistration {
return slices.Clone(er.provisioningProviders)
}

func (er *ExtensionHost) initManagers(extensionId string, brokerLogger *log.Logger) {
if er.serviceTargetManager == nil {
er.serviceTargetManager = NewServiceTargetManager(extensionId, er.client, brokerLogger)
Expand Down
Loading
Loading