Skip to content

Update connection names as instance IPs change#269

Merged
jsf9k merged 14 commits intodevelopfrom
bugfix/update-connection-names-as-ips-change
Apr 29, 2026
Merged

Update connection names as instance IPs change#269
jsf9k merged 14 commits intodevelopfrom
bugfix/update-connection-names-as-ips-change

Conversation

@jsf9k
Copy link
Copy Markdown
Member

@jsf9k jsf9k commented Apr 20, 2026

🗣 Description

This pull request modifies the Python code to update connection names as instances' internal and external IPs change.

See also:

💭 Motivation and context

Resolves #268.

🧪 Testing

All automated tests pass. I also deployed a new cisagov/guacamole-packer AMI with this change as part of the testing for cisagov/guacamole-packer#124 and verified that it functions as expected.

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All new and existing tests pass.
  • Bump major, minor, patch, pre-release, and/or build versions as appropriate via the bump_version script if this repository is versioned and the changes in this PR warrant a version bump.
  • Create a pre-release (necessary if and only if the pre-release version was bumped).

✅ Pre-merge checklist

  • Finalize version.

✅ Post-merge checklist

  • Create a release (necessary if and only if the version was bumped).

jsf9k added 4 commits April 20, 2026 17:11
This is only done if:
- The instance already exists in the database
- The instance is in a state that would cause it to be added to the
database if it did not already exist there
@jsf9k jsf9k self-assigned this Apr 20, 2026
@jsf9k jsf9k added the bug This issue or pull request addresses broken functionality label Apr 20, 2026
@github-actions github-actions Bot added version bump This issue or pull request increments the version number python Pull requests that update Python code labels Apr 20, 2026
jsf9k added 6 commits April 23, 2026 15:30
In SQL strings should be enclosed in single quotes (in case they
contain whitespace) but numeric value must not.
Quotes do not seem to be necessary at all when using
psycopg.sql.SQL().
This avoids using the same cursor for the connection ID query and the
updating of the connection names, which generates an error.
@jsf9k jsf9k marked this pull request as ready for review April 27, 2026 15:44
@jsf9k jsf9k requested a review from dav3r as a code owner April 27, 2026 15:44
Copilot AI review requested due to automatic review settings April 27, 2026 15:44
@jsf9k jsf9k requested review from felddy and mcdonnnj as code owners April 27, 2026 15:44
@jsf9k jsf9k requested a review from a team April 27, 2026 15:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates guacscanner so that when an EC2 instance already has a Guacamole connection, the connection name is refreshed to reflect changes in the instance’s IP-related metadata.

Changes:

  • Add a SQL query and helper functions to update guacamole_connection.connection_name for existing connections.
  • Invoke the update logic when an instance is in an “add” state but its connection already exists.
  • Bump the package version.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/guacscanner/guacscanner.py Adds update query + functions and calls them for existing connections to refresh connection names.
src/guacscanner/_version.py Bumps module version to 3.0.1-rc.4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/guacscanner/guacscanner.py
Comment thread src/guacscanner/guacscanner.py Outdated
Comment thread src/guacscanner/guacscanner.py
jsf9k added 3 commits April 27, 2026 13:07
In Postgres, even setting the same value generally creates a new row
version, generating table bloat. Adding this predicate avoids no-op
updates
update_connection_name() opens a new cursor and commits the
transaction each iteration. In psycopg/PostgreSQL, committing will
close/invalidate any open cursors (including the one being iterated),
which can raise errors mid-loop and/or lead to partial updates. By
fetching all connection_ids first, then performing updates without
committing inside the loop, we avoid this problem.
Copy link
Copy Markdown
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

Strong work! 💪 💼

@jsf9k jsf9k merged commit c6a1469 into develop Apr 29, 2026
111 checks passed
@jsf9k jsf9k deleted the bugfix/update-connection-names-as-ips-change branch April 29, 2026 17:17
jsf9k added a commit to cisagov/guacscanner-docker that referenced this pull request Apr 29, 2026
This also necessitates relocking the Pipfile.

This is possible now that cisagov/guacscanner#269 has been merged and
a new release created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue or pull request addresses broken functionality python Pull requests that update Python code version bump This issue or pull request increments the version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPs not updated in Guacamole connections when they change

3 participants