Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-server
Commits
344b300e
Commit
344b300e
authored
1 week ago
by
Joscha Schmiedt
Browse files
Options
Downloads
Patches
Plain Diff
Add skeleton for ServerSideScriptingServiceImpl
parent
963e2f4f
No related branches found
No related tags found
1 merge request
!121
Draft: Add server side scripting to gRPC API
Pipeline
#62024
passed
1 week ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/caosdb/server/grpc/ServerSideScriptingServiceImpl.java
+123
-0
123 additions, 0 deletions
...rg/caosdb/server/grpc/ServerSideScriptingServiceImpl.java
with
123 additions
and
0 deletions
src/main/java/org/caosdb/server/grpc/ServerSideScriptingServiceImpl.java
0 → 100644
+
123
−
0
View file @
344b300e
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2025 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2025 Joscha Schmiedt <joscha@schmiedt.dev>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org.caosdb.server.grpc
;
import
com.google.protobuf.Timestamp
;
import
io.grpc.Status
;
import
io.grpc.StatusException
;
import
io.grpc.stub.StreamObserver
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.authz.UnauthorizedException
;
import
org.apache.shiro.subject.Subject
;
import
org.caosdb.api.scripting.v1alpha1.ExecuteServerSideScriptRequest
;
import
org.caosdb.api.scripting.v1alpha1.ExecuteServerSideScriptResponse
;
import
org.caosdb.api.scripting.v1alpha1.ServerSideScriptExecutionId
;
import
org.caosdb.api.scripting.v1alpha1.ServerSideScriptExecutionResult
;
import
org.caosdb.api.scripting.v1alpha1.ServerSideScriptingServiceGrpc.ServerSideScriptingServiceImplBase
;
import
org.caosdb.server.accessControl.AuthenticationUtils
;
import
org.caosdb.server.utils.ServerMessages
;
/**
* Main entry point for the server-side scripting service of the server's GRPC API.
*
* @author Joscha Schmiedt <joscha@schmiedt.dev>
*/
public
class
ServerSideScriptingServiceImpl
extends
ServerSideScriptingServiceImplBase
{
@Override
public
void
executeServerSideScript
(
ExecuteServerSideScriptRequest
request
,
io
.
grpc
.
stub
.
StreamObserver
<
org
.
caosdb
.
api
.
scripting
.
v1alpha1
.
ExecuteServerSideScriptResponse
>
responseObserver
)
{
// ServerSideScriptingCaller caller = new ServerSideScriptingCaller()
// caller.executeServerSideScript(request, responseObserver);
try
{
AuthInterceptor
.
bindSubject
();
ExecuteServerSideScriptResponse
response
=
executeScript
(
request
);
responseObserver
.
onNext
(
response
);
responseObserver
.
onCompleted
();
}
catch
(
final
Exception
e
)
{
ServerSideScriptingServiceImpl
.
handleException
(
responseObserver
,
e
);
}
}
private
ExecuteServerSideScriptResponse
executeScript
(
ExecuteServerSideScriptRequest
request
)
{
String
scriptExecutionId
=
""
;
String
scriptFilename
=
""
;
ServerSideScriptExecutionResult
result
=
ServerSideScriptExecutionResult
.
SERVER_SIDE_SCRIPT_EXECUTION_RESULT_GENERAL_FAILURE
;
int
returnCode
=
1
;
String
stdout
=
""
;
String
stderr
=
""
;
Timestamp
startTime
=
Timestamp
.
newBuilder
().
setSeconds
(
0
).
setNanos
(
0
).
build
();
Timestamp
endTime
=
Timestamp
.
newBuilder
().
setSeconds
(
0
).
setNanos
(
0
).
build
();
int
duration_ms
=
0
;
final
ExecuteServerSideScriptResponse
response
=
ExecuteServerSideScriptResponse
.
newBuilder
()
.
setScriptExecutionId
(
ServerSideScriptExecutionId
.
newBuilder
()
.
setScriptExecutionId
(
scriptExecutionId
)
.
build
())
.
setScriptFilename
(
scriptFilename
)
.
setResult
(
result
)
.
setReturnCode
(
returnCode
)
.
setStdout
(
stdout
)
.
setStderr
(
stderr
)
.
setStartTime
(
startTime
)
.
setEndTime
(
endTime
)
.
setDurationMs
(
duration_ms
)
.
build
();
return
response
;
}
public
static
void
handleException
(
StreamObserver
<?>
responseObserver
,
Exception
e
)
{
String
description
=
e
.
getMessage
();
if
(
description
==
null
||
description
.
isBlank
())
{
description
=
"Unknown Error. Please Report!"
;
}
if
(
e
instanceof
UnauthorizedException
)
{
Subject
subject
=
SecurityUtils
.
getSubject
();
if
(
AuthenticationUtils
.
isAnonymous
(
subject
))
{
responseObserver
.
onError
(
new
StatusException
(
AuthInterceptor
.
PLEASE_LOG_IN
));
return
;
}
else
{
responseObserver
.
onError
(
new
StatusException
(
Status
.
PERMISSION_DENIED
.
withCause
(
e
).
withDescription
(
description
)));
return
;
}
}
else
if
(
e
==
ServerMessages
.
ROLE_DOES_NOT_EXIST
||
e
==
ServerMessages
.
ACCOUNT_DOES_NOT_EXIST
)
{
responseObserver
.
onError
(
new
StatusException
(
Status
.
NOT_FOUND
.
withDescription
(
description
).
withCause
(
e
)));
return
;
}
// TODO: SERVER_SIDE_DOES_NOT_EXIST, SERVER_SIDE_SCRIPT_NOT_EXECUTABLE,
// SERVER_SIDE_SCRIPT_ERROR, SERVER_SIDE_SCRIPT_SETUP_ERROR,
// SERVER_SIDE_SCRIPT_TIMEOUT, SERVER_SIDE_SCRIPT_MISSING_CALL
e
.
printStackTrace
();
responseObserver
.
onError
(
new
StatusException
(
Status
.
UNKNOWN
.
withDescription
(
description
).
withCause
(
e
)));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment