Skip to content

Commit

Permalink
SW Update check type 'bitbucket_commit' now supports API credentials …
Browse files Browse the repository at this point in the history
…for private repos
  • Loading branch information
Andy Werner committed Jul 3, 2017
1 parent e95c460 commit 4c6dfed
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@

import requests
import logging
import base64

from ..exceptions import ConfigurationInvalid

BRANCH_HEAD_URL = "https://api.bitbucket.org/2.0/repositories/{user}/{repo}/commit/{branch}"

logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.bitbucket_commit")

def _get_latest_commit(user, repo, branch):
r = requests.get(BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch))

def _get_latest_commit(user, repo, branch, api_user=None, api_password=None):
url = BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch)
headers = {}
if api_user is not None and api_password is not None:
headers['authorization'] = 'Basic {}'.format(
base64.b64encode(b"{user}:{pw}".format(user=api_user, pw=api_password)))
r = requests.get(url, headers=headers)

if not r.status_code == requests.codes.ok:
return None
Expand All @@ -34,11 +41,14 @@ def get_latest(target, check):
if "branch" in check:
branch = check["branch"]

api_user = check["api_user"] if 'api_user' in check else None
api_password = check["api_password"] if 'api_password' in check else None

current = None
if "current" in check:
current = check["current"]

remote_commit = _get_latest_commit(check["user"], check["repo"], branch)
remote_commit = _get_latest_commit(check["user"], check["repo"], branch, api_user, api_password)

information = dict(
local=dict(name="Commit {commit}".format(commit=current if current is not None else "unknown"), value=current),
Expand Down

0 comments on commit 4c6dfed

Please sign in to comment.