Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3a3fb98
Make cert expiration check independent of locale
widhalmt Mar 20, 2023
dc92349
Added filter plugin that allows to convert date strints to datetime
danopt Mar 27, 2023
c04e3c1
Updated strings to native objects for Python 2
danopt Mar 27, 2023
ed46c09
Updated elasticsearch-security.yml to read locale of CA node and impl…
danopt Mar 27, 2023
4804997
Fixed trailing spaces
danopt Mar 27, 2023
db769f8
Changed expression back to one line because of Jinja templating error
danopt Mar 27, 2023
b048ce6
Changed key-order[task] for lint
danopt Mar 27, 2023
a7c296c
Fixed invalid Jinja templating
danopt Mar 27, 2023
424a0ab
Fixed syntax
danopt Mar 27, 2023
6912163
Renamed filer module to elasticstack
danopt Mar 27, 2023
4734563
Renamed filter to FQCN in tasks
danopt Mar 28, 2023
cfa7c2b
Disabled no-handler lint
danopt Mar 28, 2023
dffc3a5
Removed no-handler from .yamllint
danopt Mar 28, 2023
21ded4c
Create .ansible-lint and added 'no-handler' to skip list for testing …
danopt Mar 28, 2023
ade949e
Added fqcn[action-core] to skip list
danopt Mar 28, 2023
d8d3643
Revert "Added fqcn[action-core] to skip list"
danopt Mar 28, 2023
c4bc9be
Added fqcn[action-core] to skip list
danopt Mar 28, 2023
a15566a
Deleted accidentaly created core.py
danopt Mar 28, 2023
7468797
Updated filter name
danopt Mar 28, 2023
3bc3d95
Added workflow for plugins
danopt Mar 28, 2023
bcf50bf
Updated elasticsearch-security.yml and filter/elasticsearch.py
danopt Mar 28, 2023
02b251b
Small corrections of task names
danopt Mar 28, 2023
4c5250f
Final update and tests
danopt Mar 28, 2023
ac5c941
Added plugins_filter scenario to test_full_stack.yml workflow
danopt Mar 28, 2023
92ea289
Corrected documentation
danopt Mar 28, 2023
b56aea8
New solution with a standard module
danopt Mar 29, 2023
ac458f0
Updated solution to better handling through cryptography library supp…
danopt Mar 30, 2023
b65a7f4
Merge branch 'main' into fix/expiry
widhalmt Mar 30, 2023
fc8c6c6
Fix newline at end of files
widhalmt Mar 31, 2023
0583d96
Add support for converting to hex and improved import of libraries
danopt Mar 31, 2023
336ce81
Merged pep8.cfg
danopt Mar 31, 2023
c27d01b
Fixed pep8.cfg
danopt Mar 31, 2023
4b04278
Improved library import and improved value accesing through direct ob…
danopt Apr 1, 2023
11dad59
Added backwards compatibility to support cryptography v2.5.x to 40.0.x
danopt Apr 2, 2023
77b9988
Added python-cryptography and ansible-core tests
danopt Apr 2, 2023
942e5a4
Added MODULES.md under plugins/modules/
danopt Apr 2, 2023
92fb9ed
Added security enhancement by making sensitive variables private and …
danopt Apr 2, 2023
4b06371
Added Overview chapter to README.md
danopt Apr 2, 2023
595b976
Update README.md
danopt Apr 2, 2023
234775b
Moved reusable functions to module_utils
danopt Apr 2, 2023
85b0023
Merged plugins/modules/README.md
danopt Apr 2, 2023
d27a05e
Modularized reusable functions to module_utils
danopt Apr 2, 2023
d3c1dcb
Merge branch 'fix/expiry' of github.com:NETWAYS/ansible-collection-el…
danopt Apr 2, 2023
ebf3df7
Removed unnecessary library imports and improved Workflow
danopt Apr 2, 2023
e5a47ad
Converted analyze_cert() function to object AnalyzeCertificate()
danopt Apr 2, 2023
fb8383b
Changed parameter names to path and passphrase
danopt Apr 3, 2023
00bd6d3
Updated role and README.md
danopt Apr 3, 2023
6782b90
Updated workflow playbook
danopt Apr 3, 2023
b3d3605
Create README.md
danopt Apr 4, 2023
3d46600
Merge branch 'main' into fix/expiry
danopt Apr 5, 2023
3530fe7
Updated converge.yml
danopt Apr 5, 2023
3d48fda
Merge branch 'main' into fix/expiry
danopt Apr 26, 2023
c8f955b
Added __pycache__ to .gitignore
danopt Apr 26, 2023
b3e5fb9
Added unit test for cert_info module
danopt Apr 26, 2023
20ac164
Restructured cert_info.py for unit test compatibility
danopt Apr 26, 2023
d88d73c
Added unit test for certs module util and cert_info module
danopt Apr 26, 2023
7242e21
Removed redundant task
danopt Apr 26, 2023
81b5cf5
Debug PWD of runner.
danopt Apr 26, 2023
85be3e1
Changed append to /home/runner
danopt Apr 26, 2023
7ec8d27
Removed debug task
danopt Apr 26, 2023
0d0ba3d
Added tests/** to events in workflow file
danopt Apr 26, 2023
6f63518
Removed line length lint
danopt Apr 27, 2023
927bee3
Removed trailing spaces
danopt Apr 27, 2023
100669e
Added folding operator
danopt Apr 27, 2023
bb5dbaa
Improved naming in test_certs.py
danopt Apr 27, 2023
653982c
Removed redundant comment
danopt Apr 27, 2023
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
4 changes: 4 additions & 0 deletions .config/pep8.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pep8]
ignore = E402, E123
# It's fine to have line-length of 99
max-line-length = 99
1 change: 1 addition & 0 deletions .github/workflows/test_full_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
- debian10
scenario:
- elasticstack_default
- plugins
release:
- 7
- 8
Expand Down
223 changes: 223 additions & 0 deletions .github/workflows/test_plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
---
name: Test Plugins
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
push:
branches:
- 'feature/**'
- 'fix/**'
- '!doc/**'
paths:
- 'plugins/**'
- '.github/workflows/test_plugins.yml'
- 'molecule/plugins/**'
- '.config/pep8.yml'
- 'tests/**'
pull_request:
branches:
- 'feature/**'
- 'fix/**'
- '!doc/**'
paths:
- 'plugins/**'
- '.github/workflows/test_plugins.yml'
- 'molecule/plugins/**'
- '.config/pep8.yml'
- 'tests/**'

jobs:
pep8:
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v3

- name: Set up Python 3.
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install test dependencies.
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pep8

- name: Lint code.
run: |
pep8 plugins/ --config=.config/pep8.cfg --statistics --count

unit-test:
needs: pep8
runs-on: ubuntu-20.04

env:
COLLECTION_NAMESPACE: netways
COLLECTION_NAME: elasticstack

strategy:
fail-fast: false
max-parallel: 1

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python 3.9.14
uses: actions/setup-python@v3
with:
python-version: 3.9.14

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install install ansible

- name: Install collection
run: |
mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE
cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME

- name: Test `cert_info` module
run: |
python tests/unit/plugins/modules/test_cert_info.py
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

- name: Test `certs` module util
run: |
python tests/unit/plugins/module_utils/test_certs.py
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

python:
needs: unit-test
runs-on: ubuntu-20.04

env:
COLLECTION_NAMESPACE: netways
COLLECTION_NAME: elasticstack

strategy:
fail-fast: false
max-parallel: 1
matrix:
python_version: [ 2.7.18, 3.5.10, 3.6.15, 3.7.13, 3.8.16, 3.10.10 ]

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python_version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install install ansible

- name: Install collection
run: |
mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE
cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME

- name: Test with ansible-playbook
run: |
ansible-playbook molecule/plugins/converge.yml
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

ansible-core:
needs: python
runs-on: ubuntu-20.04

env:
COLLECTION_NAMESPACE: netways
COLLECTION_NAME: elasticstack

strategy:
fail-fast: false
max-parallel: 1
matrix:
ansible_core_version: [ 2.11.12, 2.12.10, 2.13.8, 2.14.4 ]

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python 3.9.14
uses: actions/setup-python@v3
with:
python-version: 3.9.14

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install install ansible-core==${{ matrix.ansible_core_version }}

- name: Install collection
run: |
mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE
cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME

- name: Test with ansible-playbook
run: |
ansible-playbook molecule/plugins/converge.yml
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

python-cryptography:
needs: ansible-core
runs-on: ubuntu-20.04

env:
COLLECTION_NAMESPACE: netways
COLLECTION_NAME: elasticstack

strategy:
fail-fast: false
max-parallel: 1
matrix:
python_cryptography_version: [ 2.5, 3.0, 3.1, 3.2, 3.3, 3.4, 35.0.0, 36.0.0, 38.0.0, 40.0.1]

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python 3.9.14
uses: actions/setup-python@v3
with:
python-version: 3.9.14

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install install cryptography==${{ matrix.python_cryptography_version }}
python -m pip install install ansible

- name: Install collection
run: |
mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE
cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME

- name: Test with ansible-playbook
run: |
ansible-playbook molecule/plugins/converge.yml
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.cache
*.swp
__pycache__*
44 changes: 44 additions & 0 deletions molecule/plugins/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# The workaround for arbitrarily named role directory is important because the git repo has one name and the role within it another
# Found at: https://github.com/ansible-community/molecule/issues/1567#issuecomment-436876722
- name: Converge
collections:
- netways.elasticstack
hosts: localhost
tasks:
#
# Test modules
#
- name: Test
cert_info:
path: files/es-ca/elastic-stack-ca.p12
passphrase: PleaseChangeMe
register: test
- name: Debug
debug:
msg: "{{ test }}"
- name: Test required parameters (missing path)
cert_info:
passphrase: PleaseChangeMe
ignore_errors: true
- name: Test wrong path
cert_info:
path: es-ca-wrong
passphrase: PleaseChangeMe
ignore_errors: true
- name: Debug with to_datetime() - (( test.not_valid_after | to_datetime()) - (ansible_date_time.date | to_datetime('%Y-%m-%d'))).days
debug:
msg: >-
"{{ (( test.not_valid_after | to_datetime()) - (ansible_date_time.date | to_datetime('%Y-%m-%d'))).days }}"
- name: Test wrong passphrase
cert_info:
path: files/es-ca/elastic-stack-ca.p12
passphrase: PleaseChangeMe-wrong
ignore_errors: true
- name: Test no passphrase
cert_info:
path: files/es-ca/elastic-stack-ca.p12
ignore_errors: true
- name: Test no parameters
cert_info:
ignore_errors: true
25 changes: 25 additions & 0 deletions molecule/plugins/files/es-ca/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Bag Attributes
friendlyName: ca
2.16.840.1.113894.746875.1.1: <Unsupported tag 6>
subject=CN = Elastic Certificate Tool Autogenerated CA
issuer=CN = Elastic Certificate Tool Autogenerated CA
-----BEGIN CERTIFICATE-----
MIIDSTCCAjGgAwIBAgIUfhOfRtiBlwFsDhK9aaQoF9Vzk6gwDQYJKoZIhvcNAQEL
BQAwNDEyMDAGA1UEAxMpRWxhc3RpYyBDZXJ0aWZpY2F0ZSBUb29sIEF1dG9nZW5l
cmF0ZWQgQ0EwHhcNMjMwMzI5MDE1ODAyWhcNMjYwMzI4MDE1ODAyWjA0MTIwMAYD
VQQDEylFbGFzdGljIENlcnRpZmljYXRlIFRvb2wgQXV0b2dlbmVyYXRlZCBDQTCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANr2qXV6Lxm26yeqkCWVu9E6
sGqms3nxH6ThVT20u4dcwi0doibKdBzideN37XRE+txv6bAhzoAIe8+ahOx/DQu1
OPXIESPW+8FZcWtrFQs/uhrjBKLj09bKI46JODbsfse70454t63fwUn1D1kw9l//
UrxAS7MSceeGfrcJ+XZjMWuTuqqKhal6dA4wji3BJ/LY8rAD2G1o7uk5xHaGyLUy
h6ilJX0UbwVGAPCHZR0pQSFp5rQVUvm2QuvfOtwidPytX/9WmSB1A9nqEeKNJAMe
92VDFgOcUstuKwqs7ZgfdKLscgNuQSCGHR7mwBi3L6RDpgw6JJ+lBA2TPi1/a/kC
AwEAAaNTMFEwHQYDVR0OBBYEFIJTIBHHc6deKnfB3yLkI7TEULrPMB8GA1UdIwQY
MBaAFIJTIBHHc6deKnfB3yLkI7TEULrPMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
hvcNAQELBQADggEBAGavr5FxsXeQZVt0I51wZgS2M+fUNFhprFYxFo9ZDK1fa3IT
xQ5CRzbHYjajXqBlNxlxker0eCXdYGVI6o909H4t1ZagDGYjPjXXzL6JHnoWL2b5
dDlinlaQWmemd7esBy93lLamNpEsCx4X9b0TtewpNNxDf21y1FGT/68rJUXENjNV
GSM8hMxveRHolvGtvXbW3r38VCpl/VwE2fCUSTX+VTbSFGfsVpQE9ZZnNa/FFIPs
nu18bOAk3fRW1HL7E0ZoUfLIxANrqBxDkJZh0qzcOUoTpk/jT6mb07Btvi25g1DJ
pC1XUcSmHwoeeaQ3HNNNFlyW4rQoi9j+LJnMvcY=
-----END CERTIFICATE-----
Binary file added molecule/plugins/files/es-ca/elastic-stack-ca.p12
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions plugins/module_utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Documentation: netways.elasticstack module_utils

## Overview
- [`certs` module_util](#cert_info-module)

## `netways.elasticstack.certs` function

### `bytes_to_hex()` function

Since binascii.hexlify doesn't support a second parameter, which would define a seperator (e.g. ":") for hex strings in older Python versions like 2.6 and 2.7, we implemeted a small function to get similar results.

**Parameter:** A __bytes__ object that represent a hexadecimal value (e.g. b'\\x82S \\x11\\xc7s\\xa7^*w\\xc1\\xdf\"\\xe4#\\xb4\\xc4P\\xba\\xcf')

**Return:** A hexadecimal __string__ seperated by colons (e.g. "82:53:20:11:C7:73:A7:5E:2A:77:C1:DF:22:E4:23:B4:C4:50:BA:CF")

### `check_supported_extensions()` function

A function to check if the extension is supported. Returns true if extension name is found in `SUPPORTED_EXTENSIONS` dict.

**Parameter:** The extension name as __string__.

**Return:** Returns a __bool__.

### `check_supported_keys` function

A function to check if the extensions key is supported. Returns true if extensions key is found in `SUPPORTED_EXTENSIONS` dict.

**Parameter:** The key name as __string__.

**Return:** Returns a __bool__.

### `AnalyzeCertificate()` object

An object to load the certificate and to gather information about it.

**Parameter:** The path (required) to the certificate and the passphrase (optional), both as __string__.

**Return:** Returns the result dict to the Ansible module.
Loading