pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
859 stars 485 forks source link

Feature Request - Jenkins API Token Revoke #782

Open vovkanaz opened 4 years ago

vovkanaz commented 4 years ago
Jenkinsapi VERSION

2.222.4.3

Jenkins VERSION

2.222.4.3

SUMMARY

Right now we have the possibility to jenkins.generate_new_api_token but for the rotating purposes, there is no any option to revoke existed API token

EXPECTED RESULTS

Something like that

def revoke_api_token(self, token_name='Token By jenkinsapi python', token_uuid):
        subUrl = 'me/descriptorByName/jenkins.security.ApiTokenProperty/revoke'
        url = '%s%s' % (self.baseurl, subUrl)
        data = urlencode({'TokenName': token_name})
        response = self.requester.post_and_confirm_status(url, data=data)
        print("Token has been succesfully revoked")
ACTUAL RESULTS

Actual results are only to parse HTML: https://jenkins_url/cjoc/user/user_name/configure Get Value of token name and token UUID and create custom method which will make possible to revoke exiting API token

USEFUL INFORMATION

https://www.jenkins.io/blog/2018/07/02/new-api-token-system/

joelee2012 commented 3 years ago

@vovkanaz maybe you can try https://api4jenkins.readthedocs.io/en/latest/user/example.html#user