Skip to content

Commit 48e3f85

Browse files
authored
Remove constraint on time_machine_expiration for organization (#20)
1 parent dba1df0 commit 48e3f85

File tree

6 files changed

+71
-20
lines changed

6 files changed

+71
-20
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Quay Container Registry Collection Release Notes
44

55
.. contents:: Topics
66

7+
v2.5.2
8+
======
9+
10+
Bugfixes
11+
--------
12+
13+
- quay_organization - setting the ``time_machine_expiration`` parameter failed when Quay administrators customize the ``TAG_EXPIRATION_OPTIONS`` option in ``config.yaml``. Fix now allows any value for the ``time_machine_expiration`` parameter. The Quay API might return an error if the given value is not defined in the ``TAG_EXPIRATION_OPTIONS`` option.
14+
715
v2.5.1
816
======
917

changelogs/changelog.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,14 @@ releases:
293293
fragments:
294294
- 19-v2.5.1-summary.yml
295295
release_date: '2024-12-14'
296+
2.5.2:
297+
changes:
298+
bugfixes:
299+
- quay_organization - setting the ``time_machine_expiration`` parameter failed
300+
when Quay administrators customize the ``TAG_EXPIRATION_OPTIONS`` option in
301+
``config.yaml``. Fix now allows any value for the ``time_machine_expiration``
302+
parameter. The Quay API might return an error if the given value is not defined
303+
in the ``TAG_EXPIRATION_OPTIONS`` option.
304+
fragments:
305+
- 20-v2.5.2-summary.yml
306+
release_date: '2024-12-23'

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
namespace: infra
33
name: quay_configuration
4-
version: 2.5.1
4+
version: 2.5.2
55
readme: README.md
66
authors:
77
- Hervé Quatremain <herve.quatremain@redhat.com>

plugins/modules/quay_organization.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@
5656
type: str
5757
time_machine_expiration:
5858
description:
59-
- The amount of time, after a tag is deleted, that the tag is accessible
59+
- After a tag is deleted, the amount of time in seconds it is kept
6060
in time machine before being garbage collected.
61+
- The O(time_machine_expiration) parameter accepts a time unit as a
62+
suffix; C(s) for seconds, C(m) for minutes, C(h) for hours, C(d) for
63+
days, and C(w) for weeks. For example, C(2w) for two weeks.
64+
- Only the expiration times that your Quay administrator declares in
65+
C(config.yaml) with the C(TAG_EXPIRATION_OPTIONS) option are allowed.
66+
The default value for the C(TAG_EXPIRATION_OPTIONS) option is C(0s),
67+
C(1d), C(1w), C(2w), and C(4w).
6168
type: str
62-
choices: [0s, 1d, 7d, 14d, 1month]
6369
state:
6470
description:
6571
- If V(absent), then the module deletes the organization.
@@ -72,6 +78,9 @@
7278
default: present
7379
choices: [absent, present]
7480
notes:
81+
- To use the O(time_machine_expiration) parameter, your Quay administrator
82+
must set C(FEATURE_CHANGE_TAG_EXPIRATION) to C(true), which is the default,
83+
in C(config.yaml).
7584
- The token that you provide in O(quay_token) must have the "Administer
7685
Organization" and "Administer User" permissions.
7786
- To rename organizations, the token must also have the "Super User Access"
@@ -96,7 +105,7 @@
96105
infra.quay_configuration.quay_organization:
97106
name: production
98107
email: prodlist@example.com
99-
time_machine_expiration: "7d"
108+
time_machine_expiration: 1w
100109
state: present
101110
quay_host: https://quay.example.com
102111
quay_token: vgfH9zH5q6eV16Con7SvDQYSr0KPYQimMHVehZv7
@@ -125,18 +134,11 @@
125134

126135

127136
def main():
128-
tm_allowed_values = {
129-
"0s": 0,
130-
"1d": 86400,
131-
"7d": 604800,
132-
"14d": 1209600,
133-
"1month": 2419200,
134-
}
135137
argument_spec = dict(
136138
name=dict(required=True),
137139
new_name=dict(),
138140
email=dict(),
139-
time_machine_expiration=dict(choices=list(tm_allowed_values.keys())),
141+
time_machine_expiration=dict(),
140142
auto_prune_method=dict(
141143
choices=["none", "tags", "date"],
142144
removed_at_date="2025-12-01",
@@ -200,6 +202,14 @@ def main():
200202
)
201203
auto_prune_value = value
202204

205+
# Verify that the expiration is valid and convert it to an integer (seconds)
206+
# Even though the user might provide a valid value, the API will rejects the
207+
# value if it is not in the TAG_EXPIRATION_OPTIONS array (in config.yaml)
208+
if tm_expiration:
209+
tag_expiration_s = module.str_period_to_second(
210+
"time_machine_expiration", tm_expiration
211+
)
212+
203213
org_details = module.get_organization(name)
204214
new_org_details = module.get_organization(new_name) if new_name else None
205215

@@ -286,7 +296,7 @@ def main():
286296
# Prepare the data that gets set for update
287297
new_fields = {}
288298
if tm_expiration:
289-
new_fields["tag_expiration_s"] = tm_allowed_values[tm_expiration]
299+
new_fields["tag_expiration_s"] = tag_expiration_s
290300
if email:
291301
new_fields["email"] = email
292302

tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ services:
2626
- "8089:8080"
2727

2828
quay:
29-
image: quay.io/projectquay/quay:v3.13.1
29+
image: quay.io/projectquay/quay:3.13.2
3030
volumes:
3131
- "./quay-config:/conf/stack:Z"
3232
- "./quay-delay.sh:/quay-registry/conf/init/a-delay.sh:ro"

tests/integration/targets/quay_organization/tasks/main.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
---
2+
- name: ERROR EXPECTED Wrong time machine expiration
3+
infra.quay_configuration.quay_organization:
4+
name: testansible1
5+
time_machine_expiration: 12345s
6+
state: present
7+
quay_host: "{{ quay_url }}"
8+
quay_token: "{{ quay_token }}"
9+
validate_certs: false
10+
ignore_errors: true
11+
register: result
12+
13+
- name: Ensure that the task failed (wrong time machine expiration)
14+
ansible.builtin.assert:
15+
that: result['failed']
16+
fail_msg: The preceding task should have failed (wrong expiration)
17+
218
- name: Ensure organization testansible1 exists
319
infra.quay_configuration.quay_organization:
420
name: testansible1
@@ -7,12 +23,18 @@
723
quay_host: "{{ quay_url }}"
824
quay_token: "{{ quay_token }}"
925
validate_certs: false
26+
register: result
27+
28+
- name: Ensure that the task did change something
29+
ansible.builtin.assert:
30+
that: result['changed']
31+
fail_msg: The preceding task should have changed something
1032

1133
- name: Ensure organization testansible2 exists
1234
infra.quay_configuration.quay_organization:
1335
name: testansible2
1436
email: testansible2@example.com
15-
time_machine_expiration: "7d"
37+
time_machine_expiration: 7d
1638
quay_host: "{{ quay_url }}"
1739
quay_token: "{{ quay_token }}"
1840
validate_certs: false
@@ -43,15 +65,15 @@
4365
- name: Ensure organization testansible3 has a new time machine expiration
4466
infra.quay_configuration.quay_organization:
4567
name: testansible3
46-
time_machine_expiration: "1d"
68+
time_machine_expiration: "1 day"
4769
quay_host: "{{ quay_url }}"
4870
quay_token: "{{ quay_token }}"
4971
validate_certs: false
5072

5173
- name: Ensure organization testansible3 has the same expiration (no change)
5274
infra.quay_configuration.quay_organization:
5375
name: testansible3
54-
time_machine_expiration: "1d"
76+
time_machine_expiration: 1d
5577
auto_prune_method: none
5678
quay_host: "{{ quay_url }}"
5779
quay_token: "{{ quay_token }}"
@@ -69,7 +91,7 @@
6991
email: testansible4@example.com
7092
new_name: testansible4
7193
state: present
72-
time_machine_expiration: "1month"
94+
time_machine_expiration: "4w"
7395
quay_host: "{{ quay_url }}"
7496
quay_token: "{{ quay_token }}"
7597
validate_certs: false
@@ -79,7 +101,7 @@
79101
name: testansible5
80102
email: testansible5@example.com
81103
state: present
82-
time_machine_expiration: "1month"
104+
time_machine_expiration: "4weeks"
83105
auto_prune_method: tags
84106
auto_prune_value: 30
85107
quay_host: "{{ quay_url }}"
@@ -116,7 +138,7 @@
116138
infra.quay_configuration.quay_organization:
117139
name: testansible5
118140
state: present
119-
time_machine_expiration: "1month"
141+
time_machine_expiration: "4 w"
120142
quay_host: "{{ quay_url }}"
121143
quay_token: "{{ quay_token }}"
122144
validate_certs: false

0 commit comments

Comments
 (0)