Skip to content

Commit

Permalink
add json encode method for deployments and workloads
Browse files Browse the repository at this point in the history
Signed-off-by: mariobassem <[email protected]>
  • Loading branch information
MarioBassem committed Aug 23, 2023
1 parent 3554662 commit f55f213
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 3bot/zos/deployment.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module zos

import crypto.md5
import json

pub struct SignatureRequest {
pub mut:
Expand Down Expand Up @@ -132,3 +133,13 @@ pub fn (mut d Deployment) add_signature(twin u32, signature string) {
signature_type: 'sr25519'
}
}

pub fn (mut d Deployment) json_encode() !string {
mut encoded_workloads := []string{}
for mut w in d.workloads {
encoded_workloads << w.json_encode()!
}

workloads := '[${encoded_workloads.join(',')}]'
return '{"version":${d.version},"twin_id":${d.twin_id},"contract_id":${d.contract_id},"expiration":${d.expiration},"metadata":"${d.metadata}","description":"${d.description}","workloads":${workloads},"signature_requirement":${json.encode(d.signature_requirement)}}'
}
4 changes: 4 additions & 0 deletions 3bot/zos/workload.v
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub fn (mut workload Workload) challenge() string {
return out.join('')
}

pub fn (mut w Workload) json_encode() !string {
return '{"version":${w.version},"name":"${w.name}","type":"${w.type_}","data":${w.data},"metadata":"${w.metadata}","description":"${w.description}"}'
}

type WorkloadData = Zdb | Zmachine | Zmount | Znet
type WorkloadDataResult = ZdbResult | ZmachineResult | ZmountResult

Expand Down

0 comments on commit f55f213

Please sign in to comment.