-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new configurations to specify product. Use product to determine product passed to tfswitch and for executable used when calling terraform Issue #520
- Loading branch information
1 parent
92d95db
commit 03f20e9
Showing
4 changed files
with
101 additions
and
8 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
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,52 @@ | ||
import abc | ||
|
||
import terrareg.config | ||
|
||
|
||
class BaseProduct(abc.ABC): | ||
|
||
@abc.abstractmethod | ||
def get_tfswitch_product_arg(self) -> str: | ||
"""Return name of tfswitch product argument value""" | ||
... | ||
|
||
@abc.abstractmethod | ||
def get_executable_name(self) -> str: | ||
"""Return executable name for product""" | ||
... | ||
|
||
class Terraform(BaseProduct): | ||
"""Terraform product""" | ||
|
||
def get_tfswitch_product_arg(self) -> str: | ||
"""Return name of tfswitch product argument value""" | ||
return "terraform" | ||
|
||
def get_executable_name(self) -> str: | ||
"""Return executable name for product""" | ||
return "terraform" | ||
|
||
|
||
class OpenTofu(BaseProduct): | ||
"""OpenTofu product""" | ||
|
||
def get_tfswitch_product_arg(self) -> str: | ||
"""Return name of tfswitch product argument value""" | ||
return "opentofu" | ||
|
||
def get_executable_name(self) -> str: | ||
"""Return executable name for product""" | ||
return "tofu" | ||
|
||
|
||
class ProductFactory: | ||
|
||
@staticmethod | ||
def get_product(): | ||
"""Obtain current product""" | ||
product_enum = terrareg.config.Config().PRODUCT | ||
if product_enum is terrareg.config.Product.TERRAFORM: | ||
return Terraform() | ||
elif product_enum is terrareg.config.Product.OPENTOFU: | ||
return OpenTofu() | ||
raise Exception("Could not determine product class") |