fix(jetbrains-gateway): use magic string for session token (#53)
* fix(jetbrains-gateway): use magic string for session token * refactor * improve default logic * fmt
This commit is contained in:
committed by
GitHub
parent
83a4e40a6d
commit
1b83ae6f92
@@ -11,6 +11,16 @@ tags: [ide, jetbrains, helper, parameter]
|
||||
|
||||
This module adds a JetBrains Gateway Button to open any workspace with a single click.
|
||||
|
||||
```hcl
|
||||
module "jetbrains_gateway" {
|
||||
source = "https://registry.coder.com/modules/jetbrains-gateway"
|
||||
agent_id = coder_agent.example.id
|
||||
agent_name = "example"
|
||||
project_directory = "/home/coder/example"
|
||||
jetbrains_ides = ["GO", "WS", "IU", "IC", "PY", "PC", "PS", "CL", "RM", "DB", "RD"]
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Examples
|
||||
|
||||
@@ -25,6 +25,7 @@ variable "project_directory" {
|
||||
}
|
||||
|
||||
variable "default" {
|
||||
default = null
|
||||
type = string
|
||||
description = "Default IDE"
|
||||
}
|
||||
@@ -40,6 +41,16 @@ variable "jetbrains_ides" {
|
||||
)
|
||||
error_message = "The jetbrains_ides must be a list of valid product codes. https://plugins.jetbrains.com/docs/marketplace/product-codes.html"
|
||||
}
|
||||
# check if the list is empty
|
||||
validation {
|
||||
condition = length(var.jetbrains_ides) > 0
|
||||
error_message = "The jetbrains_ides must not be empty."
|
||||
}
|
||||
#ccheck if the list contains duplicates
|
||||
validation {
|
||||
condition = length(var.jetbrains_ides) == length(set(var.jetbrains_ides))
|
||||
error_message = "The jetbrains_ides must not contain duplicates."
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
@@ -108,7 +119,8 @@ data "coder_parameter" "jetbrains_ide" {
|
||||
display_name = "JetBrains IDE"
|
||||
icon = "/icon/gateway.svg"
|
||||
mutable = true
|
||||
default = var.default != null && var.default != "" ? local.jetbrains_ides[var.default].value : null
|
||||
# check if default is in the jet_brains_ides list and if it is not empty or null otherwise set it to null
|
||||
default = contains(var.jetbrains_ides.keys, var.default) && var.default != null && var.default != "" ? var.default : null
|
||||
|
||||
dynamic "option" {
|
||||
for_each = { for key, value in local.jetbrains_ides : key => value if contains(var.jetbrains_ides, key) }
|
||||
@@ -126,9 +138,26 @@ resource "coder_app" "gateway" {
|
||||
agent_id = var.agent_id
|
||||
display_name = data.coder_parameter.jetbrains_ide.option[index(data.coder_parameter.jetbrains_ide.option.*.value, data.coder_parameter.jetbrains_ide.value)].name
|
||||
slug = "gateway"
|
||||
url = "jetbrains-gateway://connect#type=coder&workspace=${data.coder_workspace.me.name}&agent=${var.agent_name}&folder=${var.project_directory}&url=${data.coder_workspace.me.access_url}&token=${data.coder_workspace.me.owner_session_token}&ide_product_code=${jsondecode(data.coder_parameter.jetbrains_ide.value)[0]}&ide_build_number=${jsondecode(data.coder_parameter.jetbrains_ide.value)[1]}&ide_download_link=${jsondecode(data.coder_parameter.jetbrains_ide.value)[2]}"
|
||||
icon = data.coder_parameter.jetbrains_ide.option[index(data.coder_parameter.jetbrains_ide.option.*.value, data.coder_parameter.jetbrains_ide.value)].icon
|
||||
external = true
|
||||
url = join("", [
|
||||
"jetbrains-gateway://connect#type=coder&workspace=",
|
||||
data.coder_workspace.me.name,
|
||||
"&agent=",
|
||||
var.agent_name,
|
||||
"&folder=",
|
||||
var.project_directory,
|
||||
"&url=",
|
||||
data.coder_workspace.me.access_url,
|
||||
"&token=",
|
||||
"$SESSION_TOKEN",
|
||||
"&ide_product_code=",
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[0],
|
||||
"&ide_build_number=",
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[1],
|
||||
"&ide_download_link=",
|
||||
jsondecode(data.coder_parameter.jetbrains_ide.value)[2]
|
||||
])
|
||||
}
|
||||
|
||||
output "jetbrains_ides" {
|
||||
|
||||
Reference in New Issue
Block a user