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

None-MAGIC-MODULE-iam-Projects__serviceAccounts__key - Resource Implementation #163

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
90 changes: 89 additions & 1 deletion mmv1/products/iam/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,92 @@ objects:
- !ruby/object:Api::Type::Boolean
name: 'deleted'
description: The current deleted state of the role
output: true
output: true


- !ruby/object:Api::Resource
name: ProjectServiceAccountKey
base_url: '{{name}}/keys'
self_link: '{{name}}'
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
api: 'https://cloud.google.com/iam/docs'
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: 'name'
base_url: '{op_id}'
wait_ms: 1000
result: !ruby/object:Api::OpAsync::Result
path: 'response'
resource_inside_response: true
status: !ruby/object:Api::OpAsync::Status
path: 'done'
complete: True
allowed:
- True
- False
error: !ruby/object:Api::OpAsync::Error
path: 'error'
message: 'message'
description: |-
Represents a service account key. A service account has two sets of key-pairs: user-managed, and system-managed. User-managed key-pairs can be created and deleted by users. Users are responsible for rotating these keys periodically to ensure security of their service accounts. Users retain the private key of these key-pairs, and Google retains ONLY the public key. System-managed keys are automatically rotated by Google, and are used for signing for a maximum of two weeks. The rotation process is probabilistic, and usage of the new key will gradually ramp up and down over the key's lifetime. If you cache the public key set for a service account, we recommend that you update the cache every 15 minutes. User-managed keys can be added and removed at any time, so it is important to update the cache frequently. For Google-managed keys, Google will publish a key at least 6 hours before it is first used for signing and will keep publishing it for at least 6 hours after it was last used for signing. Public keys for all service accounts are also published at the OAuth2 Service Account API.
properties:

- !ruby/object:Api::Type::String
name: 'name'
description: |
The resource name of the service account key in the following format `projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT}/keys/{key}`.
- !ruby/object:Api::Type::Enum
name: 'privateKeyType'
description: |
The output format for the private key. Only provided in `CreateServiceAccountKey` responses, not in `GetServiceAccountKey` or `ListServiceAccountKey` responses. Google never exposes system-managed private keys, and never retains user-managed private keys.
values:
- :TYPE_UNSPECIFIED
- :TYPE_PKCS12_FILE
- :TYPE_GOOGLE_CREDENTIALS_FILE
- !ruby/object:Api::Type::Enum
name: 'keyAlgorithm'
description: |
Specifies the algorithm (and possibly key size) for the key.
values:
- :KEY_ALG_UNSPECIFIED
- :KEY_ALG_RSA_1024
- :KEY_ALG_RSA_2048
- !ruby/object:Api::Type::String
name: 'privateKeyData'
description: |
The private key data. Only provided in `CreateServiceAccountKey` responses. Make sure to keep the private key data secure because it allows for the assertion of the service account identity. When base64 decoded, the private key data can be used to authenticate with Google API client libraries and with gcloud auth activate-service-account.
- !ruby/object:Api::Type::String
name: 'publicKeyData'
description: |
The public key data. Only provided in `GetServiceAccountKey` responses.
- !ruby/object:Api::Type::String
name: 'validAfterTime'
description: |
The key can be used after this timestamp.
- !ruby/object:Api::Type::String
name: 'validBeforeTime'
description: |
The key can be used before this timestamp. For system-managed key pairs, this timestamp is the end time for the private key signing operation. The public key could still be used for verification for a few hours after this time.
- !ruby/object:Api::Type::Enum
name: 'keyOrigin'
description: |
The key origin.
values:
- :ORIGIN_UNSPECIFIED
- :USER_PROVIDED
- :GOOGLE_PROVIDED
- !ruby/object:Api::Type::Enum
name: 'keyType'
description: |
The key type.
values:
- :KEY_TYPE_UNSPECIFIED
- :USER_MANAGED
- :SYSTEM_MANAGED
- !ruby/object:Api::Type::Boolean
name: 'disabled'
description: |
The key status.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% gcp_project_id = "#{external_attribute(pwd, 'gcp_project_id', doc_generation)}" -%>
<% project_service_account_key = grab_attributes(pwd)['project_service_account_key'] -%>
describe google_iam_project_service_account_key(name: <%= doc_generation ? "' #{project_service_account_key['name']}'":"project_service_account_key['name']" -%>) do
it { should exist }
its('name') { should cmp <%= doc_generation ? "'#{project_service_account_key['name']}'" : "project_service_account_key['name']" -%> }
its('private_key_type') { should cmp <%= doc_generation ? "'#{project_service_account_key['private_key_type']}'" : "project_service_account_key['private_key_type']" -%> }
its('key_algorithm') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_algorithm']}'" : "project_service_account_key['key_algorithm']" -%> }
its('private_key_data') { should cmp <%= doc_generation ? "'#{project_service_account_key['private_key_data']}'" : "project_service_account_key['private_key_data']" -%> }
its('public_key_data') { should cmp <%= doc_generation ? "'#{project_service_account_key['public_key_data']}'" : "project_service_account_key['public_key_data']" -%> }
its('valid_after_time') { should cmp <%= doc_generation ? "'#{project_service_account_key['valid_after_time']}'" : "project_service_account_key['valid_after_time']" -%> }
its('valid_before_time') { should cmp <%= doc_generation ? "'#{project_service_account_key['valid_before_time']}'" : "project_service_account_key['valid_before_time']" -%> }
its('key_origin') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_origin']}'" : "project_service_account_key['key_origin']" -%> }
its('key_type') { should cmp <%= doc_generation ? "'#{project_service_account_key['key_type']}'" : "project_service_account_key['key_type']" -%> }

end

describe google_iam_project_service_account_key(name: "does_not_exit") do
it { should_not exist }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gcp_project_id = input(:gcp_project_id, value: '<%= external_attribute(pwd, 'gcp_project_id') -%>', description: 'The GCP project identifier.')

project_service_account_key = input('project_service_account_key', value: <%= JSON.pretty_generate(grab_attributes(pwd)['project_service_account_key']) -%>, description: 'project_service_account_key description')
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% gcp_project_id = "#{external_attribute(pwd, 'gcp_project_id', doc_generation)}" -%>
<% project_service_account_key = grab_attributes(pwd)['project_service_account_key'] -%>
describe google_iam_project_service_account_keys(name: <%= doc_generation ? "' #{project_service_account_key['name']}'":"project_service_account_key['name']" -%>) do
it { should exist }
end
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,14 @@ project_secret:

service_connection:
parent : "value_parent"

project_service_account_key:
name : "value_name"
private_key_type : "value_privatekeytype"
key_algorithm : "value_keyalgorithm"
private_key_data : "value_privatekeydata"
public_key_data : "value_publickeydata"
valid_after_time : "value_validaftertime"
valid_before_time : "value_validbeforetime"
key_origin : "value_keyorigin"
key_type : "value_keytype"
Loading