|
| 1 | +local d = import 'doc-util/main.libsonnet'; |
| 2 | + |
| 3 | +local patch = { |
| 4 | + secretProviderClass+: { |
| 5 | + local secrets_store_csi_driver = self, |
| 6 | + spec+: { |
| 7 | + parameters+: { |
| 8 | + '#newAzureParameters':: d.fn( |
| 9 | + help=' shortcut to define new azure specific prameters with defaults', |
| 10 | + args=[ |
| 11 | + d.arg('tenantId', d.T.string), |
| 12 | + d.arg('keyvaultName', d.T.string), |
| 13 | + d.arg('userAssignedIdentityId', d.T.string), |
| 14 | + d.arg('useVMManagedIdentity', d.T.bool, 'true'), |
| 15 | + d.arg('usePodIdentity', d.T.bool, 'false'), |
| 16 | + ] |
| 17 | + ), |
| 18 | + newAzureParameters( |
| 19 | + tenantId, |
| 20 | + keyvaultName, |
| 21 | + userAssignedIdentityId, |
| 22 | + useVMManagedIdentity=true, |
| 23 | + usePodIdentity=false |
| 24 | + ):: { |
| 25 | + cloudName: '', |
| 26 | + objects: '', |
| 27 | + } |
| 28 | + + self.withTenantId(tenantId) |
| 29 | + + self.withKeyvaultName(keyvaultName) |
| 30 | + + self.withUserAssignedIdentityId(userAssignedIdentityId) |
| 31 | + + self.withUseVMManagedIdentity(useVMManagedIdentity) |
| 32 | + + self.withUsePodIdentity(usePodIdentity), |
| 33 | + |
| 34 | + '#withUsePodIdentity':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('usePodIdentity', d.T.bool)]), |
| 35 | + withUsePodIdentity(usePodIdentity):: { usePodIdentity: std.toString(usePodIdentity) }, |
| 36 | + '#withUseVMManagedIdentity':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withUseVMManagedIdentity', d.T.bool)]), |
| 37 | + withUseVMManagedIdentity(useVMManagedIdentity):: { useVMManagedIdentity: std.toString(useVMManagedIdentity) }, |
| 38 | + '#withUserAssignedIdentityId':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withUserAssignedIdentityId', d.T.string)]), |
| 39 | + withUserAssignedIdentityId(userAssignedIdentityID):: { userAssignedIdentityID: userAssignedIdentityID }, |
| 40 | + '#withKeyvaultName':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withKeyvaultName', d.T.string)]), |
| 41 | + withKeyvaultName(keyvaultName):: { keyvaultName: keyvaultName }, |
| 42 | + '#withCloudName':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withCloudName', d.T.string)]), |
| 43 | + withCloudName(cloudName):: { cloudName: cloudName }, |
| 44 | + '#withTenantId':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withTenantId', d.T.string)]), |
| 45 | + withTenantId(tenantId):: { tenantId: tenantId }, |
| 46 | + '#withClientId':: d.fn(help='Helper-function to set attribute according to to specification (https://learn.microsoft.com/en-us/azure/aks/csi-secrets-store-identity-access#use-a-user-assigned-managed-identity)', args=[d.arg('withClientId', d.T.string)]), |
| 47 | + withClientId(clientId):: { clientID: clientId }, |
| 48 | + |
| 49 | + '#withObjects':: d.fn(help='Function to render objects-text. Takes an object-array e.g. [{objectName:"name",objectType:"secret"}] or an single object.', args=[d.arg('objects', d.T.array)]), |
| 50 | + withObjects(objects):: { |
| 51 | + objects: std.manifestYamlDoc({ |
| 52 | + local f = function(x) std.join('', std.map(function(y) ||| |
| 53 | + %s: '%s' |
| 54 | + ||| % [y, x[y]], std.objectFields(x))), |
| 55 | + array: std.map( |
| 56 | + f, |
| 57 | + if std.isArray(objects) then objects else [objects] |
| 58 | + ), |
| 59 | + }, indent_array_in_object=true, quote_keys=false), |
| 60 | + }, |
| 61 | + }, |
| 62 | + secretObjects+: { |
| 63 | + data+: { |
| 64 | + '#new':: d.fn( |
| 65 | + help='Create new secretsObjects data entry. Object has to have an objectName field or should be provided as objectName string', |
| 66 | + args=[ |
| 67 | + d.arg('key', d.T.string), |
| 68 | + d.arg('object', d.T.object), |
| 69 | + ] |
| 70 | + ), |
| 71 | + new(key, object):: |
| 72 | + local objectName = if std.isObject(object) then object.objectName else object; |
| 73 | + {} |
| 74 | + + secrets_store_csi_driver.spec.secretObjects.data.withKey(key) |
| 75 | + + secrets_store_csi_driver.spec.secretObjects.data.withObjectName(objectName), |
| 76 | + }, |
| 77 | + '#new':: d.fn( |
| 78 | + help='Create new secretsObject.', |
| 79 | + args=[ |
| 80 | + d.arg('name', d.T.string), |
| 81 | + d.arg('objects', d.T.array), |
| 82 | + ] |
| 83 | + ), |
| 84 | + new(name, objects, type='Opaque'):: |
| 85 | + {} |
| 86 | + + secrets_store_csi_driver.spec.secretObjects.withSecretName(name) |
| 87 | + + secrets_store_csi_driver.spec.secretObjects.withType(type) |
| 88 | + + secrets_store_csi_driver.spec.secretObjects.withData( |
| 89 | + [secrets_store_csi_driver.spec.secretObjects.data.new(x, objects[x]) for x in std.objectFields(objects)] |
| 90 | + ), |
| 91 | + }, |
| 92 | + }, |
| 93 | + '#new':: d.fn( |
| 94 | + help='Create new azure specific secretProviderClass.', |
| 95 | + args=[ |
| 96 | + d.arg('name', d.T.string), |
| 97 | + d.arg('tenantId', d.T.string), |
| 98 | + d.arg('keyvaultName', d.T.string), |
| 99 | + d.arg('userAssignedIdentityId', d.T.string), |
| 100 | + d.arg('objects', d.T.array, '[]'), |
| 101 | + d.arg('secretName', d.T.array, 'null'), |
| 102 | + d.arg('secretObjects', d.T.array, '[]'), |
| 103 | + ] |
| 104 | + ), |
| 105 | + newAzure( |
| 106 | + name, |
| 107 | + tenantId, |
| 108 | + keyvaultName, |
| 109 | + userAssignedIdentityId, |
| 110 | + objects=[], |
| 111 | + secretName=null, |
| 112 | + secretObjects=[] |
| 113 | + ):: self.new(name) |
| 114 | + + self.spec.withProvider('azure') |
| 115 | + + { |
| 116 | + spec+: { |
| 117 | + parameters+: secrets_store_csi_driver.spec.parameters.newAzureParameters( |
| 118 | + userAssignedIdentityId=userAssignedIdentityId, |
| 119 | + keyvaultName=keyvaultName, |
| 120 | + tenantId=tenantId |
| 121 | + ) + secrets_store_csi_driver.spec.parameters.withObjects(objects), |
| 122 | + }, |
| 123 | + } |
| 124 | + + if secretName != null then self.spec.withSecretObjects([ |
| 125 | + secrets_store_csi_driver.spec.secretObjects.new(secretName, objects), |
| 126 | + ]) else {} |
| 127 | + + self.spec.withSecretObjects(secretObjects), |
| 128 | + }, |
| 129 | +}; |
| 130 | + |
| 131 | +{ |
| 132 | + nogroup+: { |
| 133 | + v1+: patch, |
| 134 | + v1alpha1+: patch, |
| 135 | + }, |
| 136 | +} |
0 commit comments