forked from crossplane/upjet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
118 additions
and
34 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,46 @@ | ||
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package conversion | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/crossplane/upjet/pkg/config" | ||
"github.com/crossplane/upjet/pkg/config/conversion" | ||
"github.com/crossplane/upjet/pkg/resource" | ||
) | ||
|
||
const ( | ||
errAlreadyRegistered = "conversion functions are already registered" | ||
) | ||
|
||
var instance *registry | ||
|
||
// registry represents the conversion hook registry for a provider. | ||
type registry struct { | ||
provider *config.Provider | ||
} | ||
|
||
// RegisterConversions registers the API version conversions from the specified | ||
// provider configuration. | ||
func RegisterConversions(provider *config.Provider) error { | ||
if instance != nil { | ||
return errors.New(errAlreadyRegistered) | ||
} | ||
instance = ®istry{ | ||
provider: provider, | ||
} | ||
return nil | ||
} | ||
|
||
// GetConversions returns the conversion.Conversions registered for the | ||
// Terraformed resource. | ||
func GetConversions(tr resource.Terraformed) []conversion.Conversion { | ||
t := tr.GetTerraformResourceType() | ||
if instance == nil || instance.provider == nil || instance.provider.Resources[t] == nil { | ||
return nil | ||
} | ||
return instance.provider.Resources[t].Conversions | ||
} |
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