blob: 179135e5f491a1543188144bdfe1c68adfca7985 [file] [log] [blame]
garciadeblas96b94f52024-07-08 16:18:21 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19import base64
20
21
22async def create_secret(self, secret_name, secret_namespace, secret_key, secret_value):
23 async def check_secret(secret_name, secret_namespace, secret_key, secret_value):
24 self.logger.info(f"Checking content of secret {secret_name} ...")
25 returned_secret_data = await self._kubectl.get_secret_content(
26 name=secret_name,
27 namespace=secret_namespace,
28 )
29 self.logger.debug(f"Result from async call: { returned_secret_data }")
30
31 self.logger.debug("Comparing secret values")
32 returned_secret_value = base64.b64decode(
33 returned_secret_data[secret_key]
34 ).decode("utf-8")
35 self.logger.debug(f"secret_data_original={secret_value}")
36 self.logger.debug(f"secret_data_received={returned_secret_value}")
37 self.logger.info(
38 f"Result of secret comparison: {secret_value==returned_secret_value} ..."
39 )
40
41 self.logger.info(
42 f"Creating secret {secret_name} in namespace {secret_namespace} ..."
43 )
44 secret_data = {secret_key: base64.b64encode(secret_value.encode()).decode("utf-8")}
45 self.logger.info(f"Secret name: {secret_name}")
46 self.logger.info(f"Secret data {secret_data}")
47 self.logger.info(f"Namespace: {secret_namespace}")
48 self.logger.info("Calling N2VC kubectl to create secret...")
49 await self._kubectl.create_secret(
50 name=secret_name,
51 data=secret_data,
52 namespace=secret_namespace,
53 secret_type="Opaque",
54 )
55 self.logger.info(f"Secret {secret_name} CREATED")
56
57 await check_secret(secret_name, secret_namespace, secret_key, secret_value)