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

Allow splunk_api_username and splunk_api_password to be specified as environment variables #321

Open
Res260 opened this issue Nov 4, 2024 · 1 comment · May be fixed by #327
Open

Allow splunk_api_username and splunk_api_password to be specified as environment variables #321

Res260 opened this issue Nov 4, 2024 · 1 comment · May be fixed by #327
Assignees

Comments

@Res260
Copy link
Contributor

Res260 commented Nov 4, 2024

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?= <[email protected]>
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.

@pyth0n1c
Copy link
Contributor

pyth0n1c commented Nov 4, 2024

Sorry for the delay in getting to this, as we have been helping out with some internal Splunk releases.

Thank you @Res260 , you have been hard at work with some AWESOME fixes and improvements. I admit that downloading apps from Splunkbase is a feature that used to work, but we have not used (or tested it) in quite some time. Thanks for exposing all these issue. I am going to merge all the following fixes/PRs down to a single new branch for evaluation.

Related Bugs:
#295
#319
#321

Related PRs:
#317
#320

I have opened the following PR which will be used to merge + test these changes together:
#322 (I will add these changes to the branch manually)

I will leave these issues open until all of these are reviewed + merged and a new contentctl release it made!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants