Skip to content

Commit 96b28f4

Browse files
authored
Merge pull request #183 from ChevronETC/jwts
switch from jsonwebtokens to jwts, allowing us to update json
2 parents 0c6f8fd + de5e8ff commit 96b28f4

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

Project.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AzManagers"
22
uuid = "db05ebb0-6096-11e9-199b-87b703361841"
33
authors = ["samtkaplan <[email protected]>"]
4-
version = "3.17.1"
4+
version = "3.17.2"
55

66
[deps]
77
AzSessions = "f239b30d-ae6b-58be-a2d5-7e9f30e280a9"
@@ -11,7 +11,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1111
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1212
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1313
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
14-
JSONWebTokens = "9b8beb19-0777-58c6-920b-28f749fee4d3"
14+
JWTs = "d850fbd6-035d-5a70-a269-1ca2e636ac6c"
1515
LibCURL = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
1616
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
1717
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
@@ -26,19 +26,19 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
2626
[weakdeps]
2727
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
2828

29-
[extras]
30-
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
31-
3229
[extensions]
3330
MPIExt = "MPI"
3431

3532
[compat]
3633
AzSessions = "2"
3734
CodecZlib = "0.7"
3835
HTTP = "1"
39-
JSON = "0.21"
40-
JSONWebTokens = "1"
41-
LibCURL = "0.6"
36+
JSON = "0.21, 1"
37+
JWTs = "0.3"
38+
LibCURL = "0.6, 1"
4239
MPI = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
4340
TOML = "1"
4441
julia = "^1.4"
42+
43+
[extras]
44+
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"

src/AzManagers.jl

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module AzManagers
22

3-
using AzSessions, Base64, CodecZlib, Dates, Distributed, HTTP, JSON, JSONWebTokens, LibCURL, LibGit2, Logging, Pkg, Printf, Random, Serialization, Sockets, TOML
3+
using AzSessions, Base64, CodecZlib, Dates, Distributed, HTTP, JSON, JWTs, LibCURL, LibGit2, Logging, Pkg, Printf, Random, Serialization, Sockets, TOML
44

55
function logerror(e, loglevel=Logging.Info)
66
io = IOBuffer()
@@ -37,7 +37,7 @@ function write_manifest(;
3737
manifest = Dict("resourcegroup"=>resourcegroup, "subscriptionid"=>subscriptionid, "ssh_user"=>ssh_user, "ssh_private_key_file"=>ssh_private_key_file, "ssh_public_key_file"=>ssh_public_key_file)
3838
try
3939
isdir(manifestpath()) || mkdir(manifestpath(); mode=0o700)
40-
write(manifestfile(), json(manifest, 1))
40+
write(manifestfile(), JSON.json(manifest, 1))
4141
chmod(manifestfile(), 0o600)
4242
catch e
4343
@error "Failed to write manifest file, $(AzManagers.manifestfile())"
@@ -866,7 +866,7 @@ end
866866
function Distributed.addprocs(template::AbstractString, n::Int; kwargs...)
867867
isfile(templates_filename_scaleset()) || error("scale-set template file does not exist. See `AzManagers.save_template_scaleset`")
868868

869-
templates_scaleset = JSON.parse(read(templates_filename_scaleset(), String))
869+
templates_scaleset = JSON.parse(read(templates_filename_scaleset(), String); dicttype=Dict)
870870
haskey(templates_scaleset, template) || error("scale-set template file does not contain a template with name: $template. See `AzManagers.save_template_scaleset`")
871871

872872
addprocs(templates_scaleset[template], n; kwargs...)
@@ -1313,7 +1313,7 @@ function azure_worker_init(cookie, master_address, master_port, ppi, exeflags, m
13131313
"mpi_size" => mpi_size,
13141314
"physical_hostname" => azure_physical_name()))
13151315

1316-
_vm = base64encode(json(vm))
1316+
_vm = base64encode(JSON.json(vm))
13171317

13181318
nbytes_written = write(c, _vm*"\n")
13191319
nbytes_written == length(_vm)+1 || error("wrote wrong number of bytes")
@@ -2235,7 +2235,7 @@ function resourcegraphrequest(manager, body)
22352235
manager.verbose,
22362236
"https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01",
22372237
["Authorization"=>"Bearer $(token(manager.session))", "Content-Type"=>"application/json"],
2238-
json(body)
2238+
JSON.json(body)
22392239
)
22402240
r = JSON.parse(String(_r.body))
22412241
data = [data;get(r, "data", [])]
@@ -2345,7 +2345,7 @@ function scaleset_capacity!(manager::AzManager, subscriptionid, resourcegroup, s
23452345
verbose,
23462346
"https://management.azure.com/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname?api-version=2023-03-01",
23472347
["Authorization"=>"Bearer $(token(manager.session))", "Content-Type"=>"application/json"],
2348-
json(Dict("sku"=>Dict("capacity"=>capacity))))
2348+
JSON.json(Dict("sku"=>Dict("capacity"=>capacity))))
23492349
end
23502350

