Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit ed6ed30

Browse files
authored
Merge pull request #294 from stacklok/fix-linting
fix: fix formatting issues
2 parents 2505847 + 11f999f commit ed6ed30

File tree

13 files changed

+341
-269
lines changed

13 files changed

+341
-269
lines changed

cert_gen.py

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import datetime
2+
import os
3+
14
from cryptography import x509
2-
from cryptography.x509.oid import NameOID, ExtendedKeyUsageOID
35
from cryptography.hazmat.primitives import hashes, serialization
46
from cryptography.hazmat.primitives.asymmetric import rsa
5-
import datetime
6-
import os
7+
from cryptography.x509.oid import ExtendedKeyUsageOID, NameOID
8+
79

810
def generate_certificates(cert_dir="certs"):
911
"""Generate self-signed certificates with proper extensions for HTTPS proxy"""
@@ -22,12 +24,14 @@ def generate_certificates(cert_dir="certs"):
2224
ca_public_key = ca_private_key.public_key()
2325

2426
# CA BEGIN
25-
name = x509.Name([
26-
x509.NameAttribute(NameOID.COMMON_NAME, "Proxy Pilot CA"),
27-
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Proxy Pilot"),
28-
x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "Development"),
29-
x509.NameAttribute(NameOID.COUNTRY_NAME, "UK"),
30-
])
27+
name = x509.Name(
28+
[
29+
x509.NameAttribute(NameOID.COMMON_NAME, "Proxy Pilot CA"),
30+
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Proxy Pilot"),
31+
x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "Development"),
32+
x509.NameAttribute(NameOID.COUNTRY_NAME, "UK"),
33+
]
34+
)
3135

