From 3d6d7611efecdcd6d3d8d6f78262f7bdeee585d9 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Wed, 30 Nov 2022 02:30:48 +0000 Subject: [PATCH 1/2] Update for Functions GA --- pages_deployment_test.go | 65 ++--------------------------- pages_project.go | 61 +++++++++++++++++++++------ pages_project_test.go | 90 ++++++++++++++++++++++++++++++++-------- 3 files changed, 123 insertions(+), 93 deletions(-) diff --git a/pages_deployment_test.go b/pages_deployment_test.go index 9696d7438..282710a0c 100644 --- a/pages_deployment_test.go +++ b/pages_deployment_test.go @@ -91,54 +91,6 @@ const ( "aliases": null }` - testPagesDeploymentStageLogsResponse = ` - { - "name": "build", - "started_on": "2021-01-01T00:00:00Z", - "ended_on": "2021-01-01T00:00:00Z", - "status": "success", - "start": 0, - "end": 5, - "total": 6, - "data": [ - { - "id": 0, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Installing dependencies" - }, - { - "id": 1, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Verify run directory" - }, - { - "id": 2, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Executing user command: bash test.sh" - }, - { - "id": 3, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Finished" - }, - { - "id": 4, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Building functions..." - }, - { - "id": 5, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Validating asset output directory" - }, - { - "id": 6, - "timestamp": "2021-01-01T00:00:00Z", - "message": "Parsed 2 valid header rules." - } - ] - }` - testPagesDeploymentLogsResponse = ` { "total": 6, @@ -190,9 +142,9 @@ var ( ModifiedOn: &pagesDeploymentDummyTime, Aliases: nil, LatestStage: *expectedPagesDeploymentLatestStage, - EnvVars: map[string]map[string]string{ - "NODE_VERSION": { - "value": "16", + EnvVars: EnvironmentVariableMap{ + "NODE_VERSION": &EnvironmentVariable{ + Value: "16", }, }, DeploymentTrigger: PagesProjectDeploymentTrigger{ @@ -255,17 +207,6 @@ var ( Status: "success", } - expectedPagesDeploymentStageLogs = &PagesDeploymentStageLogs{ - Name: "build", - StartedOn: &pagesDeploymentDummyTime, - EndedOn: &pagesDeploymentDummyTime, - Status: "success", - Start: 0, - End: 5, - Total: 6, - Data: expectedPagesDeploymentStageLogEntries, - } - expectedPagesDeploymentStageLogEntries = []PagesDeploymentStageLogEntry{ { ID: 0, diff --git a/pages_project.go b/pages_project.go index 753c1eb8d..3177a8e0f 100644 --- a/pages_project.go +++ b/pages_project.go @@ -67,18 +67,17 @@ type PagesProjectDeploymentConfigs struct { // PagesProjectDeploymentConfigEnvironment represents the configuration for preview or production deploys. type PagesProjectDeploymentConfigEnvironment struct { - EnvVars map[string]PagesProjectDeploymentVar `json:"env_vars"` - CompatibilityDate string `json:"compatibility_date,omitempty"` - CompatibilityFlags []string `json:"compatibility_flags,omitempty"` - KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"` - DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"` - D1Databases D1BindingMap `json:"d1_databases,omitempty"` - R2Bindings R2BindingMap `json:"r2_buckets,omitempty"` -} - -// PagesProjectDeploymentVar represents a deployment environment variable. -type PagesProjectDeploymentVar struct { - Value string `json:"value"` + EnvVars EnvironmentVariableMap `json:"env_vars,omitempty"` + KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"` + DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"` + D1Databases D1BindingMap `json:"d1_databases,omitempty"` + R2Bindings R2BindingMap `json:"r2_buckets,omitempty"` + ServiceBindings ServiceBindingMap `json:"services,omitempty"` + CompatibilityDate string `json:"compatibility_date,omitempty"` + CompatibilityFlags []string `json:"compatibility_flags,omitempty"` + FailOpen bool `json:"fail_open"` + AlwaysUseLatestCompatibilityDate bool `json:"always_use_latest_compatibility_date"` + UsageModel UsageModel `json:"usage_model,omitempty"` } // PagesProjectDeployment represents a deployment to a Pages project. @@ -93,13 +92,20 @@ type PagesProjectDeployment struct { ModifiedOn *time.Time `json:"modified_on"` Aliases []string `json:"aliases,omitempty"` LatestStage PagesProjectDeploymentStage `json:"latest_stage"` - EnvVars map[string]map[string]string `json:"env_vars"` + EnvVars EnvironmentVariableMap `json:"env_vars"` + KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"` + DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"` + D1Databases D1BindingMap `json:"d1_databases,omitempty"` + R2Bindings R2BindingMap `json:"r2_buckets,omitempty"` + ServiceBindings ServiceBindingMap `json:"services,omitempty"` DeploymentTrigger PagesProjectDeploymentTrigger `json:"deployment_trigger"` Stages []PagesProjectDeploymentStage `json:"stages"` BuildConfig PagesProjectBuildConfig `json:"build_config"` Source PagesProjectSource `json:"source"` CompatibilityDate string `json:"compatibility_date,omitempty"` CompatibilityFlags []string `json:"compatibility_flags,omitempty"` + UsageModel UsageModel `json:"usage_model,omitempty"` + IsSkipped bool `json:"is_skipped"` ProductionBranch string `json:"production_branch,omitempty"` } @@ -135,6 +141,21 @@ type pagesProjectListResponse struct { ResultInfo `json:"result_info"` } +type EnvironmentVariableMap map[string]*EnvironmentVariable + +// PagesProjectDeploymentVar represents a deployment environment variable. +type EnvironmentVariable struct { + Value string `json:"value"` + Type EnvVarType `json:"type"` +} + +type EnvVarType string + +const ( + PlainText EnvVarType = "plain_text" + SecretText EnvVarType = "secret_text" +) + type NamespaceBindingMap map[string]*NamespaceBindingValue type NamespaceBindingValue struct { @@ -153,6 +174,20 @@ type D1Binding struct { ID string `json:"id"` } +type ServiceBindingMap map[string]*ServiceBinding + +type ServiceBinding struct { + Service string `json:"service"` + Environment string `json:"environment"` +} + +type UsageModel string + +const ( + Bundled UsageModel = "bundled" + Unbound UsageModel = "unbound" +) + // ListPagesProjects returns all Pages projects for an account. // // API reference: https://api.cloudflare.com/#pages-project-get-projects diff --git a/pages_project_test.go b/pages_project_test.go index 0dffd3c30..91671a5d5 100644 --- a/pages_project_test.go +++ b/pages_project_test.go @@ -58,7 +58,11 @@ const ( }, "ENV": { "value": "preview" - } + }, + "API_KEY": { + "value": "", + "type": "secret_text" + } }, "compatibility_date": "2022-08-15", "compatibility_flags": ["preview_flag"] @@ -70,7 +74,11 @@ const ( }, "ENV": { "value": "production" - } + }, + "API_KEY": { + "value": "", + "type": "secret_text" + } }, "d1_databases": { "D1_BINDING": { @@ -92,8 +100,17 @@ const ( "name": "some-bucket" } }, + "services": { + "SERVICE_BINDING": { + "service": "some-worker", + "environment": "production" + } + }, "compatibility_date": "2022-08-15", - "compatibility_flags": ["production_flag"] + "compatibility_flags": ["production_flag"], + "fail_open": false, + "always_use_latest_compatibility_date": false, + "usage_model": "bundled" } }, "latest_deployment": { @@ -121,10 +138,17 @@ const ( }, "ENV": { "value": "STAGING" - } + }, + "API_KEY": { + "value": "", + "type": "secret_text" + } }, "compatibility_date": "2022-08-15", "compatibility_flags": ["deployment_flag"], + "fail_open": false, + "always_use_latest_compatibility_date": false, + "usage_model": "bundled", "deployment_trigger": { "type": "ad_hoc", "metadata": { @@ -201,10 +225,18 @@ const ( }, "ENV": { "value": "STAGING" - } + }, + "API_KEY": { + "value": "", + "type": "secret_text" + } }, "compatibility_date": "2022-08-15", "compatibility_flags": ["deployment_flag"], + "fail_open": false, + "always_use_latest_compatibility_date": false, + "build_image_major_version": 1, + "usage_model": "bundled", "deployment_trigger": { "type": "ad_hoc", "metadata": { @@ -295,16 +327,21 @@ var ( "https://branchname.pages-test.pages.dev", }, LatestStage: *expectedPagesProjectLatestDeploymentStage, - EnvVars: map[string]map[string]string{ - "BUILD_VERSION": { - "value": "1.2", + EnvVars: EnvironmentVariableMap{ + "BUILD_VERSION": &EnvironmentVariable{ + Value: "1.2", + }, + "ENV": &EnvironmentVariable{ + Value: "STAGING", }, - "ENV": { - "value": "STAGING", + "API_KEY": &EnvironmentVariable{ + Value: "", + Type: SecretText, }, }, CompatibilityFlags: []string{"deployment_flag"}, CompatibilityDate: "2022-08-15", + UsageModel: Bundled, DeploymentTrigger: *expectedPagesProjectDeploymentTrigger, Stages: expectedStages, BuildConfig: *expectedPagesProjectBuildConfig, @@ -363,29 +400,35 @@ var ( } expectedPagesProjectDeploymentConfigPreview = &PagesProjectDeploymentConfigEnvironment{ - EnvVars: map[string]PagesProjectDeploymentVar{ - "BUILD_VERSION": { + EnvVars: EnvironmentVariableMap{ + "BUILD_VERSION": &EnvironmentVariable{ Value: "1.2", }, - "ENV": { + "ENV": &EnvironmentVariable{ Value: "preview", }, + "API_KEY": &EnvironmentVariable{ + Value: "", + Type: SecretText, + }, }, CompatibilityDate: "2022-08-15", CompatibilityFlags: []string{"preview_flag"}, } expectedPagesProjectDeploymentConfigProduction = &PagesProjectDeploymentConfigEnvironment{ - EnvVars: map[string]PagesProjectDeploymentVar{ - "BUILD_VERSION": { + EnvVars: EnvironmentVariableMap{ + "BUILD_VERSION": &EnvironmentVariable{ Value: "1.2", }, - "ENV": { + "ENV": &EnvironmentVariable{ Value: "production", }, + "API_KEY": &EnvironmentVariable{ + Value: "", + Type: SecretText, + }, }, - CompatibilityDate: "2022-08-15", - CompatibilityFlags: []string{"production_flag"}, KvNamespaces: NamespaceBindingMap{ "KV_BINDING": &NamespaceBindingValue{Value: "5eb63bbbe01eeed093cb22bb8f5acdc3"}, }, @@ -398,6 +441,17 @@ var ( R2Bindings: R2BindingMap{ "R2_BINDING": &R2BindingValue{Name: "some-bucket"}, }, + ServiceBindings: ServiceBindingMap{ + "SERVICE_BINDING": &ServiceBinding{ + Service: "some-worker", + Environment: "production", + }, + }, + CompatibilityDate: "2022-08-15", + CompatibilityFlags: []string{"production_flag"}, + FailOpen: false, + AlwaysUseLatestCompatibilityDate: false, + UsageModel: Bundled, } expectedPagesProjectSource = &PagesProjectSource{ From 3c5cdcc66798bebc7c606537a7e8345d97ba2821 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Wed, 30 Nov 2022 02:37:44 +0000 Subject: [PATCH 2/2] Changelog --- .changelog/1136.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/1136.txt diff --git a/.changelog/1136.txt b/.changelog/1136.txt new file mode 100644 index 000000000..976f76ea7 --- /dev/null +++ b/.changelog/1136.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +pages: Updates bindings and other Functions related propreties. Service bindings, secrets, fail open/close and usage model are all now supported. +``` + +```release-note:breaking-change +pages: Changed the type of EnvVars in PagesProjectDeploymentConfigEnvironment & PagesProjectDeployment in order to properly support secrets. +```