Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

app: addcors_behavior attribute#309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
dannykopping wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromdk/cors
Draft
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionsdocs/resources/app.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@ resource "coder_app" "vim" {
### Optional

- `command` (String) A command to run in a terminal opening this app. In the web, this will open in a new tab. In the CLI, this will SSH and execute the command. Either `command` or `url` may be specified, but not both.
- `cors_behavior` (String)
- `display_name` (String) A display name to identify the app. Defaults to the slug.
- `external` (Boolean) Specifies whether `url` is opened on the client machine instead of proxied through the workspace.
- `healthcheck` (Block Set, Max: 1) HTTP health checking to determine the application readiness. (see [below for nested schema](#nestedblock--healthcheck))
Expand Down
19 changes: 19 additions & 0 deletionsprovider/app.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,6 +162,25 @@ func appResource() *schema.Resource {
return diag.Errorf("invalid app share %q, must be one of \"owner\", \"authenticated\", \"public\"", valStr)
},
},
"cors_behavior": {
Type: schema.TypeString,
Default: "simple",
ForceNew: true,
Optional: true,
ValidateDiagFunc: func(val interface{}, c cty.Path) diag.Diagnostics {
valStr, ok := val.(string)
if !ok {
return diag.Errorf("expected string, got %T", val)
}

switch valStr {
case "simple", "passthru":
return nil
}

return diag.Errorf("invalid app CORS behavior %q, must be one of \"simple\", \"passthru\"", valStr)
},
},
"url": {
Type: schema.TypeString,
Description: "An external url if `external=true` or a URL to be proxied to from inside the workspace. " +
Expand Down
59 changes: 59 additions & 0 deletionsprovider/app_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -309,4 +309,63 @@ func TestApp(t *testing.T) {
}
})

t.Run("CORS Behavior", func(t *testing.T) {
t.Parallel()

baseConfig := `
provider "coder" {}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
}
resource "coder_app" "test" {
agent_id = coder_agent.dev.id
slug = "test"
display_name = "Testing"
url = "https://google.com"
external = true
%s
}`

cases := []struct {
name string
config string
behavior string
}{{
name: "Default CORS",
config: fmt.Sprintf(baseConfig, ""),
behavior: "simple",
}, {
name: "Simple CORS",
config: fmt.Sprintf(baseConfig, "cors_behavior = \"simple\""),
behavior: "simple",
}, {
name: "Passthru CORS",
config: fmt.Sprintf(baseConfig, "cors_behavior = \"passthru\""),
behavior: "passthru",
}}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: tc.config,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 2)
resource := state.Modules[0].Resources["coder_app.test"]
require.NotNil(t, resource)
require.Equal(t, tc.behavior, resource.Primary.Attributes["cors_behavior"])
return nil
},
ExpectError: nil,
}},
})
})
}
})

}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp