Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First commits #1

Merged
merged 92 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
9ab1e5c
Bare minimum functionality
jsf9k Nov 1, 2021
7734d7d
Allow VNC username, password, and private ssh key to be specified dir…
jsf9k Nov 2, 2021
ad2a7fb
Specify a region when using boto3
jsf9k Nov 2, 2021
7c0e1d8
Refine docopt/schema validation for VPC ID
jsf9k Nov 2, 2021
6403ae3
Add code to correctly add instances depending on OS type (Windows vs …
jsf9k Nov 2, 2021
6b9b5a2
Add tests for stale (terminated) instances
jsf9k Nov 2, 2021
736c92c
Remove two unnecessary lines from test code
jsf9k Nov 2, 2021
e6fe8c8
Rename two test methods for clarity
jsf9k Nov 2, 2021
cdcdeb3
Add a couple of assert_not_called() assertions to test code
jsf9k Nov 2, 2021
5258579
Add a test for stopped instances
jsf9k Nov 2, 2021
b2fd9fa
Combine the two terminated instance tests
jsf9k Nov 2, 2021
8d13874
Break out removal of connections by ID into its own function
jsf9k Nov 2, 2021
4d9718f
Remove call_count checks
jsf9k Nov 2, 2021
ee5532a
Bump version from 0.0.1 to 0.0.1-rc.1
jsf9k Nov 3, 2021
4b80cd0
Fix location of version file
jsf9k Nov 3, 2021
11bb595
Improve function that checks for ghost instances
jsf9k Nov 3, 2021
1bd2d74
Improve handling of input arguments
jsf9k Nov 3, 2021
c9f73c2
Skip instances launched from AMIs that match any of a list of regexes
jsf9k Nov 3, 2021
1cefa6b
Bump version from 0.0.1-rc.1 to 0.0.1-rc.2
jsf9k Nov 3, 2021
bc01b3e
Fix a bug in the way the IF of the default VPC is retrieved via insta…
jsf9k Nov 3, 2021
2cfdb8b
Bump version from 0.0.1-rc.2 to 0.0.1-rc.3
jsf9k Nov 3, 2021
1000145
Add a --oneshot option that runs the update loop only once
jsf9k Nov 3, 2021
3ba0f33
Bump version from 0.0.1-rc.3 to 0.0.1-rc.4
jsf9k Nov 3, 2021
5c43c21
Add an input parameter to specify the sleep between loop iterations
jsf9k Nov 3, 2021
368a0fb
Precompile the VPC ID regex
jsf9k Nov 3, 2021
c9c3396
Bump version from 0.0.1-rc.4 to 0.0.1-rc.5
jsf9k Nov 3, 2021
21ac2ed
Move DB connection attempt inside the loop
jsf9k Nov 4, 2021
077359f
Bump version from 0.0.1-rc.5 to 0.0.1-rc.6
jsf9k Nov 4, 2021
20f5e39
Modify the connection name to be something more meaningful
jsf9k Nov 4, 2021
0229d0f
Bump version from 0.0.1-rc.6 to 0.0.1-rc.7
jsf9k Nov 4, 2021
5c8ee84
Modify DB connectin string to use key/value pairs instead of a URI
jsf9k Nov 4, 2021
30b2206
Remove continue statement
jsf9k Nov 4, 2021
db1c891
Bump version from 0.0.1-rc.7 to 0.0.1-rc.8
jsf9k Nov 4, 2021
b461185
Remove unnecessary line
jsf9k Nov 4, 2021
811847b
Use a dictionary row factory for the DB connection
jsf9k Nov 4, 2021
a6d931f
Bump version from 0.0.1-rc.8 to 0.0.1-rc.9
jsf9k Nov 4, 2021
faafc60
Fix handling of return values from fetchone()
jsf9k Nov 4, 2021
5e17187
Bump version from 0.0.1-rc.9 to 0.0.1-rc.10
jsf9k Nov 4, 2021
186707e
Fix a typo in a DB query
jsf9k Nov 4, 2021
acf8dfc
Bump version from 0.0.1-rc.10 to 0.0.1-rc.11
jsf9k Nov 4, 2021
201b42f
Fix error in instance ID regex
jsf9k Nov 4, 2021
52c7013
Use sql.Identifier for a name field
jsf9k Nov 4, 2021
4aefae5
Fix typo in field name
jsf9k Nov 4, 2021
821b220
Bump version from 0.0.1-rc.11 to 0.0.1-rc.12
jsf9k Nov 4, 2021
f61410f
Fix typo in field name
jsf9k Nov 5, 2021
c80822c
Bump version from 0.0.1-rc.12 to 0.0.1-rc.13
jsf9k Nov 5, 2021
75f0c6d
Update README from skeleton content
jsf9k Nov 5, 2021
4419fa9
Add code to create guacuser and giver it permission to use connections
jsf9k Nov 5, 2021
befafec
Bump version from 0.0.1-rc.13 to 0.0.1-rc.14
jsf9k Nov 5, 2021
c4b997b
Move creation of guacuser inside the connection creation loop
jsf9k Nov 5, 2021
b20b3dc
Bump version from 0.0.1-rc.14 to 0.0.1-rc.15
jsf9k Nov 5, 2021
08d2f52
Add some code so that the guacuser_id is only looked up once
jsf9k Nov 5, 2021
76e36b8
Bump version from 0.0.1-rc.15 to 0.0.1-rc.16
jsf9k Nov 5, 2021
ef47a62
Modify entity_exists() and get_entity_id() to take the entity type as…
jsf9k Nov 5, 2021
d7fd3fa
Bump version from 0.0.1-rc.16 to 0.0.1-rc.17
jsf9k Nov 5, 2021
808c91e
Update tests now that the guacuser code has been added
jsf9k Nov 5, 2021
bbc0cf9
Add a todo comment to improve the way the Guacamole user is created
jsf9k Nov 5, 2021
60448e0
Add a TODO comment for improvement of exception handling
jsf9k Nov 5, 2021
914eaf8
Improve capitalization
jsf9k Nov 5, 2021
2e7c8d9
Improve comment
jsf9k Nov 5, 2021
6de761f
Correctly alphabetize CLI arguments
jsf9k Nov 5, 2021
92bc51b
Also ignore instances running Nessus AMIs
jsf9k Nov 5, 2021
6a2c4e0
Add a comment explaining why a line is commented out
jsf9k Nov 5, 2021
890461b
List functions to be exported
jsf9k Nov 5, 2021
1985e78
Add some exception handling for the AMI regex matching
jsf9k Nov 5, 2021
ea88bb1
Bump version from 0.0.1-rc.17 to 0.0.1-rc.18
jsf9k Nov 5, 2021
3f421fb
Remove unnecessary import
jsf9k Nov 5, 2021
916531e
Improve comment about exception thrown by ami.name access
jsf9k Nov 8, 2021
af9e26e
Bump version from 0.0.1-rc.18 to 0.0.1
jsf9k Nov 8, 2021
3e05d61
Fix typos in comments
jsf9k Nov 9, 2021
ec52ab4
Add a --region CLI optional, defaulting to us-east-1
jsf9k Nov 10, 2021
de02b06
Add code to correctly handle generation of Guacamole passwords
jsf9k Nov 10, 2021
e595bb3
Uppercase values that are saved to the DB before converting to byte a…
jsf9k Nov 10, 2021
cd170b4
Get rid of need for noqa in one line
jsf9k Nov 10, 2021
c69e775
Remove package_data code that is commented out anyway
jsf9k Nov 10, 2021
a6278b8
Add todo comment re validating AWS region names passed in on the comm…
jsf9k Nov 10, 2021
c5f57d1
Add a comment explaining the use of a named capture group
jsf9k Nov 10, 2021
5c45b4a
Add a TODO comment to reduce duplication of mock EC2 setup code
jsf9k Nov 10, 2021
478e1a3
Add TODO comment for loosening version pins
jsf9k Nov 10, 2021
6b2db01
Remove debug logging statement that could contain sensitive information
jsf9k Nov 10, 2021
d1eb68f
Avoid importing from psycopg in two different ways
jsf9k Nov 10, 2021
0842757
Add an LGTM comment string to disable a warning
jsf9k Nov 10, 2021
da2df6b
Do not include username in logging statement
jsf9k Nov 10, 2021
40269ca
Bump version from 0.0.1 to 0.0.2
jsf9k Nov 10, 2021
70e3616
Bump version from 0.0.2 to 0.0.2-rc.1
jsf9k Nov 10, 2021
6dd384b
Rename a variable to preserve alphabetical order and yet keep related…
jsf9k Nov 10, 2021
36025de
Fix a typo
jsf9k Nov 10, 2021
95de413
Use a dataclass for passing Guacamole connection parameters as functi…
jsf9k Nov 11, 2021
270ac59
Do not create DB connection in a context manager
jsf9k Nov 12, 2021
51bf9d2
Bump version from 0.0.2-rc.1 to 0.0.2-rc.2
jsf9k Nov 12, 2021
73e625f
Bump version from 0.0.2-rc.2 to 0.0.2
jsf9k Nov 12, 2021
d3887b2
Bump version from 0.0.2 to 1.0.0
jsf9k Nov 12, 2021
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
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://coverage.readthedocs.io/en/latest/config.html

[run]
source = src/example
source = src/guacscanner
omit =
branch = true

Expand Down
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/cisagov/guacscanner.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/cisagov/guacscanner/context:python)
[![Known Vulnerabilities](https://snyk.io/test/github/cisagov/guacscanner/develop/badge.svg)](https://snyk.io/test/github/cisagov/guacscanner)

This is a generic skeleton project that can be used to quickly get a
new [cisagov](https://github.com/cisagov) Python library GitHub
project started. This skeleton project contains [licensing
information](LICENSE), as well as
[pre-commit hooks](https://pre-commit.com) and
[GitHub Actions](https://github.com/features/actions) configurations
appropriate for a Python library project.

## New Repositories from a Skeleton ##

Please see our [Project Setup guide](https://github.com/cisagov/development-guide/tree/develop/project_setup)
for step-by-step instructions on how to start a new repository from
a skeleton. This will save you time and effort when configuring a
new repository!
This project is a Python utility that continually scans the EC2 instances
in an AWS VPC and adds/removes Guacamole connections in the underlying
PostgreSQL database accordingly.

This utility is [Dockerized](https://docker.com) in
[cisagov/guacscanner-docker](https://github.com/cisagov/guacscanner-docker),
and the resulting Docker container is intended to run as a part of
[cisagov/guacamole-composition](https://github.com/cisagov/guacamole-composition),
although it could - probably uselessly - run in a [Docker
composition](https://docs.docker.com/compose/) alongside only the
[official PostgreSQL Docker image](https://hub.docker.com/_/postgres).

## Contributing ##

Expand Down
2 changes: 1 addition & 1 deletion bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o nounset
set -o errexit
set -o pipefail

VERSION_FILE=src/example/_version.py
VERSION_FILE=src/guacscanner/_version.py

HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"

Expand Down
32 changes: 23 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This is the setup module for the example project.
This is the setup module for the guacscanner project.

Based on:

Expand Down Expand Up @@ -42,10 +42,10 @@ def get_version(version_file):


setup(
name="example",
name="guacscanner",
# Versions should comply with PEP440
version=get_version("src/example/_version.py"),
description="Example Python library",
version=get_version("src/guacscanner/_version.py"),
description="Scan for EC2 instances added (removed) from a VPC and create (destroy) the corresponding Guacamole connections.",
long_description=readme(),
long_description_content_type="text/markdown",
# Landing page for CISA's cybersecurity mission
Expand Down Expand Up @@ -81,13 +81,21 @@ def get_version(version_file):
],
python_requires=">=3.6",
# What does your project relate to?
keywords="skeleton",
keywords="aws, guacamole, vpc",
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"example": ["data/*.txt"]},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=["docopt", "schema", "setuptools >= 24.2.0"],
# TODO: Loosen these requirements. See cisagov/guacscanner#9 for
# more details.
install_requires=[
"boto3 == 1.19.6",
"docopt == 0.6.2",
"ec2-metadata == 2.5.0",
"psycopg == 3.0.1",
"schema == 0.7.4",
mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved
"setuptools >= 24.2.0",
],
extras_require={
"test": [
"coverage",
Expand All @@ -98,11 +106,17 @@ def get_version(version_file):
# 1.11.1 fixed this issue, but to ensure expected behavior we'll pin
# to never grab the regression version.
"coveralls != 1.11.0",
"moto",
"pre-commit",
"pytest-cov",
"pytest",
]
},
# Conveniently allows one to run the CLI tool as `example`
entry_points={"console_scripts": ["example = example.example:main"]},
# Conveniently allows one to run the CLI tool as
# `guacscanner`
entry_points={
"console_scripts": [
"guacscanner = guacscanner.guacscanner:main",
],
},
)
9 changes: 0 additions & 9 deletions src/example/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion src/example/data/secret.txt

This file was deleted.

103 changes: 0 additions & 103 deletions src/example/example.py

This file was deleted.

33 changes: 33 additions & 0 deletions src/guacscanner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""The guacscanner library."""
# We disable a Flake8 check for "Module imported but unused (F401)"
# here because, although this import is not directly used, it
# populates the value package_name.__version__, which is used to get
# version information about this Python package.
from ._version import __version__ # noqa: F401
from .guacscanner import (
add_instance_connection,
add_user,
check_for_ghost_instances,
entity_exists,
get_connection_name,
get_entity_id,
instance_connection_exists,
main,
process_instance,
remove_connection,
remove_instance_connections,
)

__all__ = [
"add_instance_connection",
"add_user",
"check_for_ghost_instances",
"entity_exists",
"get_connection_name",
"get_entity_id",
"instance_connection_exists",
"main",
"process_instance",
"remove_connection",
"remove_instance_connections",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Code to run if this package is used as a Python module."""

from .example import main
from .guacscanner import main

main()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "0.0.1"
__version__ = "0.0.2-rc.1"
Loading