ksconf.app package¶
Submodules¶
ksconf.app.deploy module¶
-
class
ksconf.app.deploy.
DeployAction
(action: 'str')¶ Bases:
object
-
classmethod
from_dict
(data: dict) → ksconf.app.deploy.DeployAction¶
-
to_dict
() → dict¶
-
classmethod
-
class
ksconf.app.deploy.
DeployActionType
¶ Bases:
enum.Enum
An enumeration.
-
EXTRACT_FILE
= 'extract_file'¶
-
REMOVE_FILE
= 'remove'¶ Implement in future phase SET_SYMLINK = “link” UPDATE_META = “meta”
-
SET_APP_NAME
= 'app'¶
-
SOURCE_REFERENCE
= 'source'¶
-
-
class
ksconf.app.deploy.
DeployAction_ExtractFile
(subtype: 'str', path: 'PurePosixPath', mode: 'int' = None, mtime: 'int' = None, hash: 'str' = None, rel_path: 'str' = None)¶ Bases:
ksconf.app.deploy.DeployAction
-
action
= 'extract_file'¶
-
hash
= None¶
-
mode
= None¶
-
mtime
= None¶
-
rel_path
= None¶
-
-
class
ksconf.app.deploy.
DeployAction_RemoveFile
(path: 'PurePosixPath')¶ Bases:
ksconf.app.deploy.DeployAction
-
action
= 'remove'¶
-
-
class
ksconf.app.deploy.
DeployAction_SetAppName
(name: 'str')¶ Bases:
ksconf.app.deploy.DeployAction
-
action
= 'app'¶
-
-
class
ksconf.app.deploy.
DeployAction_SourceReference
(archive_path: 'str', hash: 'str')¶ Bases:
ksconf.app.deploy.DeployAction
-
action
= 'source'¶
-
-
class
ksconf.app.deploy.
DeployApply
(dest: pathlib.Path)¶ Bases:
object
-
apply_sequence
(deployment_sequence: ksconf.app.deploy.DeploySequence)¶ Apply a pre-calculated deployment sequence to the local file system.
-
resolve_source
(source, hash)¶
-
-
class
ksconf.app.deploy.
DeployPlanner
¶ Bases:
object
-
class
ksconf.app.deploy.
DeploySequence
¶ Bases:
object
-
add
(action: str, *args, **kwargs)¶
-
classmethod
from_dict
(data: dict) → ksconf.app.deploy.DeploySequence¶
-
classmethod
from_manifest
(manifest: ksconf.app.manifest.AppManifest) → ksconf.app.deploy.DeploySequence¶ Fresh deploy of an app from scratch.
(There should probably be a new op-code for this, eventually instead of listing every single file.)
-
classmethod
from_manifest_transformation
(base: ksconf.app.manifest.AppManifest, target: ksconf.app.manifest.AppManifest) → ksconf.app.deploy.DeploySequence¶
-
to_dict
() → dict¶
-
-
ksconf.app.deploy.
expand_archive_by_manifest
(archive: pathlib.Path, dest: pathlib.Path, manifest: ksconf.app.manifest.AppManifest, dir_mode=504)¶ Expand an tarball to a local file system including only the files referenced by the files within the app manifest.
This function assumes that safety checks on manifest have already been performed, such as eliminating any absolute paths.
-
ksconf.app.deploy.
get_deploy_action_class
(action: str) → ksconf.app.deploy.DeployAction¶
ksconf.app.facts module¶
Splunk Application facts:
Easily collect Splunk app name, version, label, and other nuggets from app.conf
-
class
ksconf.app.facts.
AppFacts
(name: str, label: Optional[str] = None, id: Optional[str] = None, version: Optional[str] = None, author: Optional[str] = None, description: Optional[str] = None, state: Optional[str] = None, build: Optional[int] = None)¶ Bases:
object
Basic Splunk application info container. A majority of these facts are extracted from
app.conf
-
allows_disable
= None¶
-
build
= None¶
-
check_for_updates
= None¶
-
deployer_lookups_push_mode
= None¶
-
deployer_push_mode
= None¶
-
description
= None¶
-
classmethod
from_app_dir
(app_path: pathlib.Path) → ksconf.app.facts.AppFacts¶ Create an AppFacts from a local file system. This expects a standard (non-layered) installed or extracted app folder. Both
default
andlocal
are considered.
-
classmethod
from_archive
(archive: pathlib.Path)¶ Returns list of app names, merged app_conf and a dictionary of extra facts that may be useful
-
classmethod
from_conf
(name, conf: Dict[str, Dict[str, str]]) → ksconf.app.facts.AppFacts¶ Create AppFacts from an app.conf configuration content.
-
id
= None¶
-
install_source_checksum
= None¶
-
install_source_local_checksum
= None¶
-
is_configured
= None¶
-
is_visible
= None¶
-
label
= None¶
-
state
= None¶
-
state_change_requires_restart
= None¶
-
to_dict
() → dict¶
-
to_tiny_dict
(*keep_attrs) → dict¶ Return dict representation, discarding the Nones
-
version
= None¶
-
ksconf.app.manifest module¶
Splunk App content inventory and signature management
-
exception
ksconf.app.manifest.
AppArchiveContentError
¶ Bases:
Exception
Problem with the contents of an archive
-
exception
ksconf.app.manifest.
AppArchiveError
¶ Bases:
Exception
-
class
ksconf.app.manifest.
AppManifest
(name: 'str' = None, source: 'str' = None, hash_algorithm: 'str' = 'sha256', files: 'List[AppManifestFile]' = <factory>)¶ Bases:
object
-
check_paths
()¶ Check for dangerous paths in the archive.
-
find_local
() → Iterable[ksconf.app.manifest.AppManifestFile]¶
-
classmethod
from_archive
(archive: pathlib.Path, calculate_hash=True) → ksconf.app.manifest.AppManifest¶ Create as new AppManifest from a tarball. Set
calculate_hash
as False when only a file listing is needed.
-
classmethod
from_dict
(data: dict) → ksconf.app.manifest.AppManifest¶
-
classmethod
from_filesystem
(path: pathlib.Path, name: Optional[str] = None, follow_symlinks=False, calculate_hash=True) → ksconf.app.manifest.AppManifest¶ Create as new AppManifest from an existing directory structure. Set
calculate_hash
as False when only a file listing is needed.
-
hash
¶
-
hash_algorithm
= 'sha256'¶
-
name
= None¶
-
source
= None¶
-
to_dict
()¶
-
-
class
ksconf.app.manifest.
AppManifestFile
(path: 'PurePosixPath', mode: 'int', size: 'int', hash: 'str' = None)¶ Bases:
object
-
content_match
(other)¶
-
classmethod
from_dict
(data: dict) → ksconf.app.manifest.AppManifestFile¶
-
hash
= None¶
-
to_dict
()¶
-
-
exception
ksconf.app.manifest.
AppManifestStorageError
¶ Bases:
Exception
-
exception
ksconf.app.manifest.
AppManifestStorageInvalid
¶
-
class
ksconf.app.manifest.
StoredArchiveManifest
(archive: pathlib.Path, size: int, mtime: float, hash: str)¶ Bases:
object
Stored manifest for a tarball. Typically the manifest file lives in the same directory as the archive. Details around the naming, storage, and clean up of these persistent manifest files are managed by the caller.
-
classmethod
from_dict
(data: dict) → ksconf.app.manifest.StoredArchiveManifest¶
-
classmethod
from_file
(archive: pathlib.Path, manifest: ksconf.app.manifest.AppManifest) → ksconf.app.manifest.StoredArchiveManifest¶ Construct instance from a tarball.
-
classmethod
from_json_manifest
(archive: pathlib.Path, stored_file: pathlib.Path) → ksconf.app.manifest.StoredArchiveManifest¶ Attempt to load as stored manifest from archive & stored manifest paths. If the archive has changed since the manifest was stored, then an exception will be raised indicating the reason for invalidation.
-
manifest
¶
-
classmethod
read_json_manifest
(manifest_file: pathlib.Path) → ksconf.app.manifest.StoredArchiveManifest¶
-
to_dict
()¶
-
write_json_manifest
(manifest_file: pathlib.Path)¶
-
classmethod
-
ksconf.app.manifest.
create_manifest_from_archive
(archive_file: pathlib.Path, manifest_file: pathlib.Path, manifest: ksconf.app.manifest.AppManifest) → ksconf.app.manifest.StoredArchiveManifest¶ Create a new stored manifest file based on a given archive.
-
ksconf.app.manifest.
get_stored_manifest_name
(archive: pathlib.Path) → pathlib.Path¶ Calculate the name of the stored manifest file based on
archive
.
-
ksconf.app.manifest.
load_manifest_for_archive
(archive: pathlib.Path, manifest_file: Optional[pathlib.Path] = None, read_manifest=True, write_manifest=True) → ksconf.app.manifest.AppManifest¶ Load manifest for
archive
and create a stored copy of the manifest inmanifest_file
. On subsequent calls the manifest data stored to disk will be reused assumingmanifest_file
is up-to-date.File modification time and size are used to determine if
archive
has been changed since themanifest_file
was written.If no
manifest_file
is provided, the default manifest naming convention will be applied where themanifest_file
is stored in the same directory asarchive
.
Module contents¶
Splunk App helper classes
Note that these representations are for native Splunk apps that use ‘default’ and ‘local’ and have not built-in concept of ksconf layers.
-
ksconf.app.
get_facts_manifest_from_archive
(archive: pathlib.Path, calculate_hash=True, check_paths=True) → Tuple[ksconf.app.facts.AppFacts, ksconf.app.manifest.AppManifest]¶ Get both AppFacts and AppManifest from a single archive. If
calculate_hash
is True, then the manifest will contain checksums for all files in the archive. Without this, it’s not possible to calculate a hash for the combined manifest.Use this function to collect both metadata about the app and a full listing of the app’s contents.