Skip to content

Commit

Permalink
fix(configtree): update sentinel key when tree is imported in etcd
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Jul 23, 2024
1 parent 6e17408 commit c60256b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions riocli/configtree/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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

from etcd3gw import Etcd3Client


Expand Down Expand Up @@ -49,13 +50,30 @@ def import_in_etcd(data: dict, endpoint: str, port: Optional[int] = None, prefix
}
})

sentinel_key = b64encode('/sentinel_key'.encode('utf-8')).decode()
sentinel_val = b64encode(f'{time.time_ns()}|riocli-import'.encode('utf-8')).decode()

compares.append({
'key': sentinel_key,
'result': 'EQUAL',
'target': 'VALUE',
'value': sentinel_val,
})
failures.append({
'request_put': {
'key': sentinel_key,
'value': sentinel_val,
}
})

txn = {
'compare': compares,
'failure': failures,
}

cli.transaction(txn)


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

0 comments on commit c60256b

Please sign in to comment.