#146 Adding optional kubeconfig encoding variable (#164)

* encoding input variable added

* encoding input variable added

* encoding input variable added

* corrected unit tests

* corrected unit tests

* prettier edits

* working on tests

* working on tests

* working on tests

* minor edits

* minor edits

* better logic structure

* added tests for edge cases

* edited to enum
This commit is contained in:
Betsy George
2025-07-17 14:27:04 -04:00
committed by GitHub
parent 8440376895
commit 0fc754ad67
3 changed files with 67 additions and 1 deletions
+21 -1
View File
@@ -44,7 +44,27 @@ export function getDefaultKubeconfig(): string {
}
default: {
core.debug('Setting context using kubeconfig')
return core.getInput('kubeconfig', {required: true})
enum Encoding {
Base64 = 'base64',
Plaintext = 'plaintext'
}
const rawKubeconfig = core.getInput('kubeconfig', {required: true})
const encoding =
core.getInput('kubeconfig-encoding')?.toLowerCase() ||
Encoding.Plaintext
if (encoding !== Encoding.Base64 && encoding !== Encoding.Plaintext) {
throw new Error(
`Invalid kubeconfig-encoding: '${encoding}'. Must be 'plaintext' or 'base64'.`
)
}
const kubeconfig =
encoding === Encoding.Base64
? Buffer.from(rawKubeconfig, 'base64').toString('utf-8')
: rawKubeconfig
return kubeconfig
}
}
}