Bug 14768

Summary: GitHub git protocol urls need to be scrubbed
Product: [Yocto Project Subprojects] Layer Index Reporter: Tim Orling <tim.orling>
Component: Layer Index MetadataAssignee: Tim Orling <tim.orling>
Status: RESOLVED FIXED QA Contact: apoorv sangal <apoorvsangal>
Severity: normal    
Priority: Medium+ CC: konrad.scherer, mhalstead, randy.macleod
Version: unspecified   
Target Milestone: 4.1 M1   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Tim Orling 2022-03-24 15:10:24 UTC
Layers which have git protocol urls for GitHub need to switch to https. GitHub has blocked unauthenticated git protocol.

https://github.blog/2021-09-01-improving-git-protocol-security-github/
Comment 1 Randy MacLeod 2022-03-31 14:36:05 UTC
Is this something that Michael can do in the database?
Comment 2 Konrad Scherer 2022-04-01 13:50:14 UTC
Yes from the Admin interface all the project url for each layers can be updated. 

Django does support custom commands and it should be possible to make a command that will iterate through the layers and update any github urls.
Comment 3 Tim Orling 2022-04-10 18:45:20 UTC
The following should fix it:

UPDATE layerindex_layeritem
    SET layerindex_layeritem.vcs_url = REPLACE(layerindex_layeritem.vcs_url,'git://github.com', 'https://github.com')
    WHERE layerindex_layeritem.vcs_url LIKE "git://github.com%";
Comment 4 Tim Orling 2022-04-11 22:04:39 UTC
After discussing with Paul, we do not want to do SQL directly. I'll need to refactor for 'manage.py shell' which I might have permissions to do (after testing on local instance).
Comment 5 Tim Orling 2022-04-20 17:36:36 UTC
Using manage.py shell:

from django.db.models import Value
from django.db.models.functions import Replace
from layerindex.models import LayerItem

layers = LayerItem.objects.all().filter(vcs_url__startswith='git://github.com')
layers.update(vcs_url=Replace('vcs_url', Value('git://github.com'), Value('https://github.com')))
Comment 6 Tim Orling 2022-04-20 21:25:01 UTC
To get to the shell:
docker exec -it <layersapp> sh -c "/opt/layerindex/manage.py shell"

Count before fix:
106