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

Fix: confusion in paths. #322

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bundle-workflow/src/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# compatible open source license.

import argparse
import os

from manifests.build_manifest import BuildManifest
from signing_workflow.signer import Signer
Expand All @@ -21,7 +20,6 @@
args = parser.parse_args()

manifest = BuildManifest.from_file(args.manifest)
basepath = os.path.dirname(os.path.abspath(args.manifest.name))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

signer = Signer()

for component in manifest.components:
Expand Down
10 changes: 5 additions & 5 deletions bundle-workflow/src/signing_workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# This page intentionally left blank.
11 changes: 5 additions & 6 deletions bundle-workflow/src/signing_workflow/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import os
import pathlib
import sys

from git.git_repository import GitRepository

Expand All @@ -17,12 +16,10 @@
The signed artifacts will be found in the same location as the original artifacts.
"""

sys.path.insert(0, "../git")


class Signer:

ACCEPTED_FILE_TYPES = ['.zip', '.jar', '.war', '.pom', '.module', '.tar.gz']
ACCEPTED_FILE_TYPES = [".zip", ".jar", ".war", ".pom", ".module", ".tar.gz"]

def __init__(self):
self.git_repo = GitRepository(self.get_repo_url(), "HEAD")
Expand All @@ -32,14 +29,16 @@ def __init__(self):
def sign_artifacts(self, artifacts, basepath):
for artifact in artifacts:
if self.is_invalid_file_type(artifact):
print(f'Skipping signing of file ${artifact}')
print(f"Skipping signing of file ${artifact}")
continue
location = os.path.join(basepath, artifact)
self.sign(location)
self.verify(location + ".asc")

def is_invalid_file_type(self, file_name):
return ''.join(pathlib.Path(file_name).suffixes) not in Signer.ACCEPTED_FILE_TYPES
return (
"".join(pathlib.Path(file_name).suffixes) not in Signer.ACCEPTED_FILE_TYPES
)

def get_repo_url(self):
if "GITHUB_TOKEN" in os.environ:
Expand Down
11 changes: 0 additions & 11 deletions bundle-workflow/tests/signing_workflow/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions bundle-workflow/tests/signing_workflow/test_sign.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# This page intentionally left blank.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# This page intentionally left blank.
12 changes: 12 additions & 0 deletions bundle-workflow/tests/tests_signing_workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import os
import sys

sys.path.insert(
0, os.path.realpath(os.path.join(os.path.dirname(__file__), "../../src"))
)
32 changes: 32 additions & 0 deletions bundle-workflow/tests/tests_signing_workflow/test_sign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
from unittest.mock import MagicMock, call, patch

from src.signing_workflow.signer import Signer


class TestSigner(unittest.TestCase):
@patch("src.signing_workflow.signer.GitRepository")
def test_accepted_file_types(self, git_repo):

artifacts = [
"bad-xml.xml",
"the-jar.jar",
"the-zip.zip",
"the-war.war",
"the-pom.pom",
"the-module.module",
"the-tar.tar.gz",
"random-file.txt",
]
expected = [
call("/path/the-jar.jar"),
call("/path/the-zip.zip"),
call("/path/the-war.war"),
call("/path/the-pom.pom"),
call("/path/the-module.module"),
call("/path/the-tar.tar.gz"),
]
signer = Signer()
signer.sign = MagicMock()
signer.sign_artifacts(artifacts, "/path")
self.assertEqual(signer.sign.call_args_list, expected)