How to set expiration date via API calls

188 views
Skip to first unread message

RPGang

unread,
Jul 6, 2023, 10:30:11 AM7/6/23
to quay-sig
Hello,

I am trying to set an expiration date on old tags using the quay.io API but it doesn't seem to work. 
Can someone help me here with the correct url, method and json I should use for it to work?

Flavian Missi (they / them)

unread,
Jul 6, 2023, 10:36:53 AM7/6/23
to RPGang, quay-sig
Hi there,

Would it work for you to set the expiration as a label in the Dockerfile? i.e quay.expires-after=3w
You can read more about it in our docs: https://docs.projectquay.io/use_quay.html#tag-expiration

--
You received this message because you are subscribed to the Google Groups "quay-sig" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quay-sig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quay-sig/44b49182-742e-419c-84d1-565aaa854281n%40googlegroups.com.

Ivan Bazulic

unread,
Jul 6, 2023, 10:50:39 AM7/6/23
to Flavian Missi (they / them), RPGang, quay-sig
Hey, 

The API request should be as follows:

curl -X PUT -H "Authorization: Bearer your_token_here" -H "Content-type: application/json" -d '{"expiration": unix_time_stamp}' https:quay.io/api/v1/repository/{NAMESPACE}/{REPO}/tag/{tag-name}

The important thing here is that the time stamp must be in Unix time format, you cannot just apply the number of seconds or days to the request. Note also that RBAC rules apply, the token you're using must be created on behalf of the user who has write access to the repo where you want to change expiration date.

HTH!



--

IVAN BAŽULIĆ

PRINCIPAL SUPPORT ENGINEER

Red Hat Canada Ltd.

90 Eglinton Ave E,
Suite 502,
Toronto, ON M4P 2Y3

ibaz...@redhat.com    M: +385959269281     IM: ibazulic

RPGang

unread,
Jul 9, 2023, 3:15:41 AM7/9/23
to quay-sig
Reposting my answers again because apparently "Reply to author" doesn't post my comments here:

1. I want to add expiration date to all the old tags we have for garbage collection purposes, all the tags we will push from now on will have it as part of their Dockerfile.

2. I am using python requests with the following code:

    payload = {'expiration': 1209600}
    payload = json.dumps(payload)
    headers = {"Authorization": "Bearer <Token>", 'Content-Type': 'application/json',
               "Accept": "application/json"}
    res = requests.put(url="https://quay.io/api/v1/repository/{NAMESPACE}/{REPO}/tag/{TAG}",
                       headers=headers, json=payload)

And the response I am getting is: 
"detail": "\'{\\"expiration\\": 1209600}\' is not of type \'object\' Failed validating \'type\' in schema
with a status code of 400

Daniel Messer

unread,
Jul 10, 2023, 4:39:12 AM7/10/23
to RPGang, quay-sig
Hi,


Give the curl command a try that Ivan posted and ensure that your python script is doing the same. I think the problem is that you are serializing the JSON data twice, once via payload = json.dumps(payload) and a second time when you hand it to requests.put(json=payload...). You may want to try passing the payload directly to json= without json.dumps() before or, with json dumps but then into the request body directly via requests.put(data=payload...).

Also note that the value of expiration is a timestamp in the future. Your example of 1209600 is the 15th of January 1970. You cannot supply expiration dates in the past.

HTH,
Daniel



--
Daniel Messer

Product Management

Red Hat OpenShift

RPGang

unread,
Jul 12, 2023, 5:23:15 AM7/12/23
to quay-sig
The problem was indeed the fact that the timestamp I used was in the past, unfortunately the error log was so confusing that I didn't even check the validity of the timestamp.
Thank you all for the help! :)

Reply all
Reply to author
Forward
0 new messages