Class: AWSCDK::IAM::ServicePrincipal
- Inherits:
-
PrincipalBase
- Object
- PrincipalBase
- AWSCDK::IAM::ServicePrincipal
- Defined in:
- iam/service_principal.rb
Overview
An IAM principal that represents an AWS service (i.e. sqs.amazonaws.com).
Class Method Summary collapse
-
.from_static_service_principle_name(service_principal_name) ⇒ AWSCDK::IAM::ServicePrincipal
Return the service principal using the service principal name as it is passed to the function without any change regardless of the region used in the stack if it is Opted in or not.
- .jsii_overridable_methods ⇒ Object
-
.service_principal_name(service) ⇒ String
Return the service principal name based on the region it's used in.
Instance Method Summary collapse
-
#add_to_assume_role_policy(document) ⇒ void
Add the principal to the AssumeRolePolicyDocument.
-
#add_to_policy(statement) ⇒ Boolean
Add to the policy of this principal.
-
#add_to_principal_policy(_statement) ⇒ AWSCDK::IAM::AddToPrincipalPolicyResult
Add to the policy of this principal.
-
#assume_role_action ⇒ String
When this Principal is used in an AssumeRole policy, the action to use.
-
#dedupe_string ⇒ String?
Return whether or not this principal is equal to the given principal.
-
#grant_principal ⇒ AWSCDK::IAM::IPrincipal
The principal to grant permissions to.
-
#initialize(service, opts = nil) ⇒ ServicePrincipal
constructor
Reference an AWS service, optionally in a given region.
-
#policy_fragment ⇒ AWSCDK::IAM::PrincipalPolicyFragment
Return the policy fragment that identifies this principal in a Policy.
-
#principal_account ⇒ String?
The AWS account ID of this principal.
-
#service ⇒ String
AWS service (i.e. sqs.amazonaws.com).
-
#to_json ⇒ Hash{String => Array<String>}
JSON-ify the principal.
-
#to_string ⇒ String
Returns a string representation of an object.
-
#with_conditions(conditions) ⇒ AWSCDK::IAM::PrincipalBase
Returns a new PrincipalWithConditions using this principal as the base, with the passed conditions added.
-
#with_session_tags ⇒ AWSCDK::IAM::PrincipalBase
Returns a new principal using this principal as the base, with session tags enabled.
Constructor Details
#initialize(service, opts = nil) ⇒ ServicePrincipal
Reference an AWS service, optionally in a given region.
12 13 14 15 16 17 |
# File 'iam/service_principal.rb', line 12 def initialize(service, opts = nil) opts = opts.is_a?(Hash) ? ::AWSCDK::IAM::ServicePrincipalOpts.new(**opts.transform_keys(&:to_sym)) : opts Jsii::Type.check_type(service, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "service") Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLlNlcnZpY2VQcmluY2lwYWxPcHRzIn0=")), "opts") unless opts.nil? Jsii::Object.instance_method(:initialize).bind(self).call(service, opts) end |
Class Method Details
.from_static_service_principle_name(service_principal_name) ⇒ AWSCDK::IAM::ServicePrincipal
Return the service principal using the service principal name as it is passed to the function without any change regardless of the region used in the stack if it is Opted in or not.
43 44 45 46 |
# File 'iam/service_principal.rb', line 43 def self.from_static_service_principle_name(service_principal_name) Jsii::Type.check_type(service_principal_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "servicePrincipalName") Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_iam.ServicePrincipal", "fromStaticServicePrincipleName", [service_principal_name]) end |
.jsii_overridable_methods ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'iam/service_principal.rb', line 19 def self.jsii_overridable_methods { :assume_role_action => { kind: :property, name: "assumeRoleAction", is_optional: false }, :grant_principal => { kind: :property, name: "grantPrincipal", is_optional: false }, :policy_fragment => { kind: :property, name: "policyFragment", is_optional: false }, :principal_account => { kind: :property, name: "principalAccount", is_optional: true }, :service => { kind: :property, name: "service", is_optional: false }, :add_to_assume_role_policy => { kind: :method, name: "addToAssumeRolePolicy", is_optional: false }, :add_to_policy => { kind: :method, name: "addToPolicy", is_optional: false }, :add_to_principal_policy => { kind: :method, name: "addToPrincipalPolicy", is_optional: false }, :dedupe_string => { kind: :method, name: "dedupeString", is_optional: false }, :to_json => { kind: :method, name: "toJSON", is_optional: false }, :to_string => { kind: :method, name: "toString", is_optional: false }, :with_conditions => { kind: :method, name: "withConditions", is_optional: false }, :with_session_tags => { kind: :method, name: "withSessionTags", is_optional: false }, } end |
.service_principal_name(service) ⇒ String
Return the service principal name based on the region it's used in.
Some service principal names used to be different for different partitions,
and some were not. This method would return the appropriate region-specific
service principal name, getting that information from the region-info
module.
These days all service principal names are standardized, and they are all
of the form <servicename>.amazonaws.com.
To avoid breaking changes, handling is provided for services added with the formats below, however, no additional handling will be added for new regions or partitions.
- s3
- s3.amazonaws.com
- s3.amazonaws.com.cn
- s3.c2s.ic.gov
- s3.sc2s.sgov.gov
71 72 73 74 |
# File 'iam/service_principal.rb', line 71 def self.service_principal_name(service) Jsii::Type.check_type(service, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "service") Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_iam.ServicePrincipal", "servicePrincipalName", [service]) end |
Instance Method Details
#add_to_assume_role_policy(document) ⇒ void
This method returns an undefined value.
Add the principal to the AssumeRolePolicyDocument.
Add the statements to the AssumeRolePolicyDocument necessary to give this principal permissions to assume the given role.
123 124 125 126 |
# File 'iam/service_principal.rb', line 123 def add_to_assume_role_policy(document) Jsii::Type.check_type(document, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLlBvbGljeURvY3VtZW50In0=")), "document") jsii_call_method("addToAssumeRolePolicy", [document]) end |
#add_to_policy(statement) ⇒ Boolean
Add to the policy of this principal.
132 133 134 135 |
# File 'iam/service_principal.rb', line 132 def add_to_policy(statement) Jsii::Type.check_type(statement, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLlBvbGljeVN0YXRlbWVudCJ9")), "statement") jsii_call_method("addToPolicy", [statement]) end |
#add_to_principal_policy(_statement) ⇒ AWSCDK::IAM::AddToPrincipalPolicyResult
Add to the policy of this principal.
141 142 143 144 |
# File 'iam/service_principal.rb', line 141 def add_to_principal_policy(_statement) Jsii::Type.check_type(_statement, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLlBvbGljeVN0YXRlbWVudCJ9")), "_statement") jsii_call_method("addToPrincipalPolicy", [_statement]) end |
#assume_role_action ⇒ String
When this Principal is used in an AssumeRole policy, the action to use.
79 80 81 |
# File 'iam/service_principal.rb', line 79 def assume_role_action() jsii_get_property("assumeRoleAction") end |
#dedupe_string ⇒ String?
Return whether or not this principal is equal to the given principal.
149 150 151 |
# File 'iam/service_principal.rb', line 149 def dedupe_string() jsii_call_method("dedupeString", []) end |
#grant_principal ⇒ AWSCDK::IAM::IPrincipal
The principal to grant permissions to.
86 87 88 |
# File 'iam/service_principal.rb', line 86 def grant_principal() jsii_get_property("grantPrincipal") end |
#policy_fragment ⇒ AWSCDK::IAM::PrincipalPolicyFragment
Return the policy fragment that identifies this principal in a Policy.
93 94 95 |
# File 'iam/service_principal.rb', line 93 def policy_fragment() jsii_get_property("policyFragment") end |
#principal_account ⇒ String?
The AWS account ID of this principal.
Can be undefined when the account is not known (for example, for service principals). Can be a Token - in that case, it's assumed to be AWS::AccountId.
105 106 107 |
# File 'iam/service_principal.rb', line 105 def principal_account() jsii_get_property("principalAccount") end |
#service ⇒ String
AWS service (i.e. sqs.amazonaws.com).
112 113 114 |
# File 'iam/service_principal.rb', line 112 def service() jsii_get_property("service") end |
#to_json ⇒ Hash{String => Array<String>}
JSON-ify the principal.
Used when JSON.stringify() is called
158 159 160 |
# File 'iam/service_principal.rb', line 158 def to_json() jsii_call_method("toJSON", []) end |
#to_string ⇒ String
Returns a string representation of an object.
165 166 167 |
# File 'iam/service_principal.rb', line 165 def to_string() jsii_call_method("toString", []) end |
#with_conditions(conditions) ⇒ AWSCDK::IAM::PrincipalBase
Returns a new PrincipalWithConditions using this principal as the base, with the passed conditions added.
When there is a value for the same operator and key in both the principal and the conditions parameter, the value from the conditions parameter will be used.
176 177 178 179 |
# File 'iam/service_principal.rb', line 176 def with_conditions(conditions) Jsii::Type.check_type(conditions, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6ImFueSJ9LCJraW5kIjoibWFwIn19")), "conditions") jsii_call_method("withConditions", [conditions]) end |
#with_session_tags ⇒ AWSCDK::IAM::PrincipalBase
Returns a new principal using this principal as the base, with session tags enabled.
184 185 186 |
# File 'iam/service_principal.rb', line 184 def () jsii_call_method("withSessionTags", []) end |