Skip to content

Commit

Permalink
Merge dev into main (#74)
Browse files Browse the repository at this point in the history
* 🐛 Fix incorrect module path for update user roles (#51)

* 🚑  Update User Roles: Use sync search and add summary (#52)

* 🚑 Use sync search and add summary for searches and actions

* Formatted code with black --line-length 120

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Better summary for update user roles job (#53)

* 🚑 Use sync search and add summary for searches and actions

* Formatted code with black --line-length 120

* better debugging

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Update user.py

* 🚑 Correct logic for matched user sets + role filtering (#55)

* 🚑 correct logic for matched user sets + role filtering

* Formatted code with black --line-length 120

* Update role filter logic in user.py

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Fix update user role cmd (#56)

* 🚑 correct logic for matched user sets + role filtering

* Formatted code with black --line-length 120

* Update role filter logic in user.py

* Formatted code with black --line-length 120

* aliasing

* Update user.py

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Fix update user role cmd (#57)

* 🚑 correct logic for matched user sets + role filtering

* Formatted code with black --line-length 120

* Update role filter logic in user.py

* Formatted code with black --line-length 120

* aliasing

* Update user.py

* Update user.py

* Formatted code with black --line-length 120

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* ✨ Use paged search to support larger data sets (#58)

* 🚑 correct logic for matched user sets + role filtering

* Formatted code with black --line-length 120

* Update role filter logic in user.py

* Formatted code with black --line-length 120

* aliasing

* Update user.py

* Update user.py

* Formatted code with black --line-length 120

* implement paging because we love ldap ❤️

* remove test case + add var for page size

* Formatted code with black --line-length 120

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* Bump setuptools from 71.1.0 to 72.0.0 (#60)

Bumps [setuptools](https://github.com/pypa/setuptools) from 71.1.0 to 72.0.0.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v71.1.0...v72.0.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* 🐛 Fix error handling for policy/role recreation (#65)

* 🐛 error handling for policy/role recreation

* 🎨 formatting

* ♻️ Add image build (#66)

* 🎨 formatting

* 🔧 Implement Ruff as required check instead of Black creating a commit re-formatting code (#73)

* 🔧 Implement Ruff as check instead of Black creating a commit

* Update python-checks.yml

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent 191ef62 commit 653bfa7
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 123 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/format-python.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "Image Build"

on:
workflow_dispatch:
push:
tags:
- 'v*'

run-name: "Image Build for tag ${{ github.ref_name }}"

permissions:
packages: write
contents: write

jobs:
build-and-push:
runs-on: ubuntu-22.04

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Create safe tag for image
id: safe_tag
run: |
echo "SAFE_TAG=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9.]/-/g')" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v3

- name: Log into ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push to ghcr
id: build_publish
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: true
tags: ghcr.io/ministryofjustice/hmpps-ldap-automation:${{ steps.safe_tag.outputs.SAFE_TAG }}
build-args: |
VERSION_REF=${{ steps.BumpVersionAndPushTag.outputs.new_tag }}
- name: Slack failure notification
if: ${{ failure() }}
uses: slackapi/slack-github-action@70cd7be8e40a46e8b0eced40b0de447bdb42f68e # v1.26.0
with:
payload: |
{"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]}
env:
SLACK_WEBHOOK_URL: ${{ secrets.PWO_PUBLIC_SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
71 changes: 71 additions & 0 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Ensure formatted code
on:
pull_request:
types: [ opened, edited, reopened, synchronize, ready_for_review ]
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
format_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Check formatting for Python code
env:
GH_TOKEN: ${{ github.token }}
run: |
set +e
output=$(ruff format --check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "All Python code is properly formatted."
gh pr comment ${{ github.event.pull_request.number }} --body ":white_check_mark: All Python code is properly formatted."
else
echo "$output"
echo "<details><summary>:rotating_light: Python code is not properly formatted. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff format` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
fi
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Lint Python code
env:
GH_TOKEN: ${{ github.token }}
run: |
set +e
output=$(ruff check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "No linting errors found."
gh pr comment ${{ github.event.pull_request.number }} --body ":white_check_mark: No linting errors found in Python code."
else
echo "$output"
echo "<details><summary>:rotating_light: Linting errors found in Python code. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Tip: You can run `ruff check --fix` to fix automatically fixable errors.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
fi
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.10-alpine

LABEL org.opencontainers.image.source = "https://github.com/ministryofjustice/hmpps-ldap-automation-cli"

ARG VERSION_REF=main

# Basic tools for now
RUN apk add --update --no-cache bash ca-certificates git build-base libffi-dev openssl-dev gcc musl-dev gcc g++ linux-headers build-base openldap-dev python3-dev

RUN python3 -m pip install --upgrade pip && python3 -m pip install git+https://github.com/ministryofjustice/hmpps-ldap-automation-cli.git@${VERSION_REF}

CMD ["ldap-automation"]
32 changes: 19 additions & 13 deletions cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,26 @@ def update_user_home_areas(
help="Remove role from users",
is_flag=True,
)
@click.option("-uf", "--user-filter", help="Filter to find users", required=False, default="(objectclass=*)")

@click.option(
"-uf",
"--user-filter",
help="Filter to find users",
required=False,
default="(objectclass=*)",
)
@click.option("--roles-to-filter", help="Roles to filter", required=False, default="*")
def update_user_roles(roles, user_ou, root_dn, add, remove, update_notes, user_note, user_filter, roles_to_filter):
cli.ldap_cmds.user.update_roles(
roles,
user_ou,
root_dn,
add,
remove,
update_notes,
user_note=user_note,
user_filter=user_filter,
roles_to_filter=roles_to_filter,
)
def update_user_roles(
roles,
user_ou,
root_dn,
add,
remove,
update_notes,
user_note,
user_filter,
roles_to_filter,
):


@click.command()
Expand Down
4 changes: 3 additions & 1 deletion cli/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ def connection():
log.debug("Created database connection successfully")
return conn
except Exception as e:
log.exception(f"Failed to create database connection. An exception of type {type(e).__name__} occurred: {e}")
log.exception(
f"Failed to create database connection. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
16 changes: 12 additions & 4 deletions cli/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def get_access_token(
headers=headers,
)
except Exception as e:
logging.exception(f"Failed to get access token. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to get access token. An exception of type {type(e).__name__} occurred: {e}"
)
raise e

# extract the token from the response
Expand Down Expand Up @@ -66,7 +68,9 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
# if there is a token, assume auth is required and use the token and auth_type
elif token:
Expand All @@ -79,7 +83,9 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
# if there is no token, assume auth is not required and clone without
else:
Expand All @@ -91,5 +97,7 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
8 changes: 2 additions & 6 deletions cli/ldap_cmds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@


# import oracledb
def ldap_connect(
ldap_host,
ldap_user,
ldap_password,
):
server = Server(ldap_host)
def ldap_connect(ldap_host, ldap_port, ldap_user, ldap_password):
server = Server(ldap_host, ldap_port)

return Connection(
server=server,
Expand Down
Loading

0 comments on commit 653bfa7

Please sign in to comment.