Skip to content

Commit

Permalink
Change auth methods for pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
sle118 committed Nov 24, 2022
1 parent 0e12f7f commit 3144cf5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ RUN : \
&& pip show pygit2 \
&& python --version \
&& pip --version \
&& pip3 install protobuf grpcio-tools \
&& rm -rf $IDF_TOOLS_PATH/dist \
&& :

Expand Down
25 changes: 16 additions & 9 deletions docker/build_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def load_repository(cls, path: str = os.getcwd()) -> Repository:
print(f'Opening repository from {path}')
cls.repo = Repository(path=path)
except GitError as ex:
print_error(f"Unable to access the repository.\nContent of {path}:\n{NEWLINE_CHAR.join(get_file_list(path, 1))}")
print_error(f"Unable to access the repository({ex}).\nContent of {path}:\n{NEWLINE_CHAR.join(get_file_list(path, 1))}")
raise
return cls.repo

Expand Down Expand Up @@ -844,6 +844,14 @@ def get_changed_items(repo: Repository) -> Dict:
def is_dirty(repo: Repository) -> bool:
return len(get_changed_items(repo)) > 0

def push_with_method(auth_method:str,token:str,remote: Remote,reference):
success:bool = False
try:
remote.push(reference, callbacks=RemoteCallbacks(pygit2.UserPass(auth_method, token)))
success=True
except Exception as ex:
print_error(f'Error pushing with auth method {auth_method}: {ex}.')
return success

def push_if_change(repo: Repository, token: str, source_path: str, manif_json):
if is_dirty(repo):
Expand All @@ -861,15 +869,14 @@ def push_if_change(repo: Repository, token: str, source_path: str, manif_json):
origin: Remote = repo.remotes['origin']
print(
f'Pushing commit {format_commit(repo[commit])} to url {origin.url}')
credentials = UserPass(token, 'x-oauth-basic') # passing credentials
remote: Remote = repo.remotes['origin']
# remote.credentials = credentials
auth_method = 'x-access-token'
remote.push([reference], callbacks=RemoteCallbacks(
pygit2.UserPass(auth_method, token)))
print(
f'::notice Web installer updated for {format_artifact_from_manifest(manif_json)}')

auth_methods = ['x-access-token','x-oauth-basic']
for method in auth_methods:
if push_with_method('x-access-token', token, remote, [reference]):
print(f'::notice Web installer updated for {format_artifact_from_manifest(manif_json)}')
return

raise Exception('Unable to push web installer changes to installer repo')
else:
print(f'WARNING: No change found. Skipping update')

Expand Down

0 comments on commit 3144cf5

Please sign in to comment.