IsValidTemplatedURL validates a URL with template variables against available variables For packages: validates that template variables reference package arguments or environment variables For remotes: validates that template variables reference the transport's variables map
(rawURL string, availableVariables []string)
| 164 | // For packages: validates that template variables reference package arguments or environment variables |
| 165 | // For remotes: validates that template variables reference the transport's variables map |
| 166 | func IsValidTemplatedURL(rawURL string, availableVariables []string) bool { |
| 167 | // First check basic URL structure |
| 168 | if !IsValidURL(rawURL) { |
| 169 | return false |
| 170 | } |
| 171 | |
| 172 | // Extract template variables from URL |
| 173 | templateVars := extractTemplateVariables(rawURL) |
| 174 | |
| 175 | // If no templates are found, it's a valid static URL |
| 176 | if len(templateVars) == 0 { |
| 177 | return true |
| 178 | } |
| 179 | |
| 180 | // Validate that all template variables are available |
| 181 | availableSet := make(map[string]bool) |
| 182 | for _, v := range availableVariables { |
| 183 | availableSet[v] = true |
| 184 | } |
| 185 | |
| 186 | for _, templateVar := range templateVars { |
| 187 | if !availableSet[templateVar] { |
| 188 | return false |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return true |
| 193 | } |
no test coverage detected
searching dependent graphs…