66
77import requests
88import logging
9+ import base64
910
1011from ..exceptions import ConfigurationInvalid
1112
1213BRANCH_HEAD_URL = "https://api.bitbucket.org/2.0/repositories/{user}/{repo}/commit/{branch}"
1314
1415logger = logging .getLogger ("octoprint.plugins.softwareupdate.version_checks.bitbucket_commit" )
1516
16- def _get_latest_commit (user , repo , branch ):
17- r = requests .get (BRANCH_HEAD_URL .format (user = user , repo = repo , branch = branch ))
17+
18+ def _get_latest_commit (user , repo , branch , api_user = None , api_password = None ):
19+ url = BRANCH_HEAD_URL .format (user = user , repo = repo , branch = branch )
20+ headers = {}
21+ if api_user is not None and api_password is not None :
22+ headers ['authorization' ] = 'Basic {}' .format (
23+ base64 .b64encode (b"{user}:{pw}" .format (user = api_user , pw = api_password )))
24+ r = requests .get (url , headers = headers )
1825
1926 if not r .status_code == requests .codes .ok :
2027 return None
@@ -34,11 +41,14 @@ def get_latest(target, check):
3441 if "branch" in check :
3542 branch = check ["branch" ]
3643
44+ api_user = check ["api_user" ] if 'api_user' in check else None
45+ api_password = check ["api_password" ] if 'api_password' in check else None
46+
3747 current = None
3848 if "current" in check :
3949 current = check ["current" ]
4050
41- remote_commit = _get_latest_commit (check ["user" ], check ["repo" ], branch )
51+ remote_commit = _get_latest_commit (check ["user" ], check ["repo" ], branch , api_user , api_password )
4252
4353 information = dict (
4454 local = dict (name = "Commit {commit}" .format (commit = current if current is not None else "unknown" ), value = current ),
0 commit comments