Skip to content

Commit

Permalink
fix(configtree): prefix keys with '/' when importing to etcd
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Jul 15, 2024
1 parent 6e17408 commit d382bdc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions riocli/configtree/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
from base64 import b64encode
from typing import Optional

from etcd3gw import Etcd3Client


def import_in_etcd(data: dict, endpoint: str, port: Optional[int] = None, prefix: Optional[str] = None) -> None:
def import_in_etcd(
data: dict,
endpoint: str,
port: Optional[int] = None,
prefix: Optional[str] = None,
) -> None:
if port is None:
port = 2379

Expand All @@ -33,6 +39,8 @@ def import_in_etcd(data: dict, endpoint: str, port: Optional[int] = None, prefix
for key, val in data.items():
if prefix:
key = '{}/{}'.format(prefix, key)
elif not key.startswith('/'):
key = '/{}'.format(key)

enc_key = b64encode(str(key).encode('utf-8')).decode()
enc_val = b64encode(str(val).encode('utf-8')).decode()
Expand All @@ -56,8 +64,9 @@ def import_in_etcd(data: dict, endpoint: str, port: Optional[int] = None, prefix

cli.transaction(txn)


def _delete_all_keys(client: Etcd3Client) -> None:
null_char = '\x00'
enc_null = b64encode(null_char.encode('utf-8')).decode()
enc_null = b64encode(null_char.encode('utf-8')).decode()

client.delete('\x00', range_end=enc_null)

0 comments on commit d382bdc

Please sign in to comment.