Update Gitea repository mirror authentication credentials

descriptionStandard

Recently I had to update a few hundreds repository mirror authentication details; after just a handful I explored the API and was surprised that the API had not route available to achieve this.

After some poking around; the repositories stored at the GITEA data path (repository storage) the config file contains the username and password/token combination as part of the url.

This provides us with something that can be used in a find and replace operation.

A script I put together for similar find and replace operations (SSL certificate names) found at: Find and replace script could be used here. Or alternatively you may form your own method.

The flow:

  • Identify the string to be replaced.
  • Form the replacement.
  • Test a dry-run.

Script arguments

usage() {
    echo "Replacer usage: $0 [OPTIONS]"
    echo "Performs a search and replace operation across all files in a directory."
    echo "Required:"
    echo "  -d, --directory PATH      Path to perform operation"
    echo "  -s, --search STR          Search term" 
    echo "  -r, --replace STR         Replacement term" 
    echo "  -n, --name STR            Limit files to a specific name" 
}

Example usage

As an example, the following replaces a search term recursively on all files within a path limit the filename to “config” the dryrun flag will print files that would be changed:

bash replacer.sh -d "/path/to/data/gitea-repositories/" -s "https://oauth2:old-secret-to-replace@github.com" -r "https://oauth2:new-secret-here@github.com" --name "config" --dryrun

Leave a Reply

I'm pleased you have chosen to leave a comment and engage in a meaningful conversation. Please keep in mind that comments are moderated according to our privacy policy, links are set to nofollow.

Your email address will not be published. Required fields are marked *