From d9a17f17ce7a7ddd114289fc85cb388e988f816c Mon Sep 17 00:00:00 2001
From: Arjun Sreedharan <asreedharan@vmware.com>
Date: Thu, 26 Oct 2023 23:28:50 +0000
Subject: [PATCH] support integration with python family buildpacks

This change will help apps build with python-family paketo buildpacks
to use the dynatrace buildpack.

The new buildplan integrates with cpython's "provides cpython" contract.
(https://github.com/paketo-buildpacks/cpython/blob/v1.10.0/detect.go#L70-L73)
---
 README.md         | 2 +-
 buildpack.toml    | 2 +-
 dt/build.go       | 2 +-
 dt/detect.go      | 9 +++++++++
 dt/detect_test.go | 9 +++++++++
 5 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index d87dcd0..8d45cd5 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ The binding must include the following required Secret values to successfully co
 the API URL and API token secret keys support multiple casing options for ease of integration.
 This buildpack will choose to use `api-url` over `apiurl` and `api-token` over `apitoken` if both are set.
 
-The buildpack will do the following for .NET, Go, Apache HTTPd, Java, Nginx, NodeJS, and PHP applications:
+The buildpack will do the following for .NET, Go, Apache HTTPD, Java, Nginx, NodeJS, PHP and Python applications:
 
 * Contributes a OneAgent including the appropriate libraries to a layer and configures `$LD_PRELOAD` to use it
 * Sets `$DT_TENANT`, `$DT_TENANTTOKEN`, and `$DT_CONNECTION_POINT` at launch time.
diff --git a/buildpack.toml b/buildpack.toml
index 3a8755e..c94961b 100644
--- a/buildpack.toml
+++ b/buildpack.toml
@@ -18,7 +18,7 @@ api = "0.7"
   description = "A Cloud Native Buildpack that contributes the Dynatrace OneAgent and configures it to connect to the service"
   homepage = "https://github.com/paketo-buildpacks/dynatrace"
   id = "paketo-buildpacks/dynatrace"
-  keywords = ["dynatrace", "agent", "one-agent", "apm", "java", "node.js", "go", "apache-httpd", "nginx", "php", "dotnet"]
+  keywords = ["dynatrace", "agent", "one-agent", "apm", "java", "node.js", "go", "apache-httpd", "nginx", "php", "dotnet", "python"]
   name = "Paketo Buildpack for Dynatrace"
   sbom-formats = ["application/vnd.syft+json", "application/vnd.cyclonedx+json"]
   version = "{{.version}}"
diff --git a/dt/build.go b/dt/build.go
index b2e16b0..3448daf 100644
--- a/dt/build.go
+++ b/dt/build.go
@@ -55,7 +55,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
 
 	uri := fmt.Sprintf("%s/v1/deployment/installer/agent/unix/paas/latest?bitness=64&skipMetadata=true", BaseURI(s))
 
-	for _, t := range []string{"apache", "dotnet", "go", "java", "nginx", "nodejs", "php"} {
+	for _, t := range []string{"apache", "dotnet", "go", "java", "nginx", "nodejs", "php", "python"} {
 		if _, ok, err := pr.Resolve(fmt.Sprintf("dynatrace-%s", t)); err != nil {
 			return libcnb.BuildResult{}, fmt.Errorf("unable to resolve dynatrace-%s plan entry\n%w", t, err)
 		} else if ok {
diff --git a/dt/detect.go b/dt/detect.go
index 8803ab2..9d26ef0 100644
--- a/dt/detect.go
+++ b/dt/detect.go
@@ -115,6 +115,15 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
 					{Name: "php"},
 				},
 			},
+			{
+				Provides: []libcnb.BuildPlanProvide{
+					{Name: "dynatrace-python"},
+				},
+				Requires: []libcnb.BuildPlanRequire{
+					{Name: "dynatrace-python"},
+					{Name: "cpython"},
+				},
+			},
 		},
 	}, nil
 }
diff --git a/dt/detect_test.go b/dt/detect_test.go
index 093275a..48fd0fa 100644
--- a/dt/detect_test.go
+++ b/dt/detect_test.go
@@ -104,6 +104,15 @@ var expectedResult = libcnb.DetectResult{
 				{Name: "php"},
 			},
 		},
+		{
+			Provides: []libcnb.BuildPlanProvide{
+				{Name: "dynatrace-python"},
+			},
+			Requires: []libcnb.BuildPlanRequire{
+				{Name: "dynatrace-python"},
+				{Name: "cpython"},
+			},
+		},
 	},
 }