- Notifications
You must be signed in to change notification settings - Fork1k
feat: use preview to compute workspace tags from terraform#18720
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletionsarchive/fs/zip.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package archivefs | ||
import ( | ||
"archive/zip" | ||
"io" | ||
"io/fs" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/afero/zipfs" | ||
) | ||
// FromZipReader creates a read-only in-memory FS | ||
func FromZipReader(r io.ReaderAt, size int64) (fs.FS, error) { | ||
zr, err := zip.NewReader(r, size) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return afero.NewIOFS(zipfs.New(zr)), nil | ||
} |
5 changes: 5 additions & 0 deletionscoderd/coderdtest/dynamicparameters.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package dynamicparameters | ||
import ( | ||
"fmt" | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/coder/preview" | ||
previewtypes "github.com/coder/preview/types" | ||
) | ||
func CheckTags(output *preview.Output, diags hcl.Diagnostics) *DiagnosticError { | ||
de := tagValidationError(diags) | ||
failedTags := output.WorkspaceTags.UnusableTags() | ||
if len(failedTags) == 0 && !de.HasError() { | ||
return nil // No errors, all is good! | ||
} | ||
for _, tag := range failedTags { | ||
name := tag.KeyString() | ||
if name == previewtypes.UnknownStringValue { | ||
name = "unknown" // Best effort to get a name for the tag | ||
} | ||
de.Extend(name, failedTagDiagnostic(tag)) | ||
} | ||
return de | ||
} | ||
// failedTagDiagnostic is a helper function that takes an invalid tag and | ||
// returns an appropriate hcl diagnostic for it. | ||
func failedTagDiagnostic(tag previewtypes.Tag) hcl.Diagnostics { | ||
const ( | ||
key = "key" | ||
value = "value" | ||
) | ||
diags := hcl.Diagnostics{} | ||
// TODO: It would be really nice to pull out the variable references to help identify the source of | ||
// the unknown or invalid tag. | ||
unknownErr := "Tag %s is not known, it likely refers to a variable that is not set or has no default." | ||
invalidErr := "Tag %s is not valid, it must be a non-null string value." | ||
if !tag.Key.Value.IsWhollyKnown() { | ||
diags = diags.Append(&hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: fmt.Sprintf(unknownErr, key), | ||
}) | ||
} else if !tag.Key.Valid() { | ||
diags = diags.Append(&hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: fmt.Sprintf(invalidErr, key), | ||
}) | ||
} | ||
if !tag.Value.Value.IsWhollyKnown() { | ||
diags = diags.Append(&hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: fmt.Sprintf(unknownErr, value), | ||
}) | ||
} else if !tag.Value.Valid() { | ||
diags = diags.Append(&hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: fmt.Sprintf(invalidErr, value), | ||
}) | ||
} | ||
if diags.HasErrors() { | ||
// Stop here if there are diags, as the diags manually created above are more | ||
// informative than the original tag's diagnostics. | ||
return diags | ||
} | ||
// If we reach here, decorate the original tag's diagnostics | ||
diagErr := "Tag %s: %s" | ||
if tag.Key.ValueDiags.HasErrors() { | ||
// add 'Tag key' prefix to each diagnostic | ||
for _, d := range tag.Key.ValueDiags { | ||
d.Summary = fmt.Sprintf(diagErr, key, d.Summary) | ||
} | ||
} | ||
diags = diags.Extend(tag.Key.ValueDiags) | ||
if tag.Value.ValueDiags.HasErrors() { | ||
// add 'Tag value' prefix to each diagnostic | ||
for _, d := range tag.Value.ValueDiags { | ||
d.Summary = fmt.Sprintf(diagErr, value, d.Summary) | ||
} | ||
} | ||
diags = diags.Extend(tag.Value.ValueDiags) | ||
if !diags.HasErrors() { | ||
diags = diags.Append(&hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Tag is invalid for some unknown reason. Please check the tag's value and key.", | ||
}) | ||
} | ||
return diags | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.