How to use get_secret method in Kiwi

Best Python code snippet using Kiwi_python

test_get_secret.py

Source:test_get_secret.py Github

copy

Full Screen

1########2# Copyright (c) 2014 GigaSpaces Technologies Ltd. All rights reserved3#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 at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# * See the License for the specific language governing permissions and14# * limitations under the License.15from dsl_parser import functions16from mock import MagicMock17from dsl_parser import exceptions18from dsl_parser.tasks import prepare_deployment_plan19from dsl_parser.tests.abstract_test_parser import AbstractTestParser20class TestGetSecret(AbstractTestParser):21 secrets_yaml = """22data_types:23 agent_config_type:24 properties:25 user:26 type: string27 required: false28 key:29 type: string30 required: false31relationships:32 cloudify.relationships.contained_in: {}33plugins:34 p:35 executor: central_deployment_agent36 install: false37node_types:38 webserver_type:39 properties:40 ip:41 default: ''42 agent_config:43 type: agent_config_type44node_templates:45 node:46 type: webserver_type47 webserver:48 type: webserver_type49 properties:50 ip: { get_secret: ip }51 agent_config:52 key: { get_secret: agent_key }53 user: { get_secret: user }54 interfaces:55 test:56 op_with_no_get_secret:57 implementation: p.p58 inputs:59 a: 160 op_with_get_secret:61 implementation: p.p62 inputs:63 a: { get_secret: node_template_secret_id }64 relationships:65 - type: cloudify.relationships.contained_in66 target: node67 source_interfaces:68 test:69 op_with_no_get_secret:70 implementation: p.p71 inputs:72 a: 173 op_with_get_secret:74 implementation: p.p75 inputs:76 a: { get_secret: source_op_secret_id }77 target_interfaces:78 test:79 op_with_no_get_secret:80 implementation: p.p81 inputs:82 a: 183 op_with_get_secret:84 implementation: p.p85 inputs:86 a: { get_secret: target_op_secret_id }87outputs:88 webserver_url:89 description: Web server url90 value: { concat: ['http://', { get_secret: ip }, ':',91 { get_secret: webserver_port }] }92"""93 def test_has_intrinsic_functions_property(self):94 yaml = """95relationships:96 cloudify.relationships.contained_in: {}97plugins:98 p:99 executor: central_deployment_agent100 install: false101node_types:102 webserver_type: {}103node_templates:104 node:105 type: webserver_type106 webserver:107 type: webserver_type108 interfaces:109 test:110 op_with_no_get_secret:111 implementation: p.p112 inputs:113 a: 1114 op_with_get_secret:115 implementation: p.p116 inputs:117 a: { get_secret: node_template_secret_id }118 relationships:119 - type: cloudify.relationships.contained_in120 target: node121 source_interfaces:122 test:123 op_with_no_get_secret:124 implementation: p.p125 inputs:126 a: 1127 op_with_get_secret:128 implementation: p.p129 inputs:130 a: { get_secret: source_op_secret_id }131 target_interfaces:132 test:133 op_with_no_get_secret:134 implementation: p.p135 inputs:136 a: 1137 op_with_get_secret:138 implementation: p.p139 inputs:140 a: { get_secret: target_op_secret_id }141"""142 parsed = prepare_deployment_plan(self.parse(yaml),143 self._get_secret_mock)144 webserver_node = None145 for node in parsed.node_templates:146 if node['id'] == 'webserver':147 webserver_node = node148 break149 self.assertIsNotNone(webserver_node)150 def assertion(operations):151 op = operations['test.op_with_no_get_secret']152 self.assertIs(False, op.get('has_intrinsic_functions'))153 op = operations['test.op_with_get_secret']154 self.assertIs(True, op.get('has_intrinsic_functions'))155 assertion(webserver_node['operations'])156 assertion(webserver_node['relationships'][0]['source_operations'])157 assertion(webserver_node['relationships'][0]['target_operations'])158 def test_validate_secrets_all_valid(self):159 get_secret_mock = MagicMock(return_value='secret_value')160 parsed = prepare_deployment_plan(self.parse_1_3(self.secrets_yaml),161 get_secret_mock)162 self.assertTrue(get_secret_mock.called)163 self.assertFalse(hasattr(parsed, 'secrets'))164 def test_validate_secrets_all_invalid(self):165 expected_message = "Required secrets \['target_op_secret_id', " \166 "'node_template_secret_id', 'ip', 'agent_key', " \167 "'user', 'webserver_port', " \168 "'source_op_secret_id'\] don't exist in this tenant"169 get_secret_not_found = MagicMock(side_effect=TestNotFoundException)170 self.assertRaisesRegexp(exceptions.UnknownSecretError,171 expected_message,172 prepare_deployment_plan,173 self.parse_1_3(self.secrets_yaml),174 get_secret_not_found)175 def test_validate_secrets_unexpected_exception(self):176 get_secret_exception = MagicMock(side_effect=TypeError)177 self.assertRaisesRegexp(TypeError,178 '',179 prepare_deployment_plan,180 self.parse_1_3(self.secrets_yaml),181 get_secret_exception)182 def test_validate_secrets_some_invalid(self):183 expected_message = "Required secrets \['ip', 'source_op_secret_id'\]" \184 " don't exist in this tenant"185 get_secret_not_found = MagicMock()186 get_secret_not_found.side_effect = [None, None, TestNotFoundException,187 None, None, None,188 TestNotFoundException]189 self.assertRaisesRegexp(exceptions.UnknownSecretError,190 expected_message,191 prepare_deployment_plan,192 self.parse_1_3(self.secrets_yaml),193 get_secret_not_found)194 def test_validate_secrets_without_secrets(self):195 no_secrets_yaml = """196relationships:197 cloudify.relationships.contained_in: {}198plugins:199 p:200 executor: central_deployment_agent201 install: false202node_types:203 webserver_type: {}204node_templates:205 node:206 type: webserver_type207 webserver:208 type: webserver_type209 interfaces:210 test:211 op_with_no_get_secret:212 implementation: p.p213 inputs:214 a: 1215 relationships:216 - type: cloudify.relationships.contained_in217 target: node218 source_interfaces:219 test:220 op_with_no_get_secret:221 implementation: p.p222 inputs:223 a: 1224 target_interfaces:225 test:226 op_with_no_get_secret:227 implementation: p.p228 inputs:229 a: 1230"""231 get_secret_mock = MagicMock(return_value='secret_value')232 parsed = prepare_deployment_plan(self.parse_1_3(no_secrets_yaml),233 get_secret_mock)234 self.assertFalse(get_secret_mock.called)235 self.assertFalse(hasattr(parsed, 'secrets'))236class TestNotFoundException(Exception):237 http_code = 404238class TestEvaluateFunctions(AbstractTestParser):239 def test_evaluate_functions(self):240 payload = {241 'a': {'get_secret': 'id_a'},242 'b': {'get_secret': 'id_b'},243 'c': {'get_secret': 'id_c'},244 'd': {'get_secret': 'id_d'},245 'f': {'concat': [246 {'get_secret': 'id_a'},247 {'get_secret': 'id_b'},248 {'get_secret': 'id_c'},249 {'get_secret': 'id_d'}250 ]}251 }252 functions.evaluate_functions(payload,253 {},254 None,255 None,256 None,257 self._get_secret_mock)258 self.assertEqual(payload['a'], 'id_a_value')259 self.assertEqual(payload['b'], 'id_b_value')260 self.assertEqual(payload['c'], 'id_c_value')261 self.assertEqual(payload['d'], 'id_d_value')262 self.assertEqual(payload['f'], 'id_a_valueid_b_value'263 'id_c_valueid_d_value')264 def test_node_template_properties_simple(self):265 yaml = """266node_types:267 type:268 properties:269 property: {}270node_templates:271 node:272 type: type273 properties:274 property: { get_secret: secret }275"""276 parsed = prepare_deployment_plan(self.parse_1_3(yaml),277 self._get_secret_mock)278 node = self.get_node_by_name(parsed, 'node')279 self.assertEqual({'get_secret': 'secret'},280 node['properties']['property'])281 functions.evaluate_functions(282 parsed,283 {},284 None,285 None,286 None,287 self._get_secret_mock288 )...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