23512351
function scaleset_create_or_update(manager::AzManager, user, subscriptionid, resourcegroup, scalesetname, sigimagename, sigimageversion,
@@ -2373,8 +2373,7 @@ function scaleset_create_or_update(manager::AzManager, user, subscriptionid, res
23732373
_template["properties"]["virtualMachineProfile"]["storageProfile"]["osDisk"]["diskSizeGB"] = osdisksize
23742374

23752375
_t = token(manager.session)
2376-
_e = JSONWebTokens.None()
2377-
_decoded = JSONWebTokens.decode(_e, _t)
2376+
_decoded = claims(JWT(;jwt=_t))
23782377
if haskey(_decoded, "unique_name")
23792378
_user = _decoded["unique_name"]
23802379

@@ -2469,7 +2468,7 @@ function scaleset_create_or_update(manager::AzManager, user, subscriptionid, res
24692468
verbose,
24702469
"https://management.azure.com/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname?api-version=2023-03-01",
24712470
["Content-type"=>"application/json", "Authorization"=>"Bearer $(token(manager.session))"],
2472-
String(json(_template)))
2471+
String(JSON.json(_template)))
24732472

24742473
if manager.show_quota
24752474
@info "Quota after requesting that the scale-set is created or grows" remaining_resource(_r)
@@ -2485,7 +2484,7 @@ function delete_vms(manager::AzManager, subscriptionid, resourcegroup, scalesetn
24852484
verbose,
24862485
"https://management.azure.com/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname/delete?forceDeletion=True&api-version=2023-07-01",
24872486
["Content-Type"=>"application/json", "Authorization"=>"Bearer $(token(manager.session))"],
2488-
json(body))
2487+
JSON.json(body))
24892488

24902489
if manager.show_quota
24912490
@info "Quota after requesting deletion of $(length(ids)) virtual machines" remaining_resource(_r)
@@ -2627,7 +2626,7 @@ function detachedrun(request::HTTP.Request)
26272626
r = JSON.parse(String(HTTP.payload(request)))
26282627

26292628
if !haskey(r, "code")
2630-
return HTTP.Response(400, ["Content-Type"=>"application/json"], json(Dict("error"=>"Malformed body: JSON body must contain the key: code")); request)
2629+
return HTTP.Response(400, ["Content-Type"=>"application/json"], JSON.json(Dict("error"=>"Malformed body: JSON body must contain the key: code")); request)
26312630
end
26322631

26332632
exename = get(r, "exename", "julia")
@@ -2652,7 +2651,7 @@ function detachedrun(request::HTTP.Request)
26522651
end
26532652
end
26542653
if length(codelines) == 0
2655-
return HTTP.Response(400, ["Content-Type"=>"application/json"], json(Dict("error"=>"No code to execute, missing end?", "code"=>code)); request)
2654+
return HTTP.Response(400, ["Content-Type"=>"application/json"], JSON.json(Dict("error"=>"No code to execute, missing end?", "code"=>code)); request)
26562655
end
26572656

26582657
code = join(codelines, "\n")
@@ -2712,7 +2711,7 @@ function detachedrun(request::HTTP.Request)
27122711
catch e
27132712
io = IOBuffer()
27142713
logerror(e, Logging.Warn)
2715-
return HTTP.Response(500, ["Content-Type"=>"application/json"], json(Dict("error"=>String(take!(io)))); request)
2714+
return HTTP.Response(500, ["Content-Type"=>"application/json"], JSON.json(Dict("error"=>String(take!(io)))); request)
27162715
end
27172716

27182717
Threads.@spawn begin
@@ -2725,7 +2724,7 @@ function detachedrun(request::HTTP.Request)
27252724
rmproc(vm; session=sessionbundle(:management))
27262725
end
27272726
end
2728-
HTTP.Response(200, ["Content-Type"=>"application/json"], json(Dict("id"=>id, "pid"=>pid)); request)
2727+
HTTP.Response(200, ["Content-Type"=>"application/json"], JSON.json(Dict("id"=>id, "pid"=>pid)); request)
27292728
end
27302729

