Skip to content

Commit c30c25f

Browse files
Merge pull request #23 from interlynk-io/fix/powershell-encoding
Address the byte array issue along along with encoding
2 parents ea063b5 + 0086532 commit c30c25f

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

pylynk.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import datetime
1919
import pytz
2020
import tzlocal
21+
import sys
2122
from lynkctx import LynkContext
2223

2324

@@ -33,18 +34,18 @@ def print_products(lynk_ctx):
3334

3435
# Calculate dynamic column widths
3536
name_width = max(len("NAME"), max(len(prod['name'])
36-
for prod in products))
37+
for prod in products))
3738
updated_at_width = max(len("UPDATED AT"),
3839
max(len(user_time(prod['updatedAt']))
3940
for prod in products))
4041
id_width = max(len("ID"), max(len(prod['id']) for prod in products))
4142
version_width = len("VERSIONS")
4243

4344
header = (
44-
f"{ 'NAME':<{name_width}} | "
45-
f"{ 'ID':<{id_width}} | "
46-
f"{ 'VERSIONS':<{version_width}} | "
47-
f"{ 'UPDATED AT':<{updated_at_width}} | "
45+
f"{'NAME':<{name_width}} | "
46+
f"{'ID':<{id_width}} | "
47+
f"{'VERSIONS':<{version_width}} | "
48+
f"{'UPDATED AT':<{updated_at_width}} | "
4849
)
4950
print(header)
5051

@@ -119,18 +120,21 @@ def print_versions(lynk_ctx):
119120

120121
return 0
121122

123+
122124
def download_sbom(lynk_ctx):
123125
sbom = lynk_ctx.download()
124126
if sbom is None:
125127
print('Failed to fetch SBOM')
126128
return 1
127129

128-
print(sbom.encode("utf-8"))
130+
sys.stdout.buffer.write(sbom.encode("utf-8", errors='ignore'))
129131
return 0
130132

133+
131134
def upload_sbom(lynk_ctx, sbom_file):
132135
return lynk_ctx.upload(sbom_file)
133-
136+
137+
134138
def setup_args():
135139
parser = argparse.ArgumentParser(description='Interlynk command line tool')
136140
parser.add_argument('--verbose', '-v', action='count', default=0)
@@ -164,11 +168,13 @@ def setup_args():
164168
help="Security token")
165169

166170
download_parser = subparsers.add_parser("download", help="Download SBOM")
167-
download_group = download_parser.add_mutually_exclusive_group(required=True)
171+
download_group = download_parser.add_mutually_exclusive_group(
172+
required=True)
168173
download_group.add_argument("--prod", help="Product name")
169174
download_group.add_argument("--prodId", help="Product ID")
170175

171-
download_group = download_parser.add_mutually_exclusive_group(required=True)
176+
download_group = download_parser.add_mutually_exclusive_group(
177+
required=True)
172178
download_group.add_argument("--ver", help="Version")
173179
download_group.add_argument("--verId", help="Version ID")
174180

@@ -186,18 +192,21 @@ def setup_log_level(args):
186192
logging.basicConfig(level=logging.ERROR)
187193
logging.basicConfig(level=logging.DEBUG)
188194

195+
189196
def setup_lynk_context(args):
190197
return LynkContext(
191198
os.environ.get('INTERLYNK_API_URL'),
192-
getattr(args, 'token', None) or os.environ.get('INTERLYNK_SECURITY_TOKEN'),
199+
getattr(args, 'token', None) or os.environ.get(
200+
'INTERLYNK_SECURITY_TOKEN'),
193201
getattr(args, 'prodId', None),
194202
getattr(args, 'prod', None),
195203
getattr(args, 'envId', None),
196204
getattr(args, 'env', None),
197205
getattr(args, 'verId', None),
198206
getattr(args, 'ver', None)
199207
)
200-
208+
209+
201210
def main() -> int:
202211
args = setup_args()
203212
setup_log_level(args)
@@ -207,17 +216,18 @@ def main() -> int:
207216

208217
if args.subcommand == "prods":
209218
print_products(lynk_ctx)
210-
elif args.subcommand == "vers":
219+
elif args.subcommand == "vers":
211220
print_versions(lynk_ctx)
212221
elif args.subcommand == "upload":
213222
upload_sbom(lynk_ctx, args.sbom)
214223
elif args.subcommand == "download":
215224
download_sbom(lynk_ctx)
216225
else:
217-
print("Missing or invalid command. \
226+
print("Missing or invalid command. \
218227
Supported commands: {prods, upload, download, sign, verify}")
219-
exit(1)
228+
exit(1)
220229
exit(0)
221230

231+
222232
if __name__ == "__main__":
223233
main()

0 commit comments

Comments
 (0)