1from dataengine.common.secrets import get_secret2from dataengine.monzo.model.monzo_config import MonzoApiConfig3SERVER_NAME = get_secret('SERVER_NAME')4# Monzo5BASE_URL = 'https://api.monzo.com'6MONZO_REDIRECT_URL = get_secret('MONZO_REDIRECT_URL')7DEFAULT_MONZO_REDIRECT_URL = 'http://127.0.0.1:8050/home?from=auth'8def get_monzo_config():9 return MonzoApiConfig(10 monzo_client_secret=get_secret('MONZO_CLIENT_SECRET'),11 monzo_client_id=get_secret('MONZO_CLIENT_ID'),12 monzo_account_id=get_secret('MONZO_ACC_ID'),13 base_url=BASE_URL,14 redirect_uri=MONZO_REDIRECT_URL if MONZO_REDIRECT_URL else DEFAULT_MONZO_REDIRECT_URL,15 auth_base_url='https://auth.monzo.com'16 )17SERVER_SECRET_KEY = get_secret("SERVER_SECRET_KEY")18SERVER_SESSION_TYPE = 'filesystem'19SESSION_COOKIE_NAME = 'mysession'20# influxdb21INFLUXDB_TOKEN = get_secret('INFLUXDB_TOKEN_V3')22INFLUXDB_ORG = get_secret('INFLUXDB_ORG')23INFLUXDB_BUCKET = get_secret('INFLUXDB_BUCKET')24INFLUXDB_URL = get_secret("INFLUXDB_URL")25# redis26REDIS_PORT = 637927REDIS_HOST = "redis"28# Auth029AUTH0_CLIENT_ID = get_secret('AUTH0_CLIENT_ID')30AUTO0_CLIENT_SECRET = get_secret('AUTH0_CLIENT_SECRET')31AUTH0_API_BASE_URL = get_secret('AUTH0_API_BASE_URL')32AUTH0_ACCESS_TOKEN_URL = f'{AUTH0_API_BASE_URL}/oauth/token'33AUTH0_AUTHORIZE_URL = f'{AUTH0_API_BASE_URL}/authorize'34AUTH0_CLIENT_KWARGS = 'openid profile email'35AUTH0_CALLBACK_URL = get_secret('AUTH0_CALLBACK_URL')36# DB37DB_USERNAME = get_secret("POSTGRES_USER")38DB_PASSWORD = get_secret("POSTGRES_PASSWORD")39DB_HOST = get_secret("POSTGRES_HOST")40DB_PORT = 543241DB_NAME = get_secret("POSTGRES_DB") if get_secret("POSTGRES_DB") else 'dataengine'42#MapBox43MAPBOX_ACCESS_TOKEN = get_secret('mapboxgl_access_token')44# Service45EVENT_INFLUX_BUCKET = 'events'46# USER Metric names47ALCOHOL_METRIC = 'alcohol_units'48# View49# DDD at hh:mm (dd/mm/yyyy)50DATETIME_VIEW_FORMAT = "%a at %H:%M (%d/%m/%y)"51DATETIME_LABEL_FORMAT = "%d/%m/%y, %H:%M"52DATETIME_LABEL_WITH_DOW = "%a, %d-%m-%Y"53DEFAULT_DISPLAY_RESOURCE_DAYS_AGO = 3054DEFAULT_DISPLAY_RESOURCE_SHORT_DAYS_AGO = 755# Event...

Full Screen

Full Screen

key_vaults.py

Source:key_vaults.py Github

copy

Full Screen

...5 kv_endpoint = 'https://kv-perseus.vault.azure.net/'6 credential = ManagedIdentityCredential()7 client = SecretClient(vault_url=kv_endpoint, credential=credential)8 config = {9 'DB_NAME': client.get_secret('SharedDbName').value,10 'DB_USER': client.get_secret('SharedDbAuthUser').value,11 'DB_PASSWORD': client.get_secret('SharedDbAuthPass').value,12 'DB_HOST': client.get_secret('SharedDbHost').value,13 'DB_PORT': client.get_secret('SharedDbPort').value,14 'TOKEN_SECRET_KEY': client.get_secret('TokenSecretKey').value,15 'EMAIL_SECRET_KEY': client.get_secret('EmailSecretKey').value,16 'SMTP_SERVER': client.get_secret('SmtpServer').value,17 'SMTP_PORT': client.get_secret('SmtpPort').value,18 'SMTP_EMAIL': client.get_secret('SmtpEmail').value,19 'SMTP_USER': client.get_secret('SmtpUser').value,20 'SMTP_PWD': client.get_secret('SmtpPass').value21 }22 client.close()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful