generated from crossplane-contrib/provider-jet-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c0b5e0
commit cf3de03
Showing
6 changed files
with
72 additions
and
66 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
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,56 @@ | ||
package commmon | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/crossplane/upjet/pkg/config" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Errors | ||
const ( | ||
ErrFmtNoAttribute = `attribute not found: %s` | ||
ErrFmtUnexpectedType = `unexpected type for attribute %s: Expecting a string` | ||
Managed = `managed` | ||
) | ||
|
||
func GetExternalName(tfstate map[string]any) (string, error) { | ||
id, ok := tfstate["id"] | ||
if !ok { | ||
return "", errors.Errorf(ErrFmtNoAttribute, "id") | ||
} | ||
idStr, ok := id.(string) | ||
if !ok { | ||
return "", errors.Errorf(ErrFmtUnexpectedType, "id") | ||
} | ||
return idStr, nil | ||
} | ||
|
||
func GetFakeID(_ context.Context, externalName string, _ map[string]any, _ map[string]any) (string, error) { | ||
if externalName == "" { | ||
return Managed, nil | ||
} | ||
return externalName, nil | ||
} | ||
|
||
func SplitExternalNameFromId() config.ExternalName { | ||
e := config.IdentifierFromProvider | ||
e.GetExternalNameFn = func(tfstate map[string]interface{}) (string, error) { | ||
id, ok := tfstate["id"] | ||
if !ok { | ||
return "", errors.New("id in tfstate cannot be empty") | ||
} | ||
w := strings.Split(id.(string), ":") | ||
return w[len(w)-1], nil | ||
} | ||
return e | ||
} | ||
|
||
func ExternalNameFromParams(params []string) config.ExternalName { | ||
e := config.IdentifierFromProvider | ||
e.GetExternalNameFn = func(tfstate map[string]interface{}) (string, error) { | ||
return strings.Join(params, ":"), nil | ||
} | ||
return e | ||
} |
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 was deleted.
Oops, something went wrong.
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