Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnlyRewriteDeprecatedURLs and AlwaysRewriteDistributionURLs #65

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion code/repo_sync
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,10 @@ def main():
reposadocommon.print_stderr('ERROR: curl tool not found at %s',
reposadocommon.pref('CurlPath'))
exit(-1)
if not reposadocommon.pref('LocalCatalogURLBase'):
if (not reposadocommon.pref('LocalCatalogURLBase') or
(reposadocommon.pref('AlwaysRewriteDistributionURLs') and
not reposadocommon.pref('OnlyRewriteDeprecatedURLs')
)):
download_packages = False
else:
download_packages = True
Expand Down
41 changes: 38 additions & 3 deletions code/reposadolib/reposadocommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,38 @@ def rewriteOneURL(full_url):

def rewriteURLsForProduct(product):
'''Rewrites the URLs for a product'''
if (not pref('AlwaysRewriteDistributionURLs') and
not pref('OnlyRewriteDeprecatedURLs')):
if 'ServerMetadataURL' in product:
product['ServerMetadataURL'] = rewriteOneURL(
product['ServerMetadataURL'])
for package in product.get('Packages', []):
if 'URL' in package:
package['URL'] = rewriteOneURL(package['URL'])
if 'MetadataURL' in package:
package['MetadataURL'] = rewriteOneURL(
package['MetadataURL'])
if 'IntegrityDataURL' in package:
package['IntegrityDataURL'] = rewriteOneURL(
package['IntegrityDataURL'])
# workaround for 10.8.2 issue where client ignores local pkg
# and prefers Apple's URL. Need to revisit as we better understand
# this issue
if 'Digest' in package:
# removing the Digest causes 10.8.2 to use the replica's URL
# instead of Apple's
del package['Digest']
if (pref('AlwaysRewriteDistributionURLs') or
(not pref('AlwaysRewriteDistributionURLs') and
not pref('OnlyRewriteDeprecatedURLs'))):
distributions = product['Distributions']
for dist_lang in distributions.keys():
distributions[dist_lang] = rewriteOneURL(
distributions[dist_lang])


def rewriteURLsForDeprecatedProduct(product):
'''Rewrites the URLs for a deprecated product'''
if 'ServerMetadataURL' in product:
product['ServerMetadataURL'] = rewriteOneURL(
product['ServerMetadataURL'])
Expand All @@ -355,8 +387,8 @@ def rewriteURLsForProduct(product):
package['IntegrityDataURL'] = rewriteOneURL(
package['IntegrityDataURL'])
# workaround for 10.8.2 issue where client ignores local pkg
# and prefers Apple's URL. Need to revisit as we better understand this
# issue
# and prefers Apple's URL. Need to revisit as we better understand
# this issue
if 'Digest' in package:
# removing the Digest causes 10.8.2 to use the replica's URL
# instead of Apple's
Expand Down Expand Up @@ -439,7 +471,10 @@ def writeBranchCatalogs(localcatalogpath):
'has been deprecated. Will use cached info '
'and packages.',
product_key, title, version, branch)
rewriteURLsForProduct(catalog_entry)
if pref('OnlyRewriteDeprecatedURLs'):
rewriteURLsForDeprecatedProduct(catalog_entry)
else:
rewriteURLsForProduct(catalog_entry)
catalog['Products'][product_key] = catalog_entry
continue
else:
Expand Down
26 changes: 25 additions & 1 deletion docs/reposado_preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ The following keys are optional and may be defined in preferences.plist for spec

Defaults to displaying size in bytes.

- OnlyRewriteDeprecatedURLs

This boolean preference allows for you to choose to only rewrite deprecated product URLs so they point to your LocalCatalogURLBase. Products currently available in Apple's catalogs will continue to point to Apple's CDN. This preference is intended to allow you to save bandwidth.

Note: Setting this preference requires LocalCatalogURLBase to be set and will locally cache all packages even if they will not be referenced in your catalogs.

Example:

<key>OnlyRewriteDeprecatedURLs</key>
<true/>

- AlwaysRewriteDistributionURLs

This boolean preference allows for rewriting of the DistributionURLs inside the catalogs so they point to the LocalCatalogURLBase. This preference is intended for the ability to modify config-data on products without replicating packages. More info for why you would want to do this [here.][1]

Note: Setting this preference to True will keep reposado from downloading packages unless you also specify OnlyRewriteDeprecatedURLs.

Example:

<key>AlwaysRewriteDistributionURLs</key>
<true/>


## Example preferences.plist

Expand All @@ -122,4 +144,6 @@ The following keys are optional and may be defined in preferences.plist for spec
<key>UpdatesMetadataDir</key>
<string>/Volumes/data/reposado/metadata</string>
</dict>
</plist>
</plist>

[1]: https://managingosx.wordpress.com/2015/01/30/gatekeeper-configuration-data-and-xprotectplistconfigdata-and-munki-and-reposado-oh-my/