27312730
function detachedkill(request::HTTP.Request)
@@ -2778,9 +2777,9 @@ function detachedstatus(request::HTTP.Request)
27782777
status = "starting"
27792778
end
27802779
catch e
2781-
return HTTP.Response(500, ["Content-Type"=>"application/json"], json(Dict("error"=>show(e), "trace"=>show(stacktrace()))); request)
2780+
return HTTP.Response(500, ["Content-Type"=>"application/json"], JSON.json(Dict("error"=>show(e), "trace"=>show(stacktrace()))); request)
27822781
end
2783-
HTTP.Response(200, ["Content-Type"=>"application/json"], json(Dict("id"=>id, "status"=>status)); request)
2782+
HTTP.Response(200, ["Content-Type"=>"application/json"], JSON.json(Dict("id"=>id, "status"=>status)); request)
27842783
end
27852784

27862785
function detachedstdout(request::HTTP.Request)
@@ -2857,7 +2856,7 @@ function detachedwait(request::HTTP.Request)
28572856
end
28582857
write(io, "\n")
28592858

2860-
return HTTP.Response(400, ["Content-Type"=>"application/json"], json(Dict("error"=>String(take!(io)))); request)
2859+
return HTTP.Response(400, ["Content-Type"=>"application/json"], JSON.json(Dict("error"=>String(take!(io)))); request)
28612860
end
28622861
HTTP.Response(200, ["Content-Type"=>"application/text"], "OK, job $id is finished"; request)
28632862
end
@@ -2867,7 +2866,7 @@ function detachedping(request::HTTP.Request)
28672866
end
28682867

28692868
function detachedvminfo(request::HTTP.Request)
2870-
HTTP.Response(200, ["Content-Type"=>"application/json"], json(AzManagers.DETACHED_VM[]); request)
2869+
HTTP.Response(200, ["Content-Type"=>"application/json"], JSON.json(AzManagers.DETACHED_VM[]); request)
28712870
end
28722871

28732872
#
@@ -2974,7 +2973,7 @@ function addproc(vm_template::Dict, nic_template=nothing;
29742973
verbose,
29752974
"https://management.azure.com/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.Network/networkInterfaces/$nicname?api-version=2022-09-01",
29762975
["Content-Type"=>"application/json", "Authorization"=>"Bearer $(token(session))"],
2977-
String(json(nic_template)))
2976+
String(JSON.json(nic_template)))
29782977

29792978
sleep(5)
29802979

@@ -3077,7 +3076,7 @@ function addproc(vm_template::Dict, nic_template=nothing;
30773076
verbose,
30783077
"https://management.azure.com/subscriptions/$subscriptionid/resourceGroups/$resourcegroup/providers/Microsoft.Compute/virtualMachines/$vmname?api-version=2023-09-01",
30793078
["Content-Type"=>"application/json", "Authorization"=>"Bearer $(token(session))"],
3080-
String(json(vm_template["value"])))
3079+
String(JSON.json(vm_template["value"])))
30813080

30823081
spincount = 1
30833082
starttime = tic = time()
@@ -3137,7 +3136,7 @@ end
31373136

31383137
function addproc(vm_template::AbstractString, nic_template=nothing; kwargs...)
31393138
isfile(templates_filename_vm()) || error("if vm_template is a string, then the file $(templates_filename_vm()) must exist. See AzManagers.save_template_vm.")
3140-
vm_templates = JSON.parse(read(templates_filename_vm(), String))
3139+
vm_templates = JSON.parse(read(templates_filename_vm(), String); dicttype=Dict)
31413140
vm_template = vm_templates[vm_template]
31423141

31433142
addproc(vm_template, nic_template; kwargs...)
@@ -3398,7 +3397,7 @@ function detached_run(code, ip::String="", port=detached_port();
33983397
"POST",
33993398
"http://$(vm["ip"]):$(vm["port"])/cofii/detached/run",
34003399
["Content-Type"=>"application/json"],
3401-
json(body))
3400+
JSON.json(body))
34023401
r = JSON.parse(String(_r.body))
34033402

34043403
@info "detached job id is $(r["id"]) at $(vm["name"]),$(vm["ip"]):$(vm["port"])"

src/templates.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function save_template(templates_filename::AbstractString, name::AbstractString,
66
if !ispath(templates_folder())
77
mkdir(templates_folder())
88
end
9-
write(templates_filename, json(templates, 1))
9+
write(templates_filename, JSON.json(templates, 1))
1010
nothing
1111
end
1212

0 commit comments

Comments
 (0)