3236
builder = x509.CertificateBuilder()
3337
builder = builder.subject_name(name)
@@ -54,11 +58,11 @@ def generate_certificates(cert_dir="certs"):
5458
key_cert_sign=True, # This is a CA
5559
crl_sign=True,
5660
encipher_only=False,
57-
decipher_only=False
61+
decipher_only=False,
5862
),
5963
critical=True,
6064
)
61-
65+
6266
ca_cert = builder.sign(
6367
private_key=ca_private_key,
6468
algorithm=hashes.SHA256(),
@@ -67,51 +71,55 @@ def generate_certificates(cert_dir="certs"):
6771
# Save CA certificate and key
6872

6973
with open("certs/ca.crt", "wb") as f:
70-
f.write(ca_cert.public_bytes(serialization.Encoding.PEM))
74+
f.write(ca_cert.public_bytes(serialization.Encoding.PEM))
7175

7276
with open("certs/ca.key", "wb") as f:
73-
f.write(ca_private_key.private_bytes(
74-
encoding=serialization.Encoding.PEM,
75-
format=serialization.PrivateFormat.PKCS8,
76-
encryption_algorithm=serialization.NoEncryption()
77-
))
77+
f.write(
78+
ca_private_key.private_bytes(
79+
encoding=serialization.Encoding.PEM,
80+
format=serialization.PrivateFormat.PKCS8,
81+
encryption_algorithm=serialization.NoEncryption(),
82+
)
83+
)
7884
# CA END
7985

8086
# SERVER BEGIN
8187

82-
## Generate new certificate for domain
88+
# Generate new certificate for domain
8389
server_key = rsa.generate_private_key(
8490
public_exponent=65537,
8591
key_size=2048, # 2048 bits is sufficient for domain certs
8692
)
8793

88-
name = x509.Name([
89-
x509.NameAttribute(NameOID.COMMON_NAME, "Proxy Pilot CA"),
90-
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Proxy Pilot Generated"),
91-
])
94+
name = x509.Name(
95+
[
96+
x509.NameAttribute(NameOID.COMMON_NAME, "Proxy Pilot CA"),
97+
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Proxy Pilot Generated"),
98+
]
99+
)
92100

93101
builder = x509.CertificateBuilder()
94102
builder = builder.subject_name(name)
95103
builder = builder.issuer_name(ca_cert.subject)
96104
builder = builder.public_key(server_key.public_key())
97105
builder = builder.serial_number(x509.random_serial_number())
98106
builder = builder.not_valid_before(datetime.datetime.utcnow())
99-
builder = builder.not_valid_after(
100-
datetime.datetime.utcnow() + datetime.timedelta(days=365)
101-
)
107+
builder = builder.not_valid_after(datetime.datetime.utcnow() + datetime.timedelta(days=365))
102108

103-
# Add domain to SAN
109+
# Add domain to SAN
104110
builder = builder.add_extension(
105111
x509.SubjectAlternativeName([x509.DNSName("localhost")]),
106112
critical=False,
107113
)
108114

109115
# Add extended key usage
110116
builder = builder.add_extension(
111-
x509.ExtendedKeyUsage([
112-
ExtendedKeyUsageOID.SERVER_AUTH,
113-
ExtendedKeyUsageOID.CLIENT_AUTH,
114-
]),
117+
x509.ExtendedKeyUsage(
118+
[
119+
ExtendedKeyUsageOID.SERVER_AUTH,
120+
ExtendedKeyUsageOID.CLIENT_AUTH,
121+
]
122+
),
115123
critical=False,
116124
)
117125

@@ -130,31 +138,41 @@ def generate_certificates(cert_dir="certs"):
130138
f.write(certificate.public_bytes(serialization.Encoding.PEM))
131139

132140
with open("certs/server.key", "wb") as f:
133-
f.write(server_key.private_bytes(
134-
encoding=serialization.Encoding.PEM,
135-
format=serialization.PrivateFormat.PKCS8,
136-
encryption_algorithm=serialization.NoEncryption()
137-
))
138-
141+
f.write(
142+
server_key.private_bytes(
143+
encoding=serialization.Encoding.PEM,
144+
format=serialization.PrivateFormat.PKCS8,
145+
encryption_algorithm=serialization.NoEncryption(),
146+
)
147+
)
139148

140149
print("Certificates generated successfully in the 'certs' directory")
141150
print("\nTo trust these certificates:")
142151
print("\nOn macOS:")
143-
print("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain certs/server.crt")
152+
print(
153+
"sudo security add-trusted-cert -d -r trustRoot "
154+
"-k /Library/Keychains/System.keychain certs/server.crt"
155+
)
144156
print("\nOn Windows (PowerShell as Admin):")
145-
print("Import-Certificate -FilePath \"certs\\server.crt\" -CertStoreLocation Cert:\\LocalMachine\\Root")
157+
print(
158+
'Import-Certificate -FilePath "certs\\server.crt" '
159+
'-CertStoreLocation Cert:\\LocalMachine\\Root'
160+
)
146161
print("\nOn Linux:")
147162
print("sudo cp certs/server.crt /usr/local/share/ca-certificates/proxy-pilot.crt")
148163
print("sudo update-ca-certificates")
149164
print("\nFor VSCode, add to settings.json:")
150-
print('''{
165+
print(
166+
"""{
151167
"http.proxy": "https://localhost:8989",
152168
"http.proxySupport": "on",
153169
"github.copilot.advanced": {
154170
"debug.testOverrideProxyUrl": "https://localhost:8989",
155171
"debug.overrideProxyUrl": "https://localhost:8989"
156172
}
157-
}''')
173+
}"""
174+
)
175+
158176

159177
if __name__ == "__main__":
160178
generate_certificates()

scripts/import_packages.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
class PackageImporter:
17-
def __init__(self, jsonl_dir='data', take_backup=True, restore_backup=True):
17+
def __init__(self, jsonl_dir="data", take_backup=True, restore_backup=True):
1818
self.take_backup_flag = take_backup
1919
self.restore_backup_flag = restore_backup
2020

@@ -153,12 +153,13 @@ async def run_import(self):
153153
"--jsonl-dir",
154154
type=str,
155155
default="data",
156-
help="Directory containing JSONL files. Default is 'data'."
156+
help="Directory containing JSONL files. Default is 'data'.",
157157
)
158158
args = parser.parse_args()
159159

160-
importer = PackageImporter(jsonl_dir=args.jsonl_dir, take_backup=args.take_backup,
161-
restore_backup=args.restore_backup)
160+
importer = PackageImporter(
161+
jsonl_dir=args.jsonl_dir, take_backup=args.take_backup, restore_backup=args.restore_backup
162+
)
162163
asyncio.run(importer.run_import())
163164
try:
164165
assert importer.client.is_live()

0 commit comments

Comments
 (0)