Skip to content

Commit

Permalink
Add certifi for urllib ssl context
Browse files Browse the repository at this point in the history
  • Loading branch information
n8felton committed Jan 25, 2024
1 parent c2bcb34 commit f2e22de
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion SharedProcessors/GitLabReleasesInfoProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
# limitations under the License.
"""Shared processor to allow recipes to download releases from GitLab instances."""

import certifi
import json
import os
import re
import ssl
from urllib.request import Request, urlopen

from autopkglib import Processor, ProcessorError, get_autopkg_version
Expand Down Expand Up @@ -85,6 +87,10 @@ class GitLabReleasesInfoProvider(Processor):
},
}

def ssl_context_certifi(self):
"""Provide ssl context using certifi certificate store."""
return ssl.create_default_context(cafile=certifi.where())

def gitlab_api_get(self, endpoint):
"""Helps to communicate with the GitLab API by setting necessary headers."""
GITLAB_HOSTNAME = self.env.get("GITLAB_HOSTNAME")
Expand All @@ -101,7 +107,7 @@ def gitlab_api_get(self, endpoint):
}
url = f"{GITLAB_API_BASE_URL}{endpoint}"
req = Request(url, headers=headers)
with urlopen(req) as response:
with urlopen(req, context=self.ssl_context_certifi()) as response:
data = response.read()
return data

Expand Down

0 comments on commit f2e22de

Please sign in to comment.