Skip to content

Commit

Permalink
Merge pull request #7 from JuliaComputing/tan/misc
Browse files Browse the repository at this point in the history
allow server opa command to be customized
  • Loading branch information
tanmaykm authored Oct 26, 2023
2 parents e36c957 + 2bc539c commit fcafcd2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OpenPolicyAgent"
uuid = "8f257efb-743c-4ebc-8197-d291a1f743b4"
authors = ["JuliaHub Inc.", "Tanmay Mohapatra <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
11 changes: 9 additions & 2 deletions src/server/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct MonitoredOPAServer
port::Int
stdout::Any
stderr::Any
cmdline::CommandLine
monitor_task::Ref{Union{Nothing, Task}}
server_proc::Ref{Union{Nothing, Process}}
stopped::Ref{Bool}
Expand All @@ -41,10 +42,17 @@ struct MonitoredOPAServer
port::Int = DEFAULT_PORT,
stdout = nothing,
stderr = nothing,
cmdline = nothing,
)
if isnothing(cmdline)
cmdline = CommandLine()
end
cmdline.runopts[:wait] = false

return new(configfile,
host, port,
stdout, stderr,
cmdline,
Ref{Union{Nothing, Task}}(nothing),
Ref{Union{Nothing, Process}}(nothing),
Ref{Bool}(true),
Expand All @@ -54,8 +62,7 @@ struct MonitoredOPAServer
end

function start_opa_server!(server::MonitoredOPAServer)
ctx = CommandLine()
ctx.runopts[:wait] = false
ctx = server.cmdline
if !isnothing(server.stdout)
ctx.pipelineopts[:stdout] = server.stdout
end
Expand Down
48 changes: 42 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,21 @@ function start_bundle_server(root_path)
return server
end

function start_opa_server(root_path)
opa_server = OpenPolicyAgent.Server.MonitoredOPAServer(
joinpath(root_path, "config.yaml"),
stdout = joinpath(root_path, "server.stdout"),
stderr = joinpath(root_path, "server.stderr"),
)
function start_opa_server(root_path; change_dir::Bool=true)
if change_dir
opa_server = OpenPolicyAgent.Server.MonitoredOPAServer(
joinpath(root_path, "config.yaml");
stdout = joinpath(root_path, "server.stdout"),
stderr = joinpath(root_path, "server.stderr"),
cmdline = OpenPolicyAgent.CLI.CommandLine(; cmdopts=Dict(:dir => root_path)),
)
else
opa_server = OpenPolicyAgent.Server.MonitoredOPAServer(
joinpath(root_path, "config.yaml");
stdout = joinpath(root_path, "server.stdout"),
stderr = joinpath(root_path, "server.stderr"),
)
end
OpenPolicyAgent.Server.start!(opa_server)
return opa_server
end
Expand Down Expand Up @@ -399,6 +408,33 @@ function runtests()
@info("Stopping OPA server")
OpenPolicyAgent.Server.stop!(opa_server)
end
sleep(5)
@test opa_server.stopped[]

# run again withoug changing the directory
@info("Starting OPA server without changing the directory")
opa_server = start_opa_server(opa_server_location; change_dir=false)
try
# Wait for servers to start
sleep(15)
@test !(opa_server.stopped[])
@test !isnothing(opa_server.monitor_task[])
@test !istaskdone(opa_server.monitor_task[])

# create the client
openapi_client = OpenAPI.Clients.Client("http://localhost:8181"; escape_path_params=false)
@testset "Status API" begin
test_status_api(openapi_client)
end
@testset "Health API" begin
test_health_api(openapi_client)
end
finally
@info("Stopping OPA server")
OpenPolicyAgent.Server.stop!(opa_server)
end
sleep(5)
@test opa_server.stopped[]
end
finally
@info("Stopping bundle server")
Expand Down

2 comments on commit fcafcd2

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94143

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" fcafcd25cdf8394d0dfcb3ba414468a1bbec5f1e
git push origin v0.1.1

Please sign in to comment.