Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align naming and return types for accessors in config package #327

Merged
merged 6 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,6 @@ func (c *Config) GetCustomMapFieldMembers() []string {
return members
}

// ResourceContainsSecret returns true if any of the fields in any resource are
// defined as secrets.
func (c *Config) ResourceContainsSecret() bool {
for _, resource := range c.Resources {
for _, field := range resource.Fields {
if field.IsSecret {
return true
}
}
}
return false
}

// New returns a new Config object given a supplied
// path to a config file
func New(
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type OperationConfig struct {
OperationType StringArray `json:"operation_type"`
}

// IsIgnoredOperation returns true if Operation Name is configured to be ignored
// OperationIsIgnored returns true if Operation Name is configured to be ignored
// in generator config for the AWS service
func (c *Config) IsIgnoredOperation(operation *awssdkmodel.Operation) bool {
func (c *Config) OperationIsIgnored(operation *awssdkmodel.Operation) bool {
if c == nil {
return false
}
Expand Down Expand Up @@ -99,9 +99,9 @@ func (c *Config) GetOutputWrapperFieldPath(
return &opConfig.OutputWrapperFieldPath
}

// SetOutputCustomMethodName returns custom set output operation as *string for
// GetSetOutputCustomMethodName returns custom set output operation as *string for
// given operation on custom resource, if specified in generator config
func (c *Config) SetOutputCustomMethodName(
func (c *Config) GetSetOutputCustomMethodName(
// The operation to look for the Output shape
op *awssdkmodel.Operation,
) *string {
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *Config) GetCustomCheckRequiredFieldsMissingMethod(
}

// OverrideValues returns a list of member values to override for a given operation
func (c *Config) OverrideValues(operationName string) (map[string]string, bool) {
func (c *Config) GetOverrideValues(operationName string) (map[string]string, bool) {
if c == nil {
return nil, false
}
Expand All @@ -171,7 +171,7 @@ func (c *Config) OverrideValues(operationName string) (map[string]string, bool)
}

// OperationConfig returns the OperationConfig for a given operation
func (c *Config) OperationConfig(opID string) (*OperationConfig, bool) {
func (c *Config) GetOperationConfig(opID string) (*OperationConfig, bool) {
if c == nil {
return nil, false
}
Expand Down
180 changes: 90 additions & 90 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,39 @@ type ReconcileConfig struct {
RequeueOnSuccessSeconds int `json:"requeue_on_success_seconds,omitempty"`
}

// ResourceConfig returns the ResourceConfig for a given resource name
func (c *Config) ResourceConfig(name string) (*ResourceConfig, bool) {
// ResourceIsIgnored returns true if resource name is configured to be ignored
// in generator config for the AWS service
func (c *Config) ResourceIsIgnored(resourceName string) bool {
if resourceName == "" {
return true
}
if c == nil {
return false
}
return util.InStrings(resourceName, c.Ignore.ResourceNames)
}

// ResourceIsAdoptable returns true if resource name is configured to be adoptable.
// Default behavior is every resource can be adopted using AdoptionReconciler
func (c *Config) ResourceIsAdoptable(resourceName string) bool {
if c == nil {
return nil, false
return true
}
rConfig, ok := c.Resources[resourceName]
if !ok {
return true
}
rc, ok := c.Resources[name]
return &rc, ok
if rConfig.IsAdoptable == nil {
return true
}
return *rConfig.IsAdoptable
}

// UnpacksAttributesMap returns true if the underlying API has
// ResourceContainsAttributesMap returns true if the underlying API has
// Get{Resource}Attributes/Set{Resource}Attributes API calls that map real,
// schema'd fields to a raw `map[string]*string` for a given resource name (see SNS and
// SQS APIs)
func (c *Config) UnpacksAttributesMap(resourceName string) bool {
func (c *Config) ResourceContainsAttributesMap(resourceName string) bool {
if c == nil {
return false
}
Expand All @@ -357,12 +376,28 @@ func (c *Config) UnpacksAttributesMap(resourceName string) bool {
return false
}

// SetAttributesSingleAttribute returns true if the supplied resource name has
// ResourceDisplaysAgeColumn returns true if the resource is
// configured to display resource age (created since date)
func (c *Config) ResourceDisplaysAgeColumn(resourceName string) bool {
if c == nil {
return false
}
rConfig, ok := c.Resources[resourceName]
if !ok {
return false
}
if rConfig.Print != nil {
return rConfig.Print.AddAgeColumn
}
return false
}

// ResourceSetsSingleAttribute returns true if the supplied resource name has
// a SetAttributes operation that only actually changes a single attribute at a
// time. See: SNS SetTopicAttributes API call, which is entirely different from
// the SNS SetPlatformApplicationAttributes API call, which sets multiple
// attributes at once. :shrug:
func (c *Config) SetAttributesSingleAttribute(resourceName string) bool {
func (c *Config) ResourceSetsSingleAttribute(resourceName string) bool {
if c == nil {
return false
}
Expand All @@ -373,10 +408,19 @@ func (c *Config) SetAttributesSingleAttribute(resourceName string) bool {
return resGenConfig.UnpackAttributesMapConfig.SetAttributesSingleAttribute
}

// ResourceFields returns a map, keyed by target/renamed field name, of
// GetResourceConfig returns the ResourceConfig for a given resource name
func (c *Config) GetResourceConfig(resourceName string) *ResourceConfig {
if c == nil {
return nil
}
rc, _ := c.Resources[resourceName]
return &rc
}

// GetResourceFields returns a map, keyed by target/renamed field name, of
// FieldConfig struct pointers that instruct the code generator how to handle
// the interpretation of special Resource fields (both Spec and Status)
func (c *Config) ResourceFields(resourceName string) map[string]*FieldConfig {
func (c *Config) GetResourceFields(resourceName string) map[string]*FieldConfig {
if c == nil {
return map[string]*FieldConfig{}
}
Expand All @@ -387,10 +431,10 @@ func (c *Config) ResourceFields(resourceName string) map[string]*FieldConfig {
return resourceConfig.Fields
}

// ResourceFieldByPath returns the FieldConfig for a field from
// GetResourceFieldByPath returns the FieldConfig for a field from
// "resourceName" crd, where field.Path matches the passed "fieldPath" parameter.
// This method performs the case-insensitive resource and fieldPath lookup.
func (c *Config) ResourceFieldByPath(resourceName string, fieldPath string) *FieldConfig {
func (c *Config) GetResourceFieldByPath(resourceName string, fieldPath string) *FieldConfig {
var resourceConfig ResourceConfig
if c == nil {
return nil
Expand All @@ -411,13 +455,13 @@ func (c *Config) ResourceFieldByPath(resourceName string, fieldPath string) *Fie
return nil
}

// GetCompareIgnoredFields returns the list of field path to ignore when
// comparing two differnt objects
func (c *Config) GetCompareIgnoredFields(resName string) []string {
// GetCompareIgnoredFieldPaths returns the list of field paths to ignore when
// comparing two different objects
func (c *Config) GetCompareIgnoredFieldPaths(resourceName string) []string {
if c == nil {
return nil
}
rConfig, ok := c.Resources[resName]
rConfig, ok := c.Resources[resourceName]
if !ok {
return nil
}
Expand All @@ -427,52 +471,39 @@ func (c *Config) GetCompareIgnoredFields(resName string) []string {
return rConfig.Compare.Ignore
}

// IsIgnoredResource returns true if resource name is configured to be ignored
// in generator config for the AWS service
func (c *Config) IsIgnoredResource(resourceName string) bool {
if resourceName == "" {
return true
}
if c == nil {
return false
}
return util.InStrings(resourceName, c.Ignore.ResourceNames)
}

// ResourceFieldRename returns the renamed field for a Resource, a
// supplied Operation ID and original field name and whether or not a renamed
// override field name was found
func (c *Config) ResourceFieldRename(
resName string,
// GetResourceFieldName returns a resource field name
// after applying rename overrides, if configured
func (c *Config) GetResourceFieldName(
resourceName string,
opID string,
origFieldName string,
) (string, bool) {
) string {
if c == nil {
return origFieldName, false
return origFieldName
}
rConfig, ok := c.Resources[resName]
rConfig, ok := c.Resources[resourceName]
if !ok {
return origFieldName, false
return origFieldName
}
if rConfig.Renames == nil {
return origFieldName, false
return origFieldName
}
oRenames, ok := rConfig.Renames.Operations[opID]
if !ok {
return origFieldName, false
return origFieldName
}
renamed, ok := oRenames.InputFields[origFieldName]
if !ok {
renamed, ok = oRenames.OutputFields[origFieldName]
if !ok {
return origFieldName, false
return origFieldName
}
}
return renamed, true
return renamed
}

// ResourceShortNames returns the CRD list of aliases
func (c *Config) ResourceShortNames(resourceName string) []string {
// GetResourceShortNames returns the CRD list of aliases
func (c *Config) GetResourceShortNames(resourceName string) []string {
if c == nil {
return nil
}
Expand All @@ -483,22 +514,6 @@ func (c *Config) ResourceShortNames(resourceName string) []string {
return rConfig.ShortNames
}

// ResourceIsAdoptable returns whether the given CRD is adoptable
func (c *Config) ResourceIsAdoptable(resourceName string) bool {
if c == nil {
return true
}
rConfig, ok := c.Resources[resourceName]
if !ok {
return true
}
// Default to True
if rConfig.IsAdoptable == nil {
return true
}
return *rConfig.IsAdoptable
}

// GetResourcePrintOrderByName returns the Printer Column order-by field name
func (c *Config) GetResourcePrintOrderByName(resourceName string) string {
if c == nil {
Expand All @@ -514,24 +529,9 @@ func (c *Config) GetResourcePrintOrderByName(resourceName string) string {
return ""
}

// GetResourcePrintAddAgeColumn returns the resource printer AddAgeColumn config
func (c *Config) GetResourcePrintAddAgeColumn(resourceName string) bool {
if c == nil {
return false
}
rConfig, ok := c.Resources[resourceName]
if !ok {
return false
}
if rConfig.Print != nil {
return rConfig.Print.AddAgeColumn
}
return false
}

// UpdateConditionsCustomMethodName returns custom update conditions operation
// GetUpdateConditionsCustomMethodName returns custom update conditions operation
// as *string for custom resource, if specified in generator config
func (c *Config) UpdateConditionsCustomMethodName(resourceName string) string {
func (c *Config) GetUpdateConditionsCustomMethodName(resourceName string) string {
if c == nil {
return ""
}
Expand All @@ -542,9 +542,9 @@ func (c *Config) UpdateConditionsCustomMethodName(resourceName string) string {
return resGenConfig.UpdateConditionsCustomMethodName
}

// ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue
// GetReconcileRequeueOnSuccessSeconds returns the duration after which to requeue
// the custom resource as int, if specified in generator config.
func (c *Config) ReconcileRequeuOnSuccessSeconds(resourceName string) int {
func (c *Config) GetReconcileRequeueOnSuccessSeconds(resourceName string) int {
if c == nil {
return 0
}
Expand All @@ -560,10 +560,10 @@ func (c *Config) ReconcileRequeuOnSuccessSeconds(resourceName string) int {
return 0
}

// CustomUpdateMethodName returns the name of the custom resourceManager method
// GetCustomUpdateMethodName returns the name of the custom resourceManager method
// for updating the resource state, if any has been specified in the generator
// config
func (c *Config) CustomUpdateMethodName(resourceName string) string {
func (c *Config) GetCustomUpdateMethodName(resourceName string) string {
if c == nil {
return ""
}
Expand All @@ -581,17 +581,17 @@ func (c *Config) CustomUpdateMethodName(resourceName string) string {
func (c *Config) GetAllRenames(
resourceName string,
operations map[string]*awssdkmodel.Operation,
) (map[string]string, error) {
) map[string]string {
renames := make(map[string]string)
if c == nil {
return renames, nil
return renames
}
resourceConfig, ok := c.Resources[resourceName]
if !ok {
return renames, nil
return renames
}
if resourceConfig.Renames == nil || resourceConfig.Renames.Operations == nil {
return renames, nil
return renames
}

opRenameConfigs := resourceConfig.Renames.Operations
Expand All @@ -608,12 +608,12 @@ func (c *Config) GetAllRenames(
}
}
}
return renames, nil
return renames
}

// TerminalExceptionCodes returns terminal exception codes as
// GetTerminalExceptionCodes returns terminal exception codes as
// []string for custom resource, if specified in generator config
func (c *Config) TerminalExceptionCodes(resourceName string) []string {
func (c *Config) GetTerminalExceptionCodes(resourceName string) []string {
if c == nil {
return nil
}
Expand All @@ -624,10 +624,10 @@ func (c *Config) TerminalExceptionCodes(resourceName string) []string {
return nil
}

// ListOpMatchFieldNames returns a slice of strings representing the field
// GetListOpMatchFieldNames returns a slice of strings representing the field
// names in the List operation's Output shape's element Shape that we should
// check a corresponding value in the target Spec exists.
func (c *Config) ListOpMatchFieldNames(
func (c *Config) GetListOpMatchFieldNames(
resName string,
) []string {
res := []string{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/generate/code/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func CheckExceptionMessage(
r *model.CRD,
httpStatusCode int,
) string {
rConfig, ok := cfg.ResourceConfig(r.Names.Original)
if ok && rConfig.Exceptions != nil {
rConfig := cfg.GetResourceConfig(r.Names.Original)
if rConfig != nil && rConfig.Exceptions != nil {
excConfig, ok := rConfig.Exceptions.Errors[httpStatusCode]
if !ok {
return ""
Expand Down
Loading