diff --git a/examples/server/Brewfile b/examples/grpc-samples/Brewfile similarity index 100% rename from examples/server/Brewfile rename to examples/grpc-samples/Brewfile diff --git a/examples/grpc-samples/resolve-vars.json b/examples/grpc-samples/resolve-vars.json new file mode 100644 index 000000000..552d5b9d3 --- /dev/null +++ b/examples/grpc-samples/resolve-vars.json @@ -0,0 +1,6 @@ +{ + "script": "export NAME=\"Noname\"\nexport LICENSE=$(cat ../LICENSE)\necho \"LICENSE: $LICENSE\"", + "env": [ + "LICENSE=" + ] +} diff --git a/examples/PROJECTS.md b/examples/grpc-samples/services.md similarity index 54% rename from examples/PROJECTS.md rename to examples/grpc-samples/services.md index 21958aa0a..181c6fc14 100644 --- a/examples/PROJECTS.md +++ b/examples/grpc-samples/services.md @@ -4,9 +4,9 @@ runme: version: v2.2 --- -## gRPC runme.project.v1.ProjectService +## ProjectService -Flags matche the launcher arguments in .vscode/launch.json. +Flags match the launcher arguments in `.vscode/launch.json` for `Debug Server`. Be sure to complete [setup.md](setup.md). List available operations: @@ -39,3 +39,27 @@ $ grpcurl \ -d "{\"directory\":{\"path\":\".\"}}" \ 127.0.0.1:9999 runme.project.v1.ProjectService/Load ``` + +## RunnerService + +List all runner services. + +```sh {"id":"01HNGQNYYWKP635FT8GHE67476","promptEnv":"false"} +export VERSION="v1" # there's also v2alpha1 +$ grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ + 127.0.0.1:9999 list runme.runner.$VERSION.RunnerService +``` + +Resolve variables inside cell: + +```sh {"id":"01HNGQS6TV8YKQAKE0ZD7TZREH","promptEnv":"false","terminalRows":"15"} +$ grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ + -d @ \ + 127.0.0.1:9999 runme.runner.v1.RunnerService/ResolveVars < resolve-vars.json +``` diff --git a/examples/grpc-samples/setup.md b/examples/grpc-samples/setup.md new file mode 100644 index 000000000..55fd35e78 --- /dev/null +++ b/examples/grpc-samples/setup.md @@ -0,0 +1,34 @@ +--- +runme: + id: 01HF7BT3HBDTRGQAQMH51RDQEC + version: v2.2 +--- + +# GRPC Setup + +Install system dependencies: + +```sh {"id":"01HF7BT3HBDTRGQAQMGTJN1KP3"} +$ brew bundle --no-lock +``` + +## Exercise GRPC interface + +Issue a simple call to the deserialize API, first set markdown input data: + +```sh {"id":"01HF7BT3HBDTRGQAQMH0ZYTWA9"} +export MD="# Ohai this is my cool headline" +``` + +Then issue RPC call and display the result: + +```sh {"closeTerminalOnSuccess":"false","id":"01HF7BT3HBDTRGQAQMH2K85BHG","terminalRows":"15"} +$ data="$(echo $MD | openssl base64 | tr -d '\n')" +$ cd ../.. && grpcurl \ + -cacert /tmp/runme/tls/cert.pem \ + -cert /tmp/runme/tls/cert.pem \ + -key /tmp/runme/tls/key.pem \ + -protoset <(buf build -o -) \ + -d "{\"source\": \"$data\"}" \ + 127.0.0.1:9999 runme.parser.v1.ParserService/Deserialize +``` diff --git a/examples/server/grpc.md b/examples/server/grpc.md deleted file mode 100644 index 4350ed799..000000000 --- a/examples/server/grpc.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -runme: - id: 01HF7BT3HBDTRGQAQMH51RDQEC - version: v2.2 ---- - -# Daemon/kernel functionality - -Install system dependencies: - -```sh {"id":"01HF7BT3HBDTRGQAQMGTJN1KP3"} -$ brew bundle --no-lock -``` - -Let's build the project first and include working directory into `$PATH`: - -```sh {"id":"01HF7BT3HBDTRGQAQMGVG57QBE"} -$ cd ../.. -$ make -$ export CWD=$(cd ../.. && pwd | tr -d '\n') -$ export PATH="$CWD:$PATH" -``` - -## Exercise GRPC interface - -Bring up the server. It's gRPC based: - -```sh {"background":"true","id":"01HF7BT3HBDTRGQAQMGXCKJCAB"} -$ ../../runme server --address /tmp/runme.sock -``` - -Issue a simple call to the deserialize API, first set markdown input data: - -```sh {"id":"01HF7BT3HBDTRGQAQMH0ZYTWA9"} -export mddata="# Ohai this is my cool headline" -``` - -Then issue RPC call and display the result: - -```sh {"closeTerminalOnSuccess":"false","id":"01HF7BT3HBDTRGQAQMH2K85BHG"} -$ data="$(echo $mddata | openssl base64 | tr -d '\n')" -$ cd ../.. && grpcurl \ - -protoset <(buf build -o -) \ - -d "{\"source\": \"$data\"}" \ - -plaintext \ - -unix /tmp/runme.sock \ - runme.parser.v1.ParserService/Deserialize -``` diff --git a/internal/document/editor/editorservice/service.go b/internal/document/editor/editorservice/service.go index 6f45d2ac6..d8299f9f7 100644 --- a/internal/document/editor/editorservice/service.go +++ b/internal/document/editor/editorservice/service.go @@ -26,7 +26,7 @@ func NewParserServiceServer(logger *zap.Logger) parserv1.ParserServiceServer { func (s *parserServiceServer) Deserialize(_ context.Context, req *parserv1.DeserializeRequest) (*parserv1.DeserializeResponse, error) { s.logger.Info("Deserialize", zap.ByteString("source", req.Source[:min(len(req.Source), 64)])) - identityResolver := identity.NewResolver(fromProtoRunmeIdentityToLifecycleIdentity(req.Options.Identity)) + identityResolver := identity.NewResolver(fromProtoDeserializeReqOptionsToLifecycleIdentity(req.Options)) notebook, err := editor.Deserialize(req.Source, identityResolver) if err != nil { s.logger.Info("failed to call Deserialize", zap.Error(err)) @@ -237,7 +237,13 @@ func (*parserServiceServer) serializeCellOutputs(cell *parserv1.Cell, options *p return outputs } -func fromProtoRunmeIdentityToLifecycleIdentity(idt parserv1.RunmeIdentity) identity.LifecycleIdentity { +func fromProtoDeserializeReqOptionsToLifecycleIdentity(opt *parserv1.DeserializeRequestOptions) identity.LifecycleIdentity { + var idt parserv1.RunmeIdentity + + if opt != nil { + idt = opt.Identity + } + switch idt { case parserv1.RunmeIdentity_RUNME_IDENTITY_ALL: return identity.AllLifecycleIdentity @@ -245,7 +251,9 @@ func fromProtoRunmeIdentityToLifecycleIdentity(idt parserv1.RunmeIdentity) ident return identity.DocumentLifecycleIdentity case parserv1.RunmeIdentity_RUNME_IDENTITY_CELL: return identity.CellLifecycleIdentity - default: + case parserv1.RunmeIdentity_RUNME_IDENTITY_UNSPECIFIED: return identity.UnspecifiedLifecycleIdentity + default: + return identity.DefaultLifecycleIdentity } }