splunk / splunk/contentctl

Allow splunk_api_username and splunk_api_password to be specified as environment variables

Open
#321 1 comment 0 reactions 1 assignee View on GitHub

@pyth0n1c is already working on this.

Since Nov 4, 2024.

Dominant language
Python
Stars
139
Forks
52
Avg merge
1h 16m
Merged PRs (30d)
3

Description

The splunk_api_username and splunk_api_password keys in contentctl.yml should be allowed to be provided as environment variables, to avoid putting credentials in YAML files.

Here is a git patch file that adds this change:

From f74ae37c6ec9e3b5da84029cb3afade71cca48f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89milio=20Gonzalez?= <little.moon6016@fastmail.com>
Date: Mon, 4 Nov 2024 20:34:30 +0000
Subject: Merged PR 114299: Allow test.splunk_api_username and
 test.splunk_api_password to be specified w...

Allow test.splunk_api_username and test.splunk_api_password to be specified with environment variables SPLUNKBASE_USERNAME and SPLUNKBASE_PASSWORD to avoid putting credentials in YAML files.
---
 contentctl/objects/config.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/contentctl/objects/config.py b/contentctl/objects/config.py
index cbf6929..4228ba9 100644
--- a/contentctl/objects/config.py
+++ b/contentctl/objects/config.py
@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+import os
 from os import environ
 from datetime import datetime, UTC
 from typing import Optional, Any, List, Union, Self
@@ -830,10 +831,17 @@ class test(test_common):
     model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
     container_settings:ContainerSettings = ContainerSettings()
     test_instances: List[Container] = Field([], exclude = True, validate_default=True)
-    splunk_api_username: Optional[str] = Field(default=None, exclude = True,description="Splunk API username used for running appinspect or installating apps from Splunkbase")
-    splunk_api_password: Optional[str] = Field(default=None, exclude = True, description="Splunk API password used for running appinspect or installaing apps from Splunkbase")
-    
-    
+    splunk_api_username: Optional[str] = Field(default=None, exclude = True,description="Splunk API username used for running appinspect or installating apps from Splunkbase. Can be replaced by the 'SPLUNKBASE_USERNAME' environment variable.")
+    splunk_api_password: Optional[str] = Field(default=None, exclude = True, description="Splunk API password used for running appinspect or installaing apps from Splunkbase. Can be replaced by the 'SPLUNKBASE_PASSWORD' environment variable.")
+
+    def __init__(self, **kwargs):
+        if "SPLUNKBASE_USERNAME" in os.environ:
+            breakpoint()
+            kwargs['splunk_api_username'] = os.environ["SPLUNKBASE_USERNAME"]
+        if "SPLUNKBASE_PASSWORD" in os.environ:
+            kwargs['splunk_api_password'] = os.environ["SPLUNKBASE_PASSWORD"]
+        super().__init__(**kwargs)
+
     def getContainerInfrastructureObjects(self)->Self:
         try:
             self.test_instances = self.container_settings.getContainers()
-- 
2.34.1

To fix bugs and add features in a timely manner, I maintain a private fork of contentctl and the content has drifted, so I cannot easily open a PR at the moment for this feature, but would like it to be included upstream.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.