Skip to content
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions cli/azd/.vscode/cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ words:
- unmarshals
- usgovcloudapi
- jdbc
- bicept
- springframework
languageSettings:
- languageId: go
ignoreRegExpList:
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,13 @@ func showModelDeployment(
if account.Properties.Endpoint != nil {
console.Message(ctx, color.HiMagentaString("%s (Azure AI Services Model Deployment)", id.Name))
console.Message(ctx, " Endpoint:")
console.Message(ctx, color.HiBlueString(fmt.Sprintf(" AZURE_OPENAI_ENDPOINT=%s", *account.Properties.Endpoint)))
console.Message(ctx,
color.HiBlueString(fmt.Sprintf(" %s=%s", internal.EnvNameAzureOpenAiUrl, *account.Properties.Endpoint)))
console.Message(ctx, " Access:")
console.Message(ctx, " Keyless (Microsoft Entra ID)")
//nolint:lll
console.Message(ctx, output.WithGrayFormat(" Hint: To access locally, use DefaultAzureCredential. To learn more, visit https://learn.microsoft.com/en-us/azure/ai-services/openai/supported-languages"))

console.Message(ctx, output.WithGrayFormat(" Hint: To access locally, use DefaultAzureCredential. "+
"To learn more, visit https://learn.microsoft.com/en-us/azure/ai-services/openai/supported-languages"))
console.Message(ctx, "")
}

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 @@ -103,6 +103,21 @@ func (f Dependency) IsWebUIFramework() bool {
return false
}

type RawDependency struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easier, we can just return the RawProject pom.xml representation and let the "app generation" part decide what to do with that information. I think we want to avoid having additional schema translations

Kind RawDependencyKind
Name string
Version string
}

type RawDependencyKind string

const RawDependencyKindMaven RawDependencyKind = "maven"
const MavenDependencyNameMySqlConnectorJ = "com.mysql:mysql-connector-j"
const MavenDependencyNamePostgresql = "org.postgresql:postgresql"
const MavenDependencyNameSpringCloudAzureStarterJdbcPostgresql = "com.azure.spring:" +
"spring-cloud-azure-starter-jdbc-postgresql"
const MavenDependencyNameSpringBootMavenPlugin = "org.springframework.boot:spring-boot-maven-plugin"

// A type of database that is inferred through heuristics while scanning project information.
type DatabaseDep string

