Skip to content
Closed
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
4 changes: 4 additions & 0 deletions cli/azd/.vscode/cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ words:
- runcontext
- unmarshals
- usgovcloudapi
- datasource
- jdbc
- passwordless
- postgre
languageSettings:
- languageId: go
ignoreRegExpList:
Expand Down
18 changes: 18 additions & 0 deletions cli/azd/internal/appdetect/appdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ type Project struct {
// Experimental: Database dependencies inferred through heuristics while scanning dependencies in the project.
DatabaseDeps []DatabaseDep

// Experimental: Azure dependencies inferred through heuristics while scanning dependencies in the project.
AzureDeps []AzureDep

// The path to the project directory.
Path string

Expand All @@ -151,6 +154,21 @@ type Project struct {
Docker *Docker
}

//type AzureDep string

type AzureDep interface {
ResourceDisplay() string
}

type AzureDepServiceBus struct {
Queues []string
IsJms bool
}

func (a AzureDepServiceBus) ResourceDisplay() string {
return "Azure Service Bus"
}

func (p *Project) HasWebUIFramework() bool {
for _, f := range p.Dependencies {
if f.IsWebUIFramework() {
Expand Down
29 changes: 29 additions & 0 deletions cli/azd/internal/auth_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package internal

// AuthType defines different authentication types.
type AuthType string

const (
AuthTypeUnspecified AuthType = "unspecified"
// Username and password, or key based authentication
AuthTypePassword AuthType = "password"
// Connection string authentication
AuthTypeConnectionString AuthType = "connectionString"
// Microsoft EntraID token credential
AuthTypeUserAssignedManagedIdentity AuthType = "userAssignedManagedIdentity"
)

func GetAuthTypeDescription(authType AuthType) string {
switch authType {
case AuthTypeUnspecified:
return "Unspecified"
case AuthTypePassword:
return "Username and password"
case AuthTypeConnectionString:
return "Connection string"
case AuthTypeUserAssignedManagedIdentity:
return "User assigned managed identity"
default:
return "Unspecified"
}
}
53 changes: 53 additions & 0 deletions cli/azd/internal/repository/app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var dbMap = map[appdetect.DatabaseDep]struct{}{

var featureCompose = alpha.MustFeatureKey("compose")

var azureDepMap = map[string]struct{}{
appdetect.AzureDepServiceBus{}.ResourceDisplay(): {},
}

// InitFromApp initializes the infra directory and project file from the current existing app.
func (i *Initializer) InitFromApp(
ctx context.Context,
Expand Down Expand Up @@ -455,6 +459,29 @@ func (i *Initializer) prjConfigFromDetect(
dbNames[database] = db.Name
}

for _, azureDepPair := range detect.AzureDeps {
azureDep := azureDepPair.first
authType, err := chooseAuthTypeByPrompt(
azureDep.ResourceDisplay(),
[]internal.AuthType{internal.AuthTypeUserAssignedManagedIdentity, internal.AuthTypeConnectionString},
ctx,
i.console)
if err != nil {
return config, err
}
switch azureDep := azureDep.(type) {
case appdetect.AzureDepServiceBus:
config.Resources["servicebus"] = &project.ResourceConfig{
Type: project.ResourceTypeMessagingServiceBus,
Props: project.ServiceBusProps{
Queues: azureDep.Queues,
IsJms: azureDep.IsJms,
AuthType: authType,
},
}
}
}

backends := []*project.ResourceConfig{}
frontends := []*project.ResourceConfig{}

Expand Down Expand Up @@ -483,6 +510,13 @@ func (i *Initializer) prjConfigFromDetect(
resSpec.Uses = append(resSpec.Uses, dbNames[db])
}

for _, azureDep := range svc.AzureDeps {
switch azureDep.(type) {
case appdetect.AzureDepServiceBus:
resSpec.Uses = append(resSpec.Uses, "servicebus")
}
}

resSpec.Name = name
resSpec.Props = props
config.Resources[name] = &resSpec
Expand Down Expand Up @@ -578,3 +612,22 @@ func ServiceFromDetect(

return svc, nil
}

func chooseAuthTypeByPrompt(
name string,
authOptions []internal.AuthType,
ctx context.Context,
console input.Console) (internal.AuthType, error) {
var options []string
for _, option := range authOptions {
options = append(options, internal.GetAuthTypeDescription(option))
}
selection, err := console.Select(ctx, input.ConsoleOptions{
Message: "Choose auth type for " + name + ":",
Options: options,
})
if err != nil {
return internal.AuthTypeUnspecified, err
}
return authOptions[selection], nil
}
112 changes: 112 additions & 0 deletions cli/azd/internal/repository/app_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,118 @@ func TestInitializer_prjConfigFromDetect(t *testing.T) {
},
},
},
{
name: "api with service bus umi",
detect: detectConfirm{
Services: []appdetect.Project{
{
Language: appdetect.Java,
Path: "java",
AzureDeps: []appdetect.AzureDep{
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
},
},
},
},
AzureDeps: map[string]Pair{
appdetect.AzureDepServiceBus{}.ResourceDisplay(): {
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
}, EntryKindDetected,
},
},
},
interactions: []string{
// prompt for auth type
"User assigned managed identity",
},
want: project.ProjectConfig{
Services: map[string]*project.ServiceConfig{
"java": {
Language: project.ServiceLanguageJava,
Host: project.ContainerAppTarget,
RelativePath: "java",
},
},
Resources: map[string]*project.ResourceConfig{
"java": {
Type: project.ResourceTypeHostContainerApp,
Name: "java",
Props: project.ContainerAppProps{
Port: 8080,
},
Uses: []string{"servicebus"},
},
"servicebus": {
Type: project.ResourceTypeMessagingServiceBus,
Props: project.ServiceBusProps{
Queues: []string{"queue1"},
IsJms: true,
AuthType: internal.AuthTypeUserAssignedManagedIdentity,
},
},
},
},
},
{
name: "api with service bus connection string",
detect: detectConfirm{
Services: []appdetect.Project{
{
Language: appdetect.Java,
Path: "java",
AzureDeps: []appdetect.AzureDep{
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
},
},
},
},
AzureDeps: map[string]Pair{
appdetect.AzureDepServiceBus{}.ResourceDisplay(): {
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
}, EntryKindDetected,
},
},
},
interactions: []string{
// prompt for auth type
"Connection string",
},
want: project.ProjectConfig{
Services: map[string]*project.ServiceConfig{
"java": {
Language: project.ServiceLanguageJava,
Host: project.ContainerAppTarget,
RelativePath: "java",
},
},
Resources: map[string]*project.ResourceConfig{
"java": {
Type: project.ResourceTypeHostContainerApp,
Name: "java",
Props: project.ContainerAppProps{
Port: 8080,
},
Uses: []string{"servicebus"},
},
"servicebus": {
Type: project.ResourceTypeMessagingServiceBus,
Props: project.ServiceBusProps{
Queues: []string{"queue1"},
IsJms: true,
AuthType: internal.AuthTypeConnectionString,
},
},
},
},
},
{
name: "api and web",
detect: detectConfirm{
Expand Down
13 changes: 13 additions & 0 deletions cli/azd/internal/repository/detect_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ const (
EntryKindModified EntryKind = "modified"
)

type Pair struct {
first appdetect.AzureDep
second EntryKind
}

// detectConfirm handles prompting for confirming the detected services and databases
type detectConfirm struct {
// detected services and databases
Services []appdetect.Project
Databases map[appdetect.DatabaseDep]EntryKind
AzureDeps map[string]Pair

// the root directory of the project
root string
Expand All @@ -59,6 +65,7 @@ type detectConfirm struct {
// Init initializes state from initial detection output
func (d *detectConfirm) Init(projects []appdetect.Project, root string) {
d.Databases = make(map[appdetect.DatabaseDep]EntryKind)
d.AzureDeps = make(map[string]Pair)
d.Services = make([]appdetect.Project, 0, len(projects))
d.modified = false
d.root = root
Expand All @@ -73,6 +80,12 @@ func (d *detectConfirm) Init(projects []appdetect.Project, root string) {
d.Databases[dbType] = EntryKindDetected
}
}

for _, azureDep := range project.AzureDeps {
if _, supported := azureDepMap[azureDep.ResourceDisplay()]; supported {
d.AzureDeps[azureDep.ResourceDisplay()] = Pair{azureDep, EntryKindDetected}
}
}
}

d.captureUsage(
Expand Down
30 changes: 30 additions & 0 deletions cli/azd/internal/repository/detect_confirm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ func Test_detectConfirm_confirm(t *testing.T) {
},
},
},
{
name: "confirm single with resources service bus",
detection: []appdetect.Project{
{
Language: appdetect.Java,
Path: javaDir,
AzureDeps: []appdetect.AzureDep{
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
},
},
},
},
interactions: []string{
"Confirm and continue initializing my app",
},
want: []appdetect.Project{
{
Language: appdetect.Java,
Path: javaDir,
AzureDeps: []appdetect.AzureDep{
appdetect.AzureDepServiceBus{
Queues: []string{"queue1"},
IsJms: true,
},
},
},
},
},
{
name: "add a language",
detection: []appdetect.Project{
Expand Down
Loading