n#JddlZddlZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z mZmZddlZddlmZddlmZmZmZmZmZmZmZddlmZmZejd Z ejd Z!e rdd lm"Z"d Z#d Z$dZ%dZ&dZ'dZ(dZ)dZ*e*dzZ+GddZ,dS)N) dataclass)datetimetimezone)sha256) TYPE_CHECKINGListOptionalUnion)api)BadObjectMetaErrorDigestMismatchErrorLinkIsABucketError NotFoundErrorObjectAlreadyExistsObjectDeletedErrorObjectNotFoundError)MSG_ROLLUP_SUBJECTStopIterSentinelz^[a-zA-Z0-9_-]+$z^[-/_=\.a-zA-Z0-9]+$)JetStreamContextz OBJ_{bucket}z$O.{bucket}.C.>z$O.{bucket}.M.>z$O.{bucket}.C.{obj}z$O.{bucket}.M.{obj}0izSHA-256=z{digest}c eZdZdZeGddZedGddZded ed d d d fdZ ddede e d e j fdZ d dede ejde e d efdZ d!dedeeeejfde e jd e j fdZd efdZdZdede jfdZGddZ d"d efdZded efdZ dd ee j fdZd S)# ObjectStorezK ObjectStore uses the JetStream ObjectStore functionality. :: cReZdZUdZejed<eZe eed<dS)ObjectStore.ObjectResultzX ObjectResult is the result returned from the ObjectStore in JetStream. infodataN) __name__ __module__ __qualname____doc__r ObjectInfo__annotations__bytesrr t/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/nats/js/object_store.py ObjectResultr>sF  n %huo'''''r%r'T)frozenceZdZUdZejed<eed<ede efdZ ede e fdZ ede ej fdZede efdZedefd Zedefd Zd S) ObjectStore.ObjectStoreStatuszJ ObjectStoreStatus is the status of a ObjectStore bucket. stream_infobucketreturnc$|jjjS)z[ description is the description supplied when creating the bucket. )r+config descriptionselfs r&r0z)ObjectStore.ObjectStoreStatus.descriptionPs #*6 6r%cJ|jjjdS|jjjS)z= ttl returns the max age in seconds. N)r+r/max_ager1s r&ttlz!ObjectStore.ObjectStoreStatus.ttlWs' &.6t#*2 2r%c$|jjjS)zk storage indicates the underlying JetStream storage technology used to store data. )r+r/storager1s r& storage_typez*ObjectStore.ObjectStoreStatus.storage_type`s #*2 2r%c$|jjjS)zk replicas indicates how many storage replicas are kept for the data in the bucket. )r+r/ num_replicasr1s r&replicasz&ObjectStore.ObjectStoreStatus.replicasgs #*7 7r%c$|jjjS)zb sealed indicates the stream is sealed and cannot be modified in any way. )r+r/sealedr1s r&r=z$ObjectStore.ObjectStoreStatus.sealedns #*1 1r%c$|jjjS)zk size is the combined size of all data in the bucket including metadata, in bytes. )r+stater#r1s r&sizez"ObjectStore.ObjectStoreStatus.sizeus #)/ /r%N)rrrr r StreamInfor"strpropertyr r0floatr5 StorageTyper8intr;boolr=r@r$r%r&ObjectStoreStatusr*Gs4  ^###  7# 7 7 7  7  3% 3 3 3  3  3(3?"; 3 3 3  3  8hsm 8 8 8  8  2D 2 2 2  2  0# 0 0 0  0 0 0r%rHnamestreamjsrr-Nc0||_||_||_dSN)_name_stream_js)r2rIrJrKs r&__init__zObjectStore.__init__|s   r%F show_deletedc BK|}t|jtjt |d}t|j}d} |j ||d{V}n#t$rtwxYwd}|j r|j } tjt!j|}n#t$$r } t&| d} ~ wwxYw|s|jrt|S)zP get_info will retrieve the current information for the object. utf-8r,objr,N)OBJ_META_PRE_TEMPLATEformatrNbase64urlsafe_b64encoder#decodeOBJ_STREAM_TEMPLATErP get_last_msgrrrr r! from_responsejsonloads Exceptionr deleted) r2rIrRrVmetarJmsgrres r&get_infozObjectStore.get_infosE$++:(sG)<)<==DDFF,  %++4:+>> &--fd;;;;;;;;CC & & &% % & 8 8D ,>// 40@0@AADD , , ,$! + , &$, &% %  s$;!BB/1C55 D ?DD  writeintocbK|}|||d{V}|j |jdkrt|r|jjj|jjjdkrt|j |jjj d{V}| |jjjd{VS| |}|j dkr|St|j|j}|j|dd{V} t%} d} d} |r> :| %-1B1G21M1M((..t|/@/GHHHHHHHHD$,"3"899999999 9"""-- 9>>M,334:493UU H&&zD&QQQQQQQQ HH  ./11AHy(++ .'.4 'o . . . . . . . .#--ci88F (ht[#(;;;;;;;;;; sx' HHSX   ayN**oo'''''''''hhjj![00"EEMMoNcNcNeNegijj / ;;d{{--%/( sJ.rrdc Z K|tj|}nt|dkr||_|jtjt |_|j}d}|jjj }t |j |} ||jd{V}n#t $rYnwxYwd}t#|t$r't'j|}nt#|t,rt'j|}nt/|dst#|t&jrt3jj}nAt/|dst#|t&jr|j}nt=dtj|j|j |j!|j|j |ddtEj#tHj%& } tO} tQ|jj)} d} d} d}|r|d|j*| d{V}n|*| }|dkrn| d|}| +||j,||d{V| d z } | |z } n;#tZ$r.}|j.|j/| d{V|d}~wwxYw| 0}| | _1| | _2tf tij5| | _0tl |j tij5t-|d} |j,|toj8| 9tj:j;txid{Vn;#tZ$r.}|j.|j/| d{V|d}~wwxYwtEj#tHj%&| _=|T|j>sMt |j |j?}|j.|j/| d{V| S)zU put will place the contents from the reader into this object-store. N)rIr)max_chunk_sizerUreadintormz#nats: invalid type for object store) rIr0headersrqr,ror@chunksmtimeTrk)rrTr)@r ObjectMetalenrIrqObjectMetaOptionsOBJ_DEFAULT_CHUNK_SIZErP_nc_nuidnextrurYrNr\rgr isinstancerBioBytesIOencoder#rzBufferedIOBaserwrxry TextIOWrapperrm TypeErrorr!r0rrnowrutc isoformatr bytearrayrrrpublishrb purge_streamrOrr@rOBJ_DIGEST_TEMPLATErZr[rXr`dumpsas_dictHeaderROLLUPrrrcro)r2rIrrdrVeinfonewnuidrrrrchunksenttotalnpayloaderrr meta_subjs r&putzObjectStore.puts> <>t,,,DD YY]]DI < 05DLi(,$))++-334:7>>K[K[3\\  -- 22222222EE    D  dC C:dkkmm,,DD e $ $ C:d##DD T: & & C*T2;L*M*M C/11AHH T8 $ $ C 49I(J(J C;DDABB B~(LL:!!,x|,,6688     HH$,566  -&htT]EBBBBBBBBAA e,,A66)!!!h&&z7;;;;;;;;;     h++DL*+MMMMMMMMM   &hhjj  )008PQT8U8U8\8\8^8^0__ *00:(sG)<)<==DDFF1   ("" 4<<>>**1133*,>?#            ('' j'II I I I I I I II  \(,//99;;   U] 077tzuz7ZZJ('' j'II I I I I I I I sJ; C C)(C);8K?4A K?? L7 )L22L75A/Q%% R/)RRcK|j|jd{V}|||j}|S)zA status retrieves runtime status about a bucket. N)r+r,)rPr+rOrHrN)r2rstatuss r&rzObjectStore.statusasPX))$,77777777''D'LL r%cK|j|jd{V}|j}d|_|j|d{VdS)z\ seal will seal the object store, no further modifications will be allowed. NT)rPr+rOr/r= update_stream)r2rr/s r&sealzObjectStore.sealismX))$,77777777 h$$V,,,,,,,,,,,r%c >Kd} ||d{V}n#t$rtwxYw||jkr+||dd{V}|jst |j|_|j|_|j|_t |j tj t|d} |j|t#j|t*jjt0id{Vn#t2$r}|d}~wwxYw||jkr)|j|j|d{VdSdS)z] update_meta will place the contents from the reader into this object-store. NT)rRrTrUrr)rgrrrIrcrr0rrXrYrNrZr[r#r\rPrr`rrrr rrrrbrrO)r2rIrdrrrrs r& update_metazObjectStore.update_metars %t,,,,,,,,DD" % % %$ $ % 49  --4-@@@@@@@@E= *))I +| *00:(tW)=)=>>EEGG1   ("" 4<<>>**1133*,>?#            I  49  ('' i'HH H H H H H H H H H  s!"4%A/E E&E!!E&cBeZdZeZdZdZddZdZdZ dS) ObjectStore.ObjectWatchercr||_tjd|_d|_d|_d|_dS)N)maxsizeF)rPrwQueue_updates_sub_pending _init_done)r2rKs r&rQz"ObjectStore.ObjectWatcher.__init__s:DHZaZgpsZtZtZtDMDI+/DM$DOOOr%cHK|jd{VdS)z6 stop will stop this watcher. N)rrr1s r&stopzObjectStore.ObjectWatcher.stops4)'')) ) ) ) ) ) ) ) ) )r%@cK tj|j|d{VS#tj$rt jjwxYw)zI updates fetches the next update from a watcher. N)rwwait_forrrt TimeoutErrornatserrors)r2timeouts r&updatesz!ObjectStore.ObjectWatcher.updatessg /$-dm.?.?.A.A7KKKKKKKKK' / / /k.. /s 16!Ac|SrMr$r1s r& __aiter__z#ObjectStore.ObjectWatcher.__aiter__sKr%cK |jd{V}t|trt|SrM)rrtrrStopAsyncIteration)r2entrys r& __anext__z#ObjectStore.ObjectWatcher.__anext__sN "m//11111111e%566-,, r%N)r) rrrr STOP_ITERrQrrrrr$r%r& ObjectWatcherrsr$$&&  $ $ $ * * *  / / / /        r%rcKt|j}t|fd} |j|j|d{Vn7#t$r*d_ j dd{VYnwxYwd}|stj j}|j||d|d{V_t#jdd{VS)za watch for changes in the underlying store and receive meta information updates. rWcRK|j}tjt j|j}r|js j |d{Vj s4|j dkr+d_ j dd{VdSdSdS)NrT) metadatar r!r_r`rarrcrrr num_pending)rerdrignore_deleteswatchers r& watch_updatesz(ObjectStore.watch..watch_updatess// 380D0DEED" 1DL 1&**4000000000& 1D,<,A,A%)"&**400000000000 1 1,A,Ar%NT)cbrldeliver_policyr)OBJ_ALL_META_PRE_TEMPLATErYrNrrrPr^rOrrrrr DeliverPolicyLAST_PER_SUBJECTrvrrwsleep)r2rinclude_history meta_onlyall_metarrrs ` @r&watchzObjectStore.watchsn-33:4  ++D11 1 1 1 1 1 1 -('' h?? ? ? ? ? ? ? ? ? - - -!%G "&&t,, , , , , , , , , , - @ .?N!X// !) 0         mAs&A--1B! B!c 4K|}||d{V}|j |jdkrtt|j|j}d|_d|_d|_d|_ d|_ t|jtj t|d} |j|t%j|t,jjt2id{V|j|j|d{VdS#|j|j|d{VwxYw) z0 delete will delete the object. NrjrUTrrTrr)rgror rurYrNrcr@rrrrXrZr[r#r\rPrr`rrrr rrrrrO)r2rIrVrrrs r&deletezObjectStore.deletes]]3'''''''' 9  R$ $-334:493UU      *00:(sG)<)<==DDFF1   J("" 4<<>>**1133*,>?#        ('' j'II I I I I I I I I I$('' j'II I I I I I I I Is A/E..)FcK||d{V}g}|23d{V}|sn||!6|d{V|st|S)z? list will list all the objects in this store. )rN)rappendrr)r2rrentriesrs r&listzObjectStore.lists . AAAAAAAA" " " " " " " "%  NN5 ! ! ! ! # llnn  sA)F)NFrM)FFF)rrrr rr'rHrBrQr rGr r!rgrrrtr r#rrrrrrrrrrr$r%r&rr7s (((((((Y(Yd2020202020202020h    (-%%%tn%  %%%%T26', ???B-.?tn ?  ????J*. qqqC 112qs~& q  qqqqf/---*I*In*I*I*I*IX%%%%%%%%R --  ----^#J#J#J#J#J#JN cn r%r)-rwrZrr`re dataclassesrrrhashlibrtypingrrr r nats.errorsrnats.jsr nats.js.errorsr r rrrrr nats.js.kvrrcompileVALID_BUCKET_RE VALID_KEY_RErr]OBJ_ALL_CHUNKS_PRE_TEMPLATErrurXrrrrrr$r%r&rs !!!!!!''''''''777777777777<;;;;;;;"*011rz122 )(((((($/-/-#% 2wwwwwwwwwwr%