Expand Down Expand Up @@ -139,6 +154,9 @@ type Project struct {
// Dependencies scanned in the project.
Dependencies []Dependency

// RawDependencies scanned in the project.
RawDependencies []RawDependency

// Experimental: Database dependencies inferred through heuristics while scanning dependencies in the project.
DatabaseDeps []DatabaseDep

Expand Down
68 changes: 68 additions & 0 deletions cli/azd/internal/appdetect/appdetect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ func TestDetect(t *testing.T) {
DbMySql,
DbPostgres,
},
RawDependencies: []RawDependency{
{
Kind: RawDependencyKindMaven,
Name: "com.mysql:mysql-connector-j",
Version: "8.3.0",
},
{
Kind: RawDependencyKindMaven,
Name: "org.postgresql:postgresql",
Version: "42.7.3",
},
{
Kind: RawDependencyKindMaven,
Name: "org.springframework.boot:spring-boot-maven-plugin",
Version: "3.3.0",
},
},
},
{
Language: Java,
Expand Down Expand Up @@ -136,6 +153,23 @@ func TestDetect(t *testing.T) {
DbMySql,
DbPostgres,
},
RawDependencies: []RawDependency{
{
Kind: RawDependencyKindMaven,
Name: "com.mysql:mysql-connector-j",
Version: "8.3.0",
},
{
Kind: RawDependencyKindMaven,
Name: "org.postgresql:postgresql",
Version: "42.7.3",
},
{
Kind: RawDependencyKindMaven,
Name: "org.springframework.boot:spring-boot-maven-plugin",
Version: "3.3.0",
},
},
},
{
Language: Java,
Expand Down Expand Up @@ -169,6 +203,23 @@ func TestDetect(t *testing.T) {
DbMySql,
DbPostgres,
},
RawDependencies: []RawDependency{
{
Kind: RawDependencyKindMaven,
Name: "com.mysql:mysql-connector-j",
Version: "8.3.0",
},
{
Kind: RawDependencyKindMaven,
Name: "org.postgresql:postgresql",
Version: "42.7.3",
},
{
Kind: RawDependencyKindMaven,
Name: "org.springframework.boot:spring-boot-maven-plugin",
Version: "3.3.0",
},
},
},
{
Language: Java,
Expand Down Expand Up @@ -205,6 +256,23 @@ func TestDetect(t *testing.T) {
DbMySql,
DbPostgres,
},
RawDependencies: []RawDependency{
{
Kind: RawDependencyKindMaven,
Name: "com.mysql:mysql-connector-j",
Version: "8.3.0",
},
{
Kind: RawDependencyKindMaven,
Name: "org.postgresql:postgresql",
Version: "42.7.3",
},
{
Kind: RawDependencyKindMaven,
Name: "org.springframework.boot:spring-boot-maven-plugin",
Version: "3.3.0",
},
},
},
{
Language: Java,
Expand Down
24 changes: 19 additions & 5 deletions cli/azd/internal/appdetect/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,35 @@ func readMavenProject(ctx context.Context, mvnCli *maven.Cli, filePath string) (
func detectDependencies(mavenProject *mavenProject, project *Project) (*Project, error) {
databaseDepMap := map[DatabaseDep]struct{}{}
for _, dep := range mavenProject.Dependencies {
if dep.GroupId == "com.mysql" && dep.ArtifactId == "mysql-connector-j" {
name := toDependencyName(dep.GroupId, dep.ArtifactId)
switch name {
case MavenDependencyNameMySqlConnectorJ:
databaseDepMap[DbMySql] = struct{}{}
}

if dep.GroupId == "org.postgresql" && dep.ArtifactId == "postgresql" {
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
case MavenDependencyNamePostgresql, MavenDependencyNameSpringCloudAzureStarterJdbcPostgresql:
databaseDepMap[DbPostgres] = struct{}{}
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
}
}

if len(databaseDepMap) > 0 {
project.DatabaseDeps = slices.SortedFunc(maps.Keys(databaseDepMap),
func(a, b DatabaseDep) int {
return strings.Compare(string(a), string(b))
})
}
for _, dep := range mavenProject.Build.Plugins {
name := toDependencyName(dep.GroupId, dep.ArtifactId)
if name == MavenDependencyNameSpringBootMavenPlugin {
project.RawDependencies = append(project.RawDependencies,
RawDependency{RawDependencyKindMaven, name, dep.Version})
}
}

return project, nil
}

func toDependencyName(groupId string, artifactId string) string {
return groupId + ":" + artifactId
}
3 changes: 3 additions & 0 deletions cli/azd/internal/appdetect/java_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package appdetect

import (
Expand Down
27 changes: 14 additions & 13 deletions cli/azd/internal/cmd/add/add_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"text/tabwriter"

"github.com/azure/azure-dev/cli/azd/internal"
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
"github.com/azure/azure-dev/cli/azd/pkg/input"
"github.com/azure/azure-dev/cli/azd/pkg/output"
Expand Down Expand Up @@ -41,31 +42,31 @@ func Metadata(r *project.ResourceConfig) resourceMeta {
case project.ResourceTypeDbRedis:
res.AzureResourceType = "Microsoft.Cache/redis"
res.UseEnvVars = []string{
"REDIS_HOST",
"REDIS_PORT",
"REDIS_ENDPOINT",
"REDIS_PASSWORD",
"REDIS_URL",
internal.EnvNameRedisHost,
internal.EnvNameRedisPort,
internal.EnvNameRedisEndpoint,
internal.EnvNameRedisPassword,
internal.EnvNameRedisUrl,
}
case project.ResourceTypeDbPostgres:
res.AzureResourceType = "Microsoft.DBforPostgreSQL/flexibleServers/databases"
res.UseEnvVars = []string{
"POSTGRES_HOST",
"POSTGRES_USERNAME",
"POSTGRES_DATABASE",
"POSTGRES_PASSWORD",
"POSTGRES_PORT",
"POSTGRES_URL",
internal.EnvNamePostgresHost,
internal.EnvNamePostgresUsername,
internal.EnvNamePostgresDatabase,
internal.EnvNamePostgresPassword,
internal.EnvNamePostgresPort,
internal.EnvNamePostgresUrl,
}
case project.ResourceTypeDbMongo:
res.AzureResourceType = "Microsoft.DocumentDB/databaseAccounts/mongodbDatabases"
res.UseEnvVars = []string{
"MONGODB_URL",
internal.EnvNameMongoDbUrl,
}
case project.ResourceTypeOpenAiModel:
res.AzureResourceType = "Microsoft.CognitiveServices/accounts/deployments"
res.UseEnvVars = []string{
"AZURE_OPENAI_ENDPOINT",
internal.EnvNameAzureOpenAiUrl,
}
}
return res
Expand Down
29 changes: 29 additions & 0 deletions cli/azd/internal/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package internal

// todo: keep single source for env name in go lang code and resources.bicept

const EnvNamePostgresHost = "POSTGRES_HOST"
const EnvNamePostgresPort = "POSTGRES_PORT"
const EnvNamePostgresUrl = "POSTGRES_URL"
const EnvNamePostgresDatabase = "POSTGRES_DATABASE"
const EnvNamePostgresUsername = "POSTGRES_USERNAME"

// nolint:gosec
const EnvNamePostgresPassword = "POSTGRES_PASSWORD"

const EnvNameRedisHost = "REDIS_HOST"
const EnvNameRedisPort = "REDIS_PORT"
const EnvNameRedisEndpoint = "REDIS_ENDPOINT"
const EnvNameRedisPassword = "REDIS_PASSWORD"
const EnvNameRedisUrl = "REDIS_URL"

const EnvNameMongoDbUrl = "MONGODB_URL"

const EnvNameAzureOpenAiUrl = "AZURE_OPENAI_ENDPOINT"

func ToEnvPlaceHolder(envName string) string {
return "${" + envName + "}"
}
Loading