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

update magic module-generated resources with at_least_one_of #2639

Merged
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
23 changes: 23 additions & 0 deletions api/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ module Fields
# A list of properties that conflict with this property.
attr_reader :conflicts

# A list of properties that at least one of must be set.
attr_reader :at_least_one_of

# Can only be overridden - we should never set this ourselves.
attr_reader :new_type

Expand Down Expand Up @@ -109,6 +112,7 @@ def validate

check_default_value_property
check_conflicts
check_at_least_one_of
end

def to_s
Expand All @@ -135,6 +139,8 @@ def to_json(opts = nil)
instance_variables.each do |v|
if v == :@conflicts && instance_variable_get(v).empty?
# ignore empty conflict arrays
elsif v == :@at_least_one_of && instance_variable_get(v).empty?
# ignore empty at_least_one_of arrays
elsif instance_variable_get(v) == false || instance_variable_get(v).nil?
# ignore false booleans as non-existence indicates falsey
elsif !ignored_fields.include? v
Expand Down Expand Up @@ -194,6 +200,22 @@ def conflicting
@__resource.all_user_properties.select { |p| p.conflicts.include?(@api_name) }).uniq
end

# Checks that all properties that needs at least one of their fields actually exist.
# This currently just returns if empty, because we don't want to do the check, since
# this list will have a full path for nested attributes.
def check_at_least_one_of
check :at_least_one_of, type: ::Array, default: [], item_type: ::String

return if @at_least_one_of.empty?
end

# Returns list of properties that needs at least one of their fields set.
def at_least_one_of_list
return [] unless @__resource

@at_least_one_of
end

def type
self.class.name.split('::').last
end
Expand Down Expand Up @@ -289,6 +311,7 @@ class FetchedExternal < Type

def validate
@conflicts ||= []
@at_least_one_of ||= []
end

def api_name
Expand Down
3 changes: 3 additions & 0 deletions overrides/terraform/property_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def self.attributes
# Names of attributes that can't be set alongside this one
:conflicts_with,

# Names of attributes that at least one of must be set
:at_least_one_of,

# Names of fields that should be included in the updateMask.
:update_mask_fields,

Expand Down
12 changes: 12 additions & 0 deletions products/accesscontextmanager/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ objects:
A list of GCP resources that are inside of the service perimeter.
Currently only projects are allowed.
Format: projects/{project_number}
at_least_one_of:
- status.0.resources
- status.0.access_levels
- status.0.restricted_services
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'accessLevels'
Expand All @@ -390,6 +394,10 @@ objects:
be empty.

Format: accessPolicies/{policy_id}/accessLevels/{access_level_name}
at_least_one_of:
- status.0.resources
- status.0.access_levels
- status.0.restricted_services
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'restrictedServices'
Expand All @@ -399,4 +407,8 @@ objects:
`storage.googleapis.com` is specified, access to the storage
buckets inside the perimeter must meet the perimeter's access
restrictions.
at_least_one_of:
- status.0.resources
- status.0.access_levels
- status.0.restricted_services
item_type: Api::Type::String
6 changes: 6 additions & 0 deletions products/appengine/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ objects:
name: 'zip'
description: 'Zip File'
required: false
at_least_one_of:
- deployment.0.zip
- deployment.0.files
properties:
- !ruby/object:Api::Type::String
name: 'sourceUrl'
Expand All @@ -419,6 +422,9 @@ objects:
Manifest of the files stored in Google Cloud Storage that are included as part of this version.
All files must be readable using the credentials supplied with this call.
required: false
at_least_one_of:
- deployment.0.zip
- deployment.0.files
key_name: 'name'
key_description: |
name of file
Expand Down
2 changes: 2 additions & 0 deletions products/cloudrun/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ objects:
properties:
- !ruby/object:Api::Type::String
name: name
required: true
description: |-
Name of the referent.
More info:
Expand All @@ -369,6 +370,7 @@ objects:
properties:
- !ruby/object:Api::Type::String
name: name
required: true
description: |-
Name of the referent.
More info:
Expand Down
42 changes: 42 additions & 0 deletions products/cloudscheduler/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ objects:
Values greater than 5 and negative values are not allowed.
required: false
input: true
at_least_one_of:
- retry_config.0.retry_count
- retry_config.0.max_retry_duration
- retry_config.0.min_backoff_duration
- retry_config.0.max_backoff_duration
- retry_config.0.max_doublings
- !ruby/object:Api::Type::String
name: maxRetryDuration
description: |
Expand All @@ -98,20 +104,38 @@ objects:
A duration in seconds with up to nine fractional digits, terminated by 's'.
required: false
input: true
at_least_one_of:
- retry_config.0.retry_count
- retry_config.0.max_retry_duration
- retry_config.0.min_backoff_duration
- retry_config.0.max_backoff_duration
- retry_config.0.max_doublings
- !ruby/object:Api::Type::String
name: minBackoffDuration
description: |
The minimum amount of time to wait before retrying a job after it fails.
A duration in seconds with up to nine fractional digits, terminated by 's'.
required: false
input: true
at_least_one_of:
- retry_config.0.retry_count
- retry_config.0.max_retry_duration
- retry_config.0.min_backoff_duration
- retry_config.0.max_backoff_duration
- retry_config.0.max_doublings
- !ruby/object:Api::Type::String
name: maxBackoffDuration
description: |
The maximum amount of time to wait before retrying a job after it fails.
A duration in seconds with up to nine fractional digits, terminated by 's'.
required: false
input: true
at_least_one_of:
- retry_config.0.retry_count
- retry_config.0.max_retry_duration
- retry_config.0.min_backoff_duration
- retry_config.0.max_backoff_duration
- retry_config.0.max_doublings
- !ruby/object:Api::Type::Integer
name: maxDoublings
description: |
Expand All @@ -121,6 +145,12 @@ objects:
and finally retries retries at intervals of maxBackoffDuration up to retryCount times.
required: false
input: true
at_least_one_of:
- retry_config.0.retry_count
- retry_config.0.max_retry_duration
- retry_config.0.min_backoff_duration
- retry_config.0.max_backoff_duration
- retry_config.0.max_doublings
- !ruby/object:Api::Type::NestedObject
name: pubsubTarget
description: |
Expand Down Expand Up @@ -183,20 +213,32 @@ objects:
description: |
App service.
By default, the job is sent to the service which is the default service when the job is attempted.
at_least_one_of:
- app_engine_http_target.0.app_engine_routing.0.service
- app_engine_http_target.0.app_engine_routing.0.version
- app_engine_http_target.0.app_engine_routing.0.instance
required: false
input: true
- !ruby/object:Api::Type::String
name: version
description: |
App version.
By default, the job is sent to the version which is the default version when the job is attempted.
at_least_one_of:
- app_engine_http_target.0.app_engine_routing.0.service
- app_engine_http_target.0.app_engine_routing.0.version
- app_engine_http_target.0.app_engine_routing.0.instance
required: false
input: true
- !ruby/object:Api::Type::String
name: instance
description: |
App instance.
By default, the job is sent to an instance which is available when the job is attempted.
at_least_one_of:
- app_engine_http_target.0.app_engine_routing.0.service
- app_engine_http_target.0.app_engine_routing.0.version
- app_engine_http_target.0.app_engine_routing.0.instance
required: false
input: true
- !ruby/object:Api::Type::String
Expand Down
Loading