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

Schema a d #1211

Merged
merged 13 commits into from
Feb 1, 2022
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
314 changes: 13 additions & 301 deletions cloudinit/config/cc_apt_configure.py

Large diffs are not rendered by default.

29 changes: 2 additions & 27 deletions cloudinit/config/cc_bootcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@
from textwrap import dedent

from cloudinit import subp, temp_utils, util
from cloudinit.config.schema import get_meta_doc, validate_cloudconfig_schema
from cloudinit.config.schema import get_meta_doc
blackboxsw marked this conversation as resolved.
Show resolved Hide resolved
from cloudinit.settings import PER_ALWAYS

frequency = PER_ALWAYS

# The schema definition for each cloud-config module is a strict contract for
# describing supported configuration parameters for each cloud-config section.
# It allows cloud-config to validate and alert users to invalid or ignored
# configuration options before actually attempting to deploy with said
# configuration.

distros = ["all"]

meta = {
Expand Down Expand Up @@ -62,25 +56,7 @@
"frequency": PER_ALWAYS,
}

schema = {
"type": "object",
"properties": {
"bootcmd": {
"type": "array",
"items": {
"oneOf": [
{"type": "array", "items": {"type": "string"}},
{"type": "string"},
]
},
"additionalItems": False, # Reject items of non-string non-list
"additionalProperties": False,
"minItems": 1,
}
},
}

__doc__ = get_meta_doc(meta, schema) # Supplement python help()
__doc__ = get_meta_doc(meta)


def handle(name, cfg, cloud, log, _args):
Expand All @@ -91,7 +67,6 @@ def handle(name, cfg, cloud, log, _args):
)
return

validate_cloudconfig_schema(cfg, schema)
with temp_utils.ExtendedTemporaryFile(suffix=".sh") as tmpf:
try:
content = util.shellify(cfg["bootcmd"])
Expand Down
40 changes: 22 additions & 18 deletions cloudinit/config/cc_byobu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
Byobu
-----
**Summary:** enable/disable byobu system wide and for default user
"""Byobu: Enable/disable byobu system wide and for default user."""

from cloudinit import subp, util
from cloudinit.config.schema import get_meta_doc
from cloudinit.distros import ug_util
from cloudinit.settings import PER_INSTANCE

MODULE_DESCRIPTION = """\
This module controls whether byobu is enabled or disabled system wide and for
the default system user. If byobu is to be enabled, this module will ensure it
is installed. Likewise, if it is to be disabled, it will be removed if
Expand All @@ -26,23 +29,24 @@
- ``disable``: disable byobu for all users
- ``user``: alias for ``enable-user``
- ``system``: alias for ``enable-system``

**Internal name:** ``cc_byobu``

**Module frequency:** per instance

**Supported distros:** ubuntu, debian

**Config keys**::

byobu_by_default: <user/system>
"""

from cloudinit import subp, util
from cloudinit.distros import ug_util

distros = ["ubuntu", "debian"]

meta = {
"id": "cc_byobu",
"name": "Byobu",
"title": "Enable/disable byobu system wide and for default user",
"description": MODULE_DESCRIPTION,
"distros": distros,
"frequency": PER_INSTANCE,
"examples": [
"byobu_by_default: enable-user",
"byobu_by_default: disable-system",
],
}

__doc__ = get_meta_doc(meta)


def handle(name, cfg, cloud, log, args):
if len(args) != 0:
Expand Down
108 changes: 66 additions & 42 deletions cloudinit/config/cc_ca_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,14 @@
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
CA Certs
--------
**Summary:** add ca certificates

This module adds CA certificates to ``/etc/ca-certificates.conf`` and updates
the ssl cert cache using ``update-ca-certificates``. The default certificates
can be removed from the system with the configuration option
``remove-defaults``.

.. note::
certificates must be specified using valid yaml. in order to specify a
multiline certificate, the yaml multiline list syntax must be used

.. note::
For Alpine Linux the "remove-defaults" functionality works if the
ca-certificates package is installed but not if the
ca-certificates-bundle package is installed.

