-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: provider muxing for plugin-framework (#2130)
* provider config refactor * gen docs * update provider * update docs * update provider * framework initial work * update rm * update resource monitor * update docs * go fmt * update provider config * add to framework repo
- Loading branch information
1 parent
4765410
commit f3c85c0
Showing
12 changed files
with
2,074 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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,35 @@ | ||
package stringplanmodifiers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
) | ||
|
||
// useStateForUnknownModifier implements the plan modifier. | ||
type suppressDiffIfModifier struct { | ||
f func(old, new string) bool | ||
} | ||
|
||
// Description returns a human-readable description of the plan modifier. | ||
func (m suppressDiffIfModifier) Description(_ context.Context) string { | ||
return "Suppresses diff if values based on function." | ||
} | ||
|
||
// MarkdownDescription returns a markdown description of the plan modifier. | ||
func (m suppressDiffIfModifier) MarkdownDescription(_ context.Context) string { | ||
return "Suppresses diff if values based on function." | ||
} | ||
|
||
// PlanModifyBool implements the plan modification logic. | ||
func (m suppressDiffIfModifier) PlanModifyString(_ context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
if m.f(req.StateValue.ValueString(), req.PlanValue.ValueString()) { | ||
resp.PlanValue = req.StateValue | ||
} | ||
} | ||
|
||
func SuppressDiffIf(f func(old, new string) bool) planmodifier.String { | ||
return suppressDiffIfModifier{ | ||
f: f, | ||
} | ||
} |
This file contains 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,84 @@ | ||
package provider | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/gookit/color" | ||
) | ||
|
||
type tfOperation string | ||
|
||
const ( | ||
CreateOperation tfOperation = "CREATE" | ||
ReadOperation tfOperation = "READ" | ||
UpdateOperation tfOperation = "UPDATE" | ||
DeleteOperation tfOperation = "DELETE" | ||
) | ||
|
||
func formatSQLPreview(operation tfOperation, resourceName string, id string, commands []string) string { | ||
var c color.Color | ||
switch operation { | ||
case CreateOperation: | ||
c = color.HiGreen | ||
case ReadOperation: | ||
c = color.HiBlue | ||
case UpdateOperation: | ||
c = color.HiYellow | ||
case DeleteOperation: | ||
c = color.HiRed | ||
} | ||
var sb strings.Builder | ||
sb.WriteString(c.Sprintf("\n[ %s %s %s ]", operation, resourceName, id)) | ||
for _, command := range commands { | ||
sb.WriteString(c.Sprintf("\n - %s", command)) | ||
} | ||
sb.WriteString("\n") | ||
return sb.String() | ||
} | ||
|
||
type sensitiveAttributes struct { | ||
m map[string]bool | ||
} | ||
|
||
var ( | ||
sa *sensitiveAttributes | ||
lock = sync.Mutex{} | ||
) | ||
|
||
func isSensitive(s string) bool { | ||
if sa == nil { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
if sa == nil { | ||
sa = &sensitiveAttributes{ | ||
m: make(map[string]bool), | ||
} | ||
dir, err := os.UserHomeDir() | ||
if err != nil { | ||
return false | ||
} | ||
// sensitive path is ~/.snowflake/sensitive. | ||
f := filepath.Join(dir, ".snowflake", "sensitive") | ||
dat, err := os.ReadFile(f) | ||
if err != nil { | ||
return false | ||
} | ||
lines := strings.Split(string(dat), "\n") | ||
r := regexp.MustCompile("(data[.])?snowflake_(.*)[.](.+)[.](.+)") | ||
for _, line := range lines { | ||
strippedLine := strings.TrimSpace(line) | ||
if r.MatchString(strippedLine) { | ||
sa.m[strippedLine] = true | ||
} | ||
} | ||
} | ||
} | ||
if _, ok := sa.m[s]; ok { | ||
return true | ||
} | ||
return false | ||
} |
Oops, something went wrong.