mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-24 07:54:14 +08:00
b6c5bf067a
* updated action file with node16 * Code consistency using prettier and its workflow * Enforce Prettier * code fix * code fix * code fix Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
26 lines
756 B
TypeScript
26 lines
756 B
TypeScript
import * as util from 'util'
|
|
|
|
export interface K8sSecret {
|
|
data: {
|
|
token: string
|
|
'ca.crt': string
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Throws an error if an object does not have all required fields to be a K8sSecret
|
|
* @param secret
|
|
* @returns A type guarded K8sSecret
|
|
*/
|
|
export function parseK8sSecret(secret: any): K8sSecret {
|
|
if (!secret) throw Error('K8s secret yaml is invalid')
|
|
if (!secret.data) throw k8sSecretMissingFieldError('data')
|
|
if (!secret.data.token) throw k8sSecretMissingFieldError('token')
|
|
if (!secret.data['ca.crt']) throw k8sSecretMissingFieldError('ca.crt')
|
|
|
|
return secret as K8sSecret
|
|
}
|
|
|
|
const k8sSecretMissingFieldError = (field: string): Error =>
|
|
Error(util.format('K8s secret yaml does not contain %s field', field))
|