**Internal name:** ``cc_ca_certs``

**Module frequency:** per instance

**Supported distros:** alpine, debian, ubuntu, rhel

**Config keys**::

ca-certs:
remove-defaults: <true/false>
trusted:
- <single line cert>
- |
-----BEGIN CERTIFICATE-----
YOUR-ORGS-TRUSTED-CA-CERT-HERE
-----END CERTIFICATE-----
"""
"""CA Certs: Add ca certificates."""

import os
from textwrap import dedent

from cloudinit import subp, util
from cloudinit.config.schema import get_meta_doc
from cloudinit.settings import PER_INSTANCE

DEFAULT_CONFIG = {
"ca_cert_path": "/usr/share/ca-certificates/",
Expand All @@ -60,9 +28,48 @@
}
}

MODULE_DESCRIPTION = """\
This module adds CA certificates to ``/etc/ca-certificates.conf`` and updates
the ssl cert cache using ``update-ca-certificates``. The default certificates
can be removed from the system with the configuration option
``remove_defaults``.

.. note::
certificates must be specified using valid yaml. in order to specify a
multiline certificate, the yaml multiline list syntax must be used

.. note::
For Alpine Linux the "remove_defaults" functionality works if the
ca-certificates package is installed but not if the
ca-certificates-bundle package is installed.
"""
distros = ["alpine", "debian", "ubuntu", "rhel"]

meta = {
"id": "cc_ca_certs",
"name": "CA Certificates",
"title": "Add ca certificates",
"description": MODULE_DESCRIPTION,
"distros": distros,
"frequency": PER_INSTANCE,
"examples": [
dedent(
"""\
ca_certs:
remove_defaults: true
trusted:
- single_line_cert
- |
-----BEGIN CERTIFICATE-----
YOUR-ORGS-TRUSTED-CA-CERT-HERE
-----END CERTIFICATE-----
"""
)
],
}

__doc__ = get_meta_doc(meta)


def _distro_ca_certs_configs(distro_name):
"""Return a distro-specific ca_certs config dictionary
Expand Down Expand Up @@ -162,20 +169,37 @@ def handle(name, cfg, cloud, log, _args):
@param log: Pre-initialized Python logger object to use for logging.
@param args: Any module arguments from cloud.cfg
"""
# If there isn't a ca-certs section in the configuration don't do anything
if "ca-certs" not in cfg:
if "ca-certs" in cfg:
log.warning(
"DEPRECATION: key 'ca-certs' is now deprecated. Use 'ca_certs'"
" instead."
)
elif "ca_certs" not in cfg:
blackboxsw marked this conversation as resolved.
Show resolved Hide resolved
log.debug(
"Skipping module named %s, no 'ca-certs' key in configuration",
"Skipping module named %s, no 'ca_certs' key in configuration",
name,
)
return

ca_cert_cfg = cfg["ca-certs"]
if "ca-certs" in cfg and "ca_certs" in cfg:
log.warning(
"Found both ca-certs (deprecated) and ca_certs config keys."
" Ignoring ca-certs."
)
ca_cert_cfg = cfg.get("ca_certs", cfg.get("ca-certs"))
distro_cfg = _distro_ca_certs_configs(cloud.distro.name)

# If there is a remove-defaults option set to true, remove the system
# If there is a remove_defaults option set to true, remove the system
# default trusted CA certs first.
if ca_cert_cfg.get("remove-defaults", False):
if "remove-defaults" in ca_cert_cfg:
log.warning(
"DEPRECATION: key 'ca-certs.remove-defaults' is now deprecated."
" Use 'ca_certs.remove_defaults' instead."
)
if ca_cert_cfg.get("remove-defaults", False):
log.debug("Removing default certificates")
remove_default_ca_certs(cloud.distro.name, distro_cfg)
elif ca_cert_cfg.get("remove_defaults", False):
log.debug("Removing default certificates")
remove_default_ca_certs(cloud.distro.name, distro_cfg)

Expand Down
Loading