예제 #1
0
        private async Task <V1Secret> CreateSecret(KamusSecret kamusSecret)
        {
            var @namespace     = kamusSecret.Metadata.NamespaceProperty ?? "default";
            var serviceAccount = kamusSecret.ServiceAccount;
            var id             = $"{@namespace}:{serviceAccount}";

            mLogger.Debug("Starting decrypting KamusSecret items. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            Action <Exception, string> errorHandler = (e, key) => mLogger.Error(e,
                                                                                "Failed to decrypt KamusSecret key {key}. KamusSecret {name} in namespace {namespace}",
                                                                                key,
                                                                                kamusSecret.Metadata.Name,
                                                                                @namespace);

            var decryptedData = await mKeyManagement.DecryptItems(kamusSecret.Data, id, errorHandler, Convert.FromBase64String);

            var decryptedStringData = await mKeyManagement.DecryptItems(kamusSecret.StringData, id, errorHandler, x => x);

            mLogger.Debug("KamusSecret items decrypted successfully. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            var ownerReference = !mSetOwnerReference ? new V1OwnerReference[0] : new[]
            {
                new V1OwnerReference
                {
                    ApiVersion         = kamusSecret.ApiVersion,
                    Kind               = kamusSecret.Kind,
                    Name               = kamusSecret.Metadata.Name,
                    Uid                = kamusSecret.Metadata.Uid,
                    Controller         = true,
                    BlockOwnerDeletion = true,
                }
            };

            IDictionary <string, string> annotations = null;

            if (kamusSecret.PropagateAnnotations)
            {
                annotations = kamusSecret.Metadata.Annotations;
                annotations.Remove("kubectl.kubernetes.io/last-applied-configuration");
            }

            return(new V1Secret
            {
                Metadata = new V1ObjectMeta
                {
                    Name = kamusSecret.Metadata.Name,
                    NamespaceProperty = @namespace,
                    Labels = kamusSecret.Metadata.Labels,
                    Annotations = annotations,
                    OwnerReferences = ownerReference
                },
                Type = kamusSecret.Type,
                StringData = decryptedStringData,
                Data = decryptedData
            });
        }
예제 #2
0
        private async Task <V1Secret> CreateSecret(KamusSecret kamusSecret)
        {
            var @namespace     = kamusSecret.Metadata.NamespaceProperty ?? "default";
            var serviceAccount = kamusSecret.ServiceAccount;
            var id             = $"{@namespace}:{serviceAccount}";

            mLogger.Debug("Starting decrypting KamusSecret items. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            Action <Exception, string> errorHandler = (e, key) => mLogger.Error(e,
                                                                                "Failed to decrypt KamusSecret key {key}. KamusSecret {name} in namespace {namespace}",
                                                                                key,
                                                                                kamusSecret.Metadata.Name,
                                                                                @namespace);

            var decryptedData = await mKeyManagement.DecryptItems(kamusSecret.Data, id, errorHandler, Convert.FromBase64String);

            var decryptedStringData = await mKeyManagement.DecryptItems(kamusSecret.StringData, id, errorHandler, x => x);

            mLogger.Debug("KamusSecret items decrypted successfully. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            var ownerReference = !this.mSetOwnerReference ? new V1OwnerReference[0] : new[]
            {
                new V1OwnerReference
                {
                    ApiVersion         = kamusSecret.ApiVersion,
                    Kind               = kamusSecret.Kind,
                    Name               = kamusSecret.Metadata.Name,
                    Uid                = kamusSecret.Metadata.Uid,
                    Controller         = true,
                    BlockOwnerDeletion = true,
                }
            };

            return(new V1Secret
            {
                Metadata = new V1ObjectMeta
                {
                    Name = kamusSecret.Metadata.Name,
                    NamespaceProperty = @namespace,
                    OwnerReferences = ownerReference
                },
                Type = kamusSecret.Type,
                StringData = decryptedStringData,
                Data = decryptedData
            });
        }
예제 #3
0
        private async Task <V1Secret> CreateSecret(KamusSecret kamusSecret)
        {
            var @namespace     = kamusSecret.Metadata.NamespaceProperty ?? "default";
            var serviceAccount = kamusSecret.ServiceAccount;
            var id             = $"{@namespace}:{serviceAccount}";

            mLogger.Debug("Starting decrypting KamusSecret items. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            Action <Exception, string> errorHandler = (e, key) => mLogger.Error(e,
                                                                                "Failed to decrypt KamusSecret key {key}. KamusSecret {name} in namespace {namespace}",
                                                                                key,
                                                                                kamusSecret.Metadata.Name,
                                                                                @namespace);

            var decryptedStrings = await mKeyManagement.DecryptItems(kamusSecret.Data, id, errorHandler, x => x);

            mLogger.Debug("KamusSecret items decrypted successfully. KamusSecret {name} in namespace {namespace}",
                          kamusSecret.Metadata.Name,
                          @namespace);

            return(new V1Secret
            {
                Metadata = new V1ObjectMeta
                {
                    Name = kamusSecret.Metadata.Name,
                    NamespaceProperty = @namespace
                },
                Type = kamusSecret.Type,
                StringData = decryptedStrings
            });
        }