Metadata
This section contains details about Metadata in StackSpot.
Metadata is an object created during a Plugin's execution. It contains several values that assist you in executing other processes or creating automations.
The basic structure of the object is:
metadata:
inputs: Dict
global_inputs: Dict
computed_inputs: Dict
global_computed_inputs: Dict
filters: Dict
target_path: Path
component_path: Path
Metadata Properties
metadata.inputs
It is a dictionary containing the processed inputs.
The
global_inputs,computed_inputs, andglobal_computed_inputsinput types show the same behavior asinputs. The main difference is that each object contains its specific data.
Example of usage in a Hook:
# Example in a Plugin/Hook
hooks:
...
commands:
- ping -c 4 {{ inputs.ipv4 }}
# or
- ping -c 4 {{ ipv4 }}
The
ipv4input is requested during the Hook execution. The system interpolates the value before executing the command.
The processed inputs are also added to the main object body. See how to access them:
metadata.inputs.varname
metadata.varname
# If you are running inside a Jinja template, the 'metadata' term is omitted:
{{ inputs.varname }}
{{ varname }}
metadata.target_path
Represents the path where the Plugin is being executed.
Example applying a main.yaml file relative to the execution path:
# Example in a Plugin/Hook
hooks:
...
commands: |
kubectl apply -f {{ target_path }}/deployment/main.yaml
The
target_pathprovides the current execution folder. Example:'/home/linus/scheduler'.
metadata.component_path
Represents the source path of the Plugin, meaning the location where the Plugin files are stored locally.
Example of executing scripts internal to the Plugin:
# Example in a Plugin/Hook
hooks:
...
commands:
windows: |
call "{{ component_path }}\scripts\my-script.bat"
linux: |
bash "{{ component_path }}/scripts/my-script.sh"
The
component_pathhelps keep binaries and scripts organized within your Plugin, making it easier to reference them for later execution.
Advanced Metadata
You can use metadata in more advanced features.
The target_path and component_path values are objects of type Path (Python pathlib library). This means you can use the properties and methods of this object within the execution context.
Example to check the parent directory size:
# Example in a Plugin/Hook
hooks:
...
commands: |
# Parent directory size of the execution path
du -sh {{ target_path.parent }}
Hooks
Metadata can also be used in Declarative Hooks scenarios. For example, when using the run-script type:
YAML declaration:
hooks:
- type: run-script
...
script: my-custom-script.py
Python Script (my-custom-script.py):
# my-custom-script.py
import json
from templateframework.metadata import Metadata
def run(metadata: Metadata):
# Uses target_path to locate the package.json file
with open(f"{metadata.target_path}/package.json") as f:
data = json.load(f)
if data["license"] == "MIT":
print("license ok")
else:
print("license error, please set MIT license at package.json")
exit(1)
return metadata
Summary of Methods and Properties
The table below lists the methods and properties available via the metadata object within a script:
| Method/Property | Description |
|---|---|
metadata.all_inputs() | Returns all processed inputs from the Plugin. |
metadata.inputs | Dictionary containing the inputs. |
metadata.global_inputs | Dictionary containing the global inputs. |
metadata.global_computed_inputs | Dictionary containing the global computed inputs. |
metadata.target_path | Path where the Plugin is running. |
metadata.component_path | Path where the Plugin is stored (e.g., ~/.stk/stacks/my-stack/). |
metadata.filters | String filters integrated into Jinja Templates. |
metadata.group_id_folder(str) | Replaces dots . with slashes / (useful for Java packages). |
metadata.to_unidecode(str) | Removes accents and converts non-ASCII characters (e.g., áçhó -> acho). |