Skip to content
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
9 changes: 6 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install dependencies
working-directory: v3 # Set the working directory to v3 where pyproject.toml is located
working-directory: v3
run: |
sudo apt-get install libldap2-dev libsasl2-dev
uv sync --all-extras --dev
- name: Testing with ruff
working-directory: v3 # Ensure ruff runs in the correct directory
- name: Check with ruff
working-directory: v3
run: uv run ruff check
- name: Format with ruff
working-directory: v3
run: uv run ruff format --diff
30 changes: 15 additions & 15 deletions v3/server/api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import asfquart
APP = asfquart.APP

APP = asfquart.APP
33 changes: 17 additions & 16 deletions v3/server/bin/asf-load-ldap.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env python3

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import pathlib
import logging
Expand Down Expand Up @@ -43,13 +45,12 @@ def main():
pdb.db.conn.execute('BEGIN TRANSACTION')

client = ldap.initialize(LDAP_URL)
binddn, bindpw = [ s.strip()
for s in open(THIS_DIR / 'bind.txt').readlines()[:2] ]
#print('BIND:', binddn, bindpw)
binddn, bindpw = [s.strip() for s in open(THIS_DIR / 'bind.txt').readlines()[:2]]
# print('BIND:', binddn, bindpw)
client.simple_bind_s(binddn, bindpw)

with asfpy.stopwatch.Stopwatch('run LDAP full scan'):
results = client.search_s(LDAP_DN, ldap.SCOPE_SUBTREE, 'uid=*', attrlist=None) #[LDAP_ATTR,])
results = client.search_s(LDAP_DN, ldap.SCOPE_SUBTREE, 'uid=*', attrlist=None)

count = 0
for r in results:
Expand Down
26 changes: 14 additions & 12 deletions v3/server/bin/fetch-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Fetch latest bootstrap, and places files into our git working copy.

Expand Down
63 changes: 40 additions & 23 deletions v3/server/bin/load-fakedata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/env python3

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Load a bunch of fake data into the database, for stuff to work with.

Expand All @@ -25,6 +27,7 @@
import faker

import steve.election

### we shouldn't need this. do so, for now.
import steve.crypto

Expand All @@ -49,8 +52,7 @@ def main(args):
def gen_election(owner_pid, issue_count=10):
title = FAKE.sentence()
e = steve.election.Election.create(DB_FNAME, title, owner_pid)
_LOGGER.info(f'Created election[E:{e.eid}]: "{title}",'
f' by owner "{owner_pid}"')
_LOGGER.info(f'Created election[E:{e.eid}]: "{title}", by owner "{owner_pid}"')

for _ in range(issue_count):
title = FAKE.sentence()
Expand Down Expand Up @@ -78,13 +80,28 @@ def random_owner():
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)

parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--elections', type=int, required=False, default=10,
help="The number of elections to create.")
parser.add_argument('--issues', type=int, required=False, default=10,
help="The number of issues per election to create.")
parser.add_argument('--owner-pid', type=str, required=False,
help="The owner's Apache ID to use for created elections."
" If not set, pick a random existing person.")

parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'--elections',
type=int,
required=False,
default=10,
help='The number of elections to create.',
)
parser.add_argument(
'--issues',
type=int,
required=False,
default=10,
help='The number of issues per election to create.',
)
parser.add_argument(
'--owner-pid',
type=str,
required=False,
help="The owner's Apache ID to use for created elections."
' If not set, pick a random existing person.',
)
main(parser.parse_args())
28 changes: 14 additions & 14 deletions v3/server/config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

server:
# Default port for the server. Typical usage is that a proxy sits
Expand Down
59 changes: 31 additions & 28 deletions v3/server/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import sys
import logging
Expand All @@ -28,11 +29,12 @@


def main():
logging.basicConfig(level=logging.DEBUG,
style='{',
format='[{asctime}|{levelname}|{name}] {message}',
datefmt=DATE_FORMAT,
)
logging.basicConfig(
level=logging.DEBUG,
style='{',
format='[{asctime}|{levelname}|{name}] {message}',
datefmt=DATE_FORMAT,
)

# Switch some loggers to INFO, rather than DEBUG
logging.getLogger('selector_events').setLevel(logging.INFO)
Expand All @@ -45,8 +47,11 @@ def main():
### is this really needed right now?
# Avoid OIDC
import asfquart.generics
asfquart.generics.OAUTH_URL_INIT = "https://oauth.apache.org/auth?state=%s&redirect_uri=%s"
asfquart.generics.OAUTH_URL_CALLBACK = "https://oauth.apache.org/token?code=%s"

asfquart.generics.OAUTH_URL_INIT = (
'https://oauth.apache.org/auth?state=%s&redirect_uri=%s'
)
asfquart.generics.OAUTH_URL_CALLBACK = 'https://oauth.apache.org/token?code=%s'

app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)

Expand All @@ -62,21 +67,19 @@ def main():
# There are other things to watch, and cause a reload.
extra_files = {
steve.election.QUERIES,
}
}

kwargs = { }
kwargs = {}
if app.cfg.server.certfile:
kwargs['certfile'] = CERTS_DIR / app.cfg.server.certfile
kwargs['keyfile'] = CERTS_DIR / app.cfg.server.keyfile
extra_files.update((kwargs['certfile'], kwargs['keyfile']))

# Spool up the app!
app.runx(port=app.cfg.server.port,
extra_files=extra_files,
**kwargs)
app.runx(port=app.cfg.server.port, extra_files=extra_files, **kwargs)

#print('LOGGERS:', sorted(_LOGGER.manager.loggerDict.keys()))
#print(_LOGGER.manager.loggerDict['sslproto'])
# print('LOGGERS:', sorted(_LOGGER.manager.loggerDict.keys()))
# print(_LOGGER.manager.loggerDict['sslproto'])


if __name__ == '__main__':
Expand Down
Loading