code stringlengths 25 201k | docstring stringlengths 19 96.2k | func_name stringlengths 0 235 | language stringclasses 1 value | repo stringlengths 8 51 | path stringlengths 11 314 | url stringlengths 62 377 | license stringclasses 7 values |
|---|---|---|---|---|---|---|---|
private void closeConnection(Session session, GuacamoleStatus guacStatus) {
closeConnection(session, guacStatus.getGuacamoleStatusCode(),
guacStatus.getWebSocketCode());
} | Sends the given Guacaomle Status and closes the given
connection.
@param session
The outbound WebSocket connection to close.
@param guacStatus
The status to use for the connection. | closeConnection | java | ixrjog/opscloud4 | opscloud-guacamole/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-guacamole/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java | Apache-2.0 |
protected int calendarValueGet(int field) {
Calendar calendar = Calendar.getInstance();
return calendar.get(field);
} | the value for the given calendar field.
@param field
@return | calendarValueGet | java | ixrjog/opscloud4 | opscloud-leo/src/main/java/com/baiyi/opscloud/leo/interceptor/rule/BaseLeoRuleExpression.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-leo/src/main/java/com/baiyi/opscloud/leo/interceptor/rule/BaseLeoRuleExpression.java | Apache-2.0 |
@Override
protected GuacamoleTunnel createTunnel(Session session, EndpointConfig endpointConfig) throws GuacamoleException {
Map<String, List<String>> parameterMap = session.getRequestParameterMap();
String token = getGuacamoleParam(parameterMap, "token");
SimpleLoginMessage simpleLogin = SimpleLoginMessage.builder()
.token(token)
.build();
String username = simpleAuthentication.hasLogin(simpleLogin);
return super.createTunnel(session, endpointConfig);
} | @param session
@param endpointConfig
@return
@throws GuacamoleException | createTunnel | java | ixrjog/opscloud4 | opscloud-manage/src/main/java/com/baiyi/opscloud/controller/socket/GuacamoleController.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-manage/src/main/java/com/baiyi/opscloud/controller/socket/GuacamoleController.java | Apache-2.0 |
protected HttpResult<Boolean> notify(ApolloConfig apolloConfig, ApolloParam.ReleaseEvent releaseEvent, Integer ticketId) {
Application application = applicationService.getByName(releaseEvent.getAppId());
apolloReleaseMessenger.notify(apolloConfig, releaseEvent, ticketId, application);
return HttpResult.SUCCESS;
} | Notify and Result
@param apolloConfig
@param releaseEvent
@param ticketId
@return | notify | java | ixrjog/opscloud4 | opscloud-manage/src/main/java/com/baiyi/opscloud/facade/apollo/handler/BaseApolloReleaseChainHandler.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-manage/src/main/java/com/baiyi/opscloud/facade/apollo/handler/BaseApolloReleaseChainHandler.java | Apache-2.0 |
protected HttpResult<Boolean> notify(ApolloConfig apolloConfig, ApolloParam.ReleaseEvent releaseEvent) {
this.notify(apolloConfig, releaseEvent, NO_WORK_ORDER_ID);
return HttpResult.SUCCESS;
} | Notify and Result
@param apolloConfig
@param releaseEvent
@return | notify | java | ixrjog/opscloud4 | opscloud-manage/src/main/java/com/baiyi/opscloud/facade/apollo/handler/BaseApolloReleaseChainHandler.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-manage/src/main/java/com/baiyi/opscloud/facade/apollo/handler/BaseApolloReleaseChainHandler.java | Apache-2.0 |
@Test
void finOpsTagResourcesTest() {
final String regionId = "eu-central-1";
AliyunConfig config = getConfigById(1);
List<DescribeInstancesResponse.Instance> instanceList = aliyunEcsDriver.listInstances(regionId, config.getAliyun());
for (DescribeInstancesResponse.Instance instance : instanceList) {
List<DescribeInstancesResponse.Instance.Tag> tags = instance.getTags();
if (CollectionUtils.isEmpty(tags)) {
continue;
}
Optional<DescribeInstancesResponse.Instance.Tag> optionalTag = tags.stream().filter(t -> t.getTagKey().equals("FIN")).findFirst();
if (optionalTag.isPresent()) {
final String tagValue = optionalTag.get().getTagValue();
List<DescribeDisksResponse.Disk> disks = aliyunEcsDriver.describeDisks(instance.getRegionId(), config.getAliyun(), instance.getInstanceId());
// print(disks);
if (!CollectionUtils.isEmpty(disks)) {
List<String> resourceIds = disks.stream().map(DescribeDisksResponse.Disk::getDiskId).toList();
TagResourcesRequest.Tag tag = new TagResourcesRequest.Tag();
tag.setKey("FIN");
tag.setValue(tagValue);
aliyunTagDriver.tagResources(instance.getRegionId(), config.getAliyun(), "disk", resourceIds, Lists.newArrayList(tag));
}
}
}
} | - eu-west-1
- eu-central-1
- cn-hangzhou
- cn-shenzhen
- cn-hongkong | finOpsTagResourcesTest | java | ixrjog/opscloud4 | opscloud-manage/src/test/java/com/baiyi/opscloud/datasource/aliyun/AliyunEcsTest.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-manage/src/test/java/com/baiyi/opscloud/datasource/aliyun/AliyunEcsTest.java | Apache-2.0 |
@Override
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
} | enforce that this class is a singleton
@return
@throws CloneNotSupportedException | clone | java | ixrjog/opscloud4 | opscloud-otp/src/main/java/com/baiyi/opscloud/otp/Base32StringUtil.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-otp/src/main/java/com/baiyi/opscloud/otp/Base32StringUtil.java | Apache-2.0 |
@Override
public void run() {
try {
while (session.isOpen()) {
List<SessionOutput> outputList = SessionOutputUtil.getOutput(sessionId);
if (CollectionUtils.isNotEmpty(outputList)) {
String jsonStr = JSONUtil.writeValueAsString(outputList);
session.getBasicRemote().sendText(jsonStr);
}
NewTimeUtil.millisecondsSleep(25L);
}
} catch (IOException ignored) {
}
} | class to send output to web socket client
@author liangjian | run | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/task/terminal/SentOutputTask.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/task/terminal/SentOutputTask.java | Apache-2.0 |
@Override
public void write(char[] buf, int off, int len) {
SessionOutputUtil.addToOutput(getSessionOutput().getSessionId(), getSessionOutput().getInstanceId(), buf, off, len);
} | Task to watch for output read from the ssh session stream
@author liangjian | write | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/task/terminal/WatchServerTerminalOutputTask.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/task/terminal/WatchServerTerminalOutputTask.java | Apache-2.0 |
public static void removeUserSession(String sessionId) {
UserSessionsOutput userSessionsOutput = USER_SESSIONS_OUTPUT_MAP.get(sessionId);
if (userSessionsOutput != null) {
userSessionsOutput.getSessionOutputMap().clear();
}
USER_SESSIONS_OUTPUT_MAP.remove(sessionId);
} | removes session for user session
@param sessionId session id | removeUserSession | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | Apache-2.0 |
public static void removeOutput(String sessionId, String instanceId) {
UserSessionsOutput userSessionsOutput = USER_SESSIONS_OUTPUT_MAP.get(sessionId);
if (userSessionsOutput != null) {
userSessionsOutput.getSessionOutputMap().remove(instanceId);
}
} | removes session output for host system
@param sessionId session id
@param instanceId id of host system instance | removeOutput | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | Apache-2.0 |
public static void addOutput(SessionOutput sessionOutput) {
UserSessionsOutput userSessionsOutput = USER_SESSIONS_OUTPUT_MAP.get(sessionOutput.getSessionId());
if (userSessionsOutput == null) {
USER_SESSIONS_OUTPUT_MAP.put(sessionOutput.getSessionId(), new UserSessionsOutput());
userSessionsOutput = USER_SESSIONS_OUTPUT_MAP.get(sessionOutput.getSessionId());
}
userSessionsOutput.getSessionOutputMap().put(sessionOutput.getInstanceId(), sessionOutput);
} | adds a new output
@param sessionOutput session output object | addOutput | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | Apache-2.0 |
public static List<SessionOutput> getOutput(String sessionId) {
List<SessionOutput> outputList = Lists.newArrayList();
UserSessionsOutput userSessionsOutput = USER_SESSIONS_OUTPUT_MAP.get(sessionId);
if (userSessionsOutput != null) {
userSessionsOutput.getSessionOutputMap().keySet().forEach(instanceId -> {
//get output chars and set to output
try {
SessionOutput sessionOutput = userSessionsOutput.getSessionOutputMap().get(instanceId);
if (sessionOutput != null && sessionOutput.getOutput() != null
&& StringUtils.isNotEmpty(sessionOutput.getOutput())) {
outputList.add(sessionOutput);
userSessionsOutput.getSessionOutputMap().put(instanceId, new SessionOutput(sessionId, sessionOutput));
}
} catch (Exception ex) {
log.error(ex.toString(), ex);
}
});
}
return outputList;
} | returns list of output lines
@param sessionId session id object
@return session output list | getOutput | java | ixrjog/opscloud4 | opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-core/src/main/java/com/baiyi/opscloud/sshcore/util/SessionOutputUtil.java | Apache-2.0 |
private static List<String> sanitizeInput(List<String> words) {
words = words.stream()
// CR at beginning/end of line introduced by backslash continuation
.map(s -> s.replaceAll("^\\n+|\\n+$", ""))
// CR in middle of word introduced by return inside a quoted string
.map(s -> s.replaceAll("\\n+", " "))
.collect(Collectors.toList());
return words;
} | Sanitize the buffer input given the customizations applied to the JLine parser (<em>e.g.</em> support for
line continuations, <em>etc.</em>)
See @{@link CompleterAutoConfiguration} | sanitizeInput | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/ExtendedCompleterAdapter.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/ExtendedCompleterAdapter.java | Apache-2.0 |
@Override
public void run(InputProvider inputProvider) {
run(inputProvider, () -> false);
} | Extended shell to handle post processors
@param resultHandlerService result handler service
@param commandRegistry command registry
@param terminal terminal
@param shellContext shell context
@param exitCodeMappings exit code mappipngs
@param postProcessors post processors | run | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/ExtendedShell.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/ExtendedShell.java | Apache-2.0 |
public boolean isLocalPrompt() {
return sshShellRunnable == null;
} | Check if current prompt is the one started with application
@return if local prompt or not | isLocalPrompt | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | Apache-2.0 |
public ServerSession getSshSession() {
return isLocalPrompt() ? null : sshShellRunnable.getSshSession();
} | Return current ssh session
@return ssh session, or null of is local prompt | getSshSession | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | Apache-2.0 |
public Environment getSshEnv() {
return isLocalPrompt() ? null : sshShellRunnable.getSshEnv();
} | Return current ssh env
@return ssh env, or null of is local prompt | getSshEnv | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshContext.java | Apache-2.0 |
@Bean
@ConditionalOnMissingBean
public PromptProvider sshPromptProvider() {
return () -> new AttributedString(properties.getPrompt().getText(),
AttributedStyle.DEFAULT.foreground(properties.getPrompt().getColor().toJlineAttributedStyle()));
} | Primary prompt provider
@return prompt provider | sshPromptProvider | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellAutoConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellAutoConfiguration.java | Apache-2.0 |
@Bean
public SshShellListenerService sshShellListenerService(@Autowired(required = false) List<SshShellListener> listeners) {
return new SshShellListenerService(listeners);
} | Creates ssh listener service
@param listeners found listeners in context
@return listener service | sshShellListenerService | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellAutoConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellAutoConfiguration.java | Apache-2.0 |
public Map<Long, ChannelSession> listSessions() {
return threads.keySet().stream()
.collect(Collectors.toMap(s -> s.getServerSession().getIoSession().getId(), Function.identity()));
} | List current sessions
@return current sessions | listSessions | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellCommandFactory.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellCommandFactory.java | Apache-2.0 |
@Bean
public SshServerLifecycle sshServerLifecycle(SshServer sshServer) {
return new SshServerLifecycle(sshServer, this.properties);
} | Create the bean responsible for starting and stopping the SSH server
@param sshServer the ssh server to manage
@return ssh server lifecycle | sshServerLifecycle | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | Apache-2.0 |
@PostConstruct
public void startServer() throws IOException {
sshServer.start();
log.info("Ssh server started [{}:{}]", properties.getHost(), properties.getPort());
} | Start ssh server
@throws IOException in case of error | startServer | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | Apache-2.0 |
@PreDestroy
public void stopServer() throws IOException {
sshServer.stop();
} | Stop ssh server
@throws IOException in case of error | stopServer | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellConfiguration.java | Apache-2.0 |
public boolean confirm(String message, String... confirmWords) {
return confirm(message, false, confirmWords);
} | @param message confirmation message
@param confirmWords (optional) confirmation words, default are {@link SshShellHelper#DEFAULT_CONFIRM_WORDS},
or configured in {@link SshShellProperties}
@return whether it has been confirmed | confirm | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public boolean confirm(String message, boolean caseSensitive, String... confirmWords) {
String response = read(message);
List<String> confirm = this.confirmWords;
if (confirmWords != null && confirmWords.length > 0) {
confirm = Arrays.asList(confirmWords);
}
for (String c : confirm) {
if (caseSensitive && c.equals(response)) {
return true;
} else if (!caseSensitive && c.equalsIgnoreCase(response)) {
return true;
}
}
return false;
} | @param message confirmation message
@param caseSensitive should be case sensitive or not
@param confirmWords (optional) confirmation words, default are {@link SshShellHelper#DEFAULT_CONFIRM_WORDS},
or configured in {@link SshShellProperties}
@return whether it has been confirmed | confirm | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String read() {
return read(null);
} | Read from terminal
@return response read from terminal | read | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String read(String message) {
LineReader lr = reader();
if (message != null) {
lr.getTerminal().writer().println(message);
}
lr.readLine();
if (lr.getTerminal() instanceof AbstractPosixTerminal) {
lr.getTerminal().writer().println();
}
return lr.getParsedLine().line();
} | Print confirmation message and get response
@param message message to print
@return response read from terminal | read | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String getSuccess(String message) {
return getColored(message, PromptColor.GREEN);
} | Color message with color {@link PromptColor#GREEN}
@param message message to return
@return colored message | getSuccess | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String getInfo(String message) {
return getColored(message, PromptColor.CYAN);
} | Color message with color {@link PromptColor#CYAN}
@param message message to return
@return colored message | getInfo | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String getWarning(String message) {
return getColored(message, PromptColor.YELLOW);
} | Color message with color {@link PromptColor#YELLOW}
@param message message to return
@return colored message | getWarning | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String getError(String message) {
return getColored(message, PromptColor.RED);
} | Color message with color {@link PromptColor#RED}
@param message message to return
@return colored message | getError | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void printSuccess(String message) {
print(message, PromptColor.GREEN);
} | Print message with color {@link PromptColor#GREEN}
@param message message to print | printSuccess | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void printInfo(String message) {
print(message, PromptColor.CYAN);
} | Print message with color {@link PromptColor#CYAN}
@param message message to print | printInfo | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void printWarning(String message) {
print(message, PromptColor.YELLOW);
} | Print message with color {@link PromptColor#YELLOW}
@param message message to print | printWarning | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void printError(String message) {
print(message, PromptColor.RED);
} | Print message with color {@link PromptColor#RED}
@param message message to print | printError | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void print(String message) {
print(message, null);
} | Print in the console
@param message message to print | print | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public void print(String message, PromptColor color) {
String toPrint = message;
if (color != null) {
toPrint = getColored(message, color);
}
terminal().writer().println(toPrint);
} | Print in the console
@param message message to print
@param color (optional) prompt color | print | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String renderTable(SimpleTable simpleTable) {
return renderTable(buildTable(simpleTable));
} | Renders table in current terminal
@param simpleTable simple table
@return table as string | renderTable | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String renderTable(Table table) {
return table.render(terminalSize().getColumns());
} | Renders table in current terminal
@param table built table
@return table as string | renderTable | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public Table buildTable(SimpleTable simpleTable) {
int nbColumns = simpleTable.getColumns().size();
if (nbColumns == 0) {
throw new IllegalArgumentException("Table should have at least one column");
}
int nbLines = simpleTable.getLines().size();
if (simpleTable.isDisplayHeaders()) {
nbLines++;
}
String[][] data = new String[nbLines][simpleTable.getColumns().size()];
TableModel model = new ArrayTableModel(data);
TableBuilder tableBuilder = new TableBuilder(model);
int i = 0;
if (simpleTable.isDisplayHeaders()) {
// let first line for headers
i = 1;
int c = 0;
if (simpleTable.getHeaderAligners() == null || simpleTable.getHeaderAligners().isEmpty()) {
simpleTable.setHeaderAligners(DEFAULT_ALIGNERS);
}
for (String header : simpleTable.getColumns()) {
data[0][c] = header;
for (Aligner headerAligner : simpleTable.getHeaderAligners()) {
tableBuilder.on(at(0, c)).addAligner(headerAligner);
}
c++;
}
}
if (simpleTable.getLineAligners() == null || simpleTable.getLineAligners().isEmpty()) {
simpleTable.setLineAligners(DEFAULT_ALIGNERS);
}
for (List<Object> line : simpleTable.getLines()) {
int c = 0;
for (Object objValue : line) {
// ensure we don't have more column in line than in column names
if (c >= nbColumns) {
break;
}
String value = "";
if (objValue != null) {
if (objValue instanceof String) {
value = (String) objValue;
} else {
value = objValue.toString();
}
}
data[i][c] = value;
for (Aligner lineAligner : simpleTable.getLineAligners()) {
tableBuilder.on(at(i, c)).addAligner(lineAligner);
}
c++;
}
i++;
}
if (simpleTable.getTableBuilderListener() != null) {
simpleTable.getTableBuilderListener().onBuilt(tableBuilder);
}
if (simpleTable.isUseFullBorder()) {
tableBuilder.addFullBorder(simpleTable.getBorderStyle());
}
return tableBuilder.build();
} | Build table from simple builder
@param simpleTable simple table
@return table | buildTable | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public static CellMatcher at(final int row, final int col) {
return (r, column, model) -> r == row && column == col;
} | Build cell matcher
<p>Should be used only once</p>
@param row the row
@param col the col
@return the cell matcher | at | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public SshAuthentication getAuthentication() {
return SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getAuthentication();
} | Get ssh authentication containing objects from spring security when configured to 'security'
@return authentication from spring authentication, or null of not found in context | getAuthentication | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public ServerSession getSshSession() {
return SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getSshSession();
} | Get ssh session
@return current ssh session, or null if local prompt | getSshSession | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public Environment getSshEnvironment() {
return SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getSshEnv();
} | Get ssh environment
@return current ssh environment, or null if local prompt | getSshEnvironment | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public boolean isLocalPrompt() {
SshContext sshContext = SshShellCommandFactory.SSH_THREAD_CONTEXT.get();
if (sshContext == null) {
return true;
}
return sshContext.isLocalPrompt();
} | @return true if current command executed in a local prompt | isLocalPrompt | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public boolean checkAuthorities(List<String> authorizedRoles) {
if (isLocalPrompt()) {
log.debug("Not an ssh session -> local prompt -> giving all rights");
return true;
}
SshAuthentication auth = SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getAuthentication();
return checkAuthorities(authorizedRoles, auth != null ? auth.getAuthorities() : null, false);
} | Check that one of the roles is in current authorities
@param authorizedRoles authorized roles
@return true if role found in authorities | checkAuthorities | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public boolean checkAuthorities(List<String> authorizedRoles, List<String> authorities,
boolean authorizedIfNoAuthorities) {
if (authorities == null) {
// if authorized only -> return false
return authorizedIfNoAuthorities;
}
for (String authority : authorities) {
String check = authority;
if (check.startsWith("ROLE_")) {
check = check.substring(5);
}
if (authorizedRoles.contains(check)) {
return true;
}
}
return false;
} | Check that one of the roles is in authorities
@param authorizedRoles authorized roles
@param authorities current authorities
@param authorizedIfNoAuthorities whether to return true if no authorities
@return true if role found in authorities | checkAuthorities | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public String progress(int percentage) {
int current = percentage;
if (current > 100) {
current = 100;
log.warn("Setting percentage to 100 (was: {})", percentage);
}
return progress(current, 100);
} | Display percentage on full terminal line
@param percentage current value
@return percentage line | progress | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public PrintWriter terminalWriter() {
return terminal().writer();
} | Return the terminal writer
@return terminal writer | terminalWriter | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public History getHistory() {
return new DefaultHistory(this.reader());
} | Return the terminal reader history
@return history | getHistory | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellHelper.java | Apache-2.0 |
public static void fill(Attributes attr, Map<PtyMode, Integer> ptyModes) {
for (Map.Entry<PtyMode, Integer> e : ptyModes.entrySet()) {
switch (e.getKey()) {
case VINTR ->
attr.setControlChar(Attributes.ControlChar.VINTR, e.getValue());
case VQUIT ->
attr.setControlChar(Attributes.ControlChar.VQUIT, e.getValue());
case VERASE ->
attr.setControlChar(Attributes.ControlChar.VERASE, e.getValue());
case VKILL ->
attr.setControlChar(Attributes.ControlChar.VKILL, e.getValue());
case VEOF ->
attr.setControlChar(Attributes.ControlChar.VEOF, e.getValue());
case VEOL ->
attr.setControlChar(Attributes.ControlChar.VEOL, e.getValue());
case VEOL2 ->
attr.setControlChar(Attributes.ControlChar.VEOL2, e.getValue());
case VSTART ->
attr.setControlChar(Attributes.ControlChar.VSTART, e.getValue());
case VSTOP ->
attr.setControlChar(Attributes.ControlChar.VSTOP, e.getValue());
case VSUSP ->
attr.setControlChar(Attributes.ControlChar.VSUSP, e.getValue());
case VDSUSP ->
attr.setControlChar(Attributes.ControlChar.VDSUSP, e.getValue());
case VREPRINT ->
attr.setControlChar(Attributes.ControlChar.VREPRINT, e.getValue());
case VWERASE ->
attr.setControlChar(Attributes.ControlChar.VWERASE, e.getValue());
case VLNEXT ->
attr.setControlChar(Attributes.ControlChar.VLNEXT, e.getValue());
case VSTATUS ->
attr.setControlChar(Attributes.ControlChar.VSTATUS, e.getValue());
case VDISCARD ->
attr.setControlChar(Attributes.ControlChar.VDISCARD, e.getValue());
case ECHO ->
attr.setLocalFlag(Attributes.LocalFlag.ECHO, e.getValue() != 0);
case ICANON ->
attr.setLocalFlag(Attributes.LocalFlag.ICANON, e.getValue() != 0);
case ISIG ->
attr.setLocalFlag(Attributes.LocalFlag.ISIG, e.getValue() != 0);
case ICRNL ->
attr.setInputFlag(Attributes.InputFlag.ICRNL, e.getValue() != 0);
case INLCR ->
attr.setInputFlag(Attributes.InputFlag.INLCR, e.getValue() != 0);
case IGNCR ->
attr.setInputFlag(Attributes.InputFlag.IGNCR, e.getValue() != 0);
case OCRNL ->
attr.setOutputFlag(Attributes.OutputFlag.OCRNL, e.getValue() != 0);
case ONLCR ->
attr.setOutputFlag(Attributes.OutputFlag.ONLCR, e.getValue() != 0);
case ONLRET ->
attr.setOutputFlag(Attributes.OutputFlag.ONLRET, e.getValue() != 0);
case OPOST ->
attr.setOutputFlag(Attributes.OutputFlag.OPOST, e.getValue() != 0);
default -> {
}
// nothing to do
}
}
} | Fill attributes with given modes
@param attr attributes
@param ptyModes pty modes | fill | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellUtils.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/SshShellUtils.java | Apache-2.0 |
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
boolean authenticated = super.authenticate(username, key, session);
session.getIoSession().setAttribute(SshShellAuthenticationProvider.AUTHENTICATION_ATTRIBUTE, new SshAuthentication(username, username));
return authenticated;
} | Default constructor
@param publicKeysFile public keys file | authenticate | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/auth/SshShellPublicKeyAuthenticationProvider.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/auth/SshShellPublicKeyAuthenticationProvider.java | Apache-2.0 |
@Bean
@Primary
public SshShellAuthenticationProvider passwordAuthenticatorProvider() {
return (username, pass, serverSession) -> {
User user = userService.getByUsername(username);
if (user == null) {
return false;
}
return pass.equals(user.getPassword());
};
} | {@code @Author} baiyi
{@code @Date} 2023/4/4 10:12
{@code @Version} 1.0 | passwordAuthenticatorProvider | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/auth/custom/CustomPasswordConfiguration.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/auth/custom/CustomPasswordConfiguration.java | Apache-2.0 |
protected Availability availability(String commandGroup, String commandName) {
try {
preAvailability();
if (!commandProperties.isEnable()) {
return Availability.unavailable("command deactivated (please check property '" +
SshShellProperties.SSH_SHELL_PREFIX + ".commands." + commandGroup + ".enable" + "')");
}
if (commandProperties.getExcludes() != null && commandProperties.getExcludes().contains(commandName)) {
return Availability.unavailable("command is excluded (please check property '" +
SshShellProperties.SSH_SHELL_PREFIX + ".commands." + commandGroup + ".excludes" + "')");
}
if (commandProperties.getIncludes() != null && !commandProperties.getIncludes().contains(commandName)) {
return Availability.unavailable("command not included (please check property '" +
SshShellProperties.SSH_SHELL_PREFIX + ".commands." + commandGroup + ".includes" + "')");
}
if (helper.isLocalPrompt()) {
log.debug("Not an ssh session -> local prompt -> giving all rights");
return Availability.available();
}
SshAuthentication auth = SshShellCommandFactory.SSH_THREAD_CONTEXT.get().getAuthentication();
List<String> authorities = auth != null ? auth.getAuthorities() : null;
if (commandProperties.isRestricted() && !helper.checkAuthorities(commandProperties.getAuthorizedRoles(),
authorities, properties.getAuthentication() == SshShellProperties.AuthenticationType.simple)) {
return Availability.unavailable("command is forbidden for current user");
}
postAvailability();
return Availability.available();
} catch (AvailabilityException e) {
return Availability.unavailable(e.getMessage());
}
} | Compute availability depending on command group and name
@param commandGroup command group
@param commandName command name
@return command availability | availability | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | Apache-2.0 |
protected void preAvailability() throws AvailabilityException {
// nothing by default
} | Extends this to add behavior before the one in abstract
@throws AvailabilityException if unavailable | preAvailability | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | Apache-2.0 |
protected void postAvailability() throws AvailabilityException {
// nothing by default
} | Extends this to add behavior after the one in abstract
@throws AvailabilityException if unavailable | postAvailability | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/AbstractCommand.java | Apache-2.0 |
@Override
public String[] align(String[] text, int cellWidth, int cellHeight) {
String[] result = new String[text.length];
for (int i = 0; i < text.length; i++) {
result[i] = SshShellHelper.getColoredMessage(text[i], color);
}
return result;
} | Default constructor
@param color the cell text color | align | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/ColorAligner.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/ColorAligner.java | Apache-2.0 |
public static CommandProperties disabledByDefault() {
CommandProperties properties = new CommandProperties();
properties.setEnable(false);
return properties;
} | Create properties for disabled command
@return disabled command | disabledByDefault | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | Apache-2.0 |
public static CommandProperties withAuthorizedRoles(List<String> authorizedRoles) {
CommandProperties properties = new CommandProperties();
properties.setAuthorizedRoles(authorizedRoles);
return properties;
} | Create properties for command with authorized roles
@return command with authorized roles | withAuthorizedRoles | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | Apache-2.0 |
public static CommandProperties notRestrictedByDefault() {
CommandProperties properties = new CommandProperties();
properties.setRestricted(false);
properties.setAuthorizedRoles(null);
return properties;
} | Create properties for not restructed command
@return not restructed command | notRestrictedByDefault | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | Apache-2.0 |
public static CommandProperties withExcludedByDefault(List<String> excludes) {
CommandProperties properties = new CommandProperties();
properties.setExcludes(excludes);
return properties;
} | Create properties for excluded by default
@return excluded by default | withExcludedByDefault | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/CommandProperties.java | Apache-2.0 |
private Availability historyAvailability() {
return availability(GROUP, COMMAND_HISTORY);
} | Override history command to get history per user if not shared | historyAvailability | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/builtin/HistoryCommand.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/command/builtin/HistoryCommand.java | Apache-2.0 |
@Override
default List<AttributedString> getLines(Size size, long currentDelay) {
return getIO(size, currentDelay).getLines();
} | Get lines to write
@param size terminal size
@param currentDelay current refresh delay
@return bean containing lines | getLines | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/interactive/StoppableInteractiveInput.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/interactive/StoppableInteractiveInput.java | Apache-2.0 |
public void onSessionStarted(ChannelSession channelSession) {
notify(new SshShellEvent(SshShellEventType.SESSION_STARTED, channelSession));
} | Session started
@param channelSession ssh channel session | onSessionStarted | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | Apache-2.0 |
public void onSessionStopped(ChannelSession channelSession) {
notify(new SshShellEvent(SshShellEventType.SESSION_STOPPED, channelSession));
} | Session stopped
@param channelSession ssh channel session | onSessionStopped | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | Apache-2.0 |
public void onSessionDestroyed(ChannelSession channelSession) {
notify(new SshShellEvent(SshShellEventType.SESSION_DESTROYED, channelSession));
} | Session destroyed
@param channelSession ssh channel session | onSessionDestroyed | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/listeners/SshShellListenerService.java | Apache-2.0 |
public Map<Long, ChannelSession> listSessions() {
return this.commandFactory.listSessions();
} | List active sessions
@return active sessions | listSessions | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | Apache-2.0 |
public ChannelSession getSession(long id) {
return listSessions().get(id);
} | @param id session id
@return found session, or null if not existing | getSession | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | Apache-2.0 |
public boolean stopSession(long id) {
ChannelSession session = getSession(id);
if (session != null) {
this.commandFactory.destroy(session);
return true;
}
return false;
} | Stop active session
@param id session id
@return true if session found and stopped, false otherwise | stopSession | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | Apache-2.0 |
public static String sessionUserName(ChannelSession session) {
SshAuthentication authentication =
(SshAuthentication) session.getServerSession().getIoSession().getAttribute("authentication");
if (authentication == null) {
return null;
}
return authentication.getName();
} | Search for authenticated user in session
@param session ssh session
@return user name | sessionUserName | java | ixrjog/opscloud4 | opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | https://github.com/ixrjog/opscloud4/blob/master/opscloud-ssh-server/src/main/java/com/baiyi/opscloud/sshserver/manage/SshShellSessionManager.java | Apache-2.0 |
public static FlinkVersion current() {
return values()[values().length - 1];
} | Returns the version for the current branch. | current | java | apache/flink | flink-annotations/src/main/java/org/apache/flink/FlinkVersion.java | https://github.com/apache/flink/blob/master/flink-annotations/src/main/java/org/apache/flink/FlinkVersion.java | Apache-2.0 |
@Override
public String toString() {
return name;
} | The execution mode the config works for. | toString | java | apache/flink | flink-annotations/src/main/java/org/apache/flink/annotation/docs/Documentation.java | https://github.com/apache/flink/blob/master/flink-annotations/src/main/java/org/apache/flink/annotation/docs/Documentation.java | Apache-2.0 |
public static ArchCondition<JavaMethod> haveLeafTypes(
DescribedPredicate<JavaClass> typePredicate) {
return haveLeafReturnTypes(typePredicate)
.and(haveLeafArgumentTypes(typePredicate))
.and(haveLeafExceptionTypes(typePredicate));
} | Tests leaf types of a method against the given predicate.
<p>Given some {@link JavaType}, "leaf" types are recursively determined as described below.
Leaf types are taken from argument, return, and (declared) exception types.
<ul>
<li>If the type is an array type, check its base component type.
<li>If the type is a generic type, check the type itself and all of its type arguments.
<li>Otherwise, check just the type itself.
</ul> | haveLeafTypes | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Conditions.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Conditions.java | Apache-2.0 |
@Override
public boolean includes(Location location) {
return location.matches(MAVEN);
} | Only import class files residing in maven main classes target directory. | includes | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/ImportOptions.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/ImportOptions.java | Apache-2.0 |
@Override
public boolean includes(Location location) {
return !location.matches(SCALA);
} | Excludes Scala classes on a best-effort basis.
<p>ArchUnit doesn't yet support fully Scala. This is a best-effort attempt to not import
Scala classes in the first place. However, it is not perfect, and thus {@link
GivenJavaClasses} or {@link SourcePredicates#areJavaClasses()} should be used in rules as
well. | includes | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/ImportOptions.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/ImportOptions.java | Apache-2.0 |
public static DescribedPredicate<JavaField> isPublic() {
return DescribedPredicate.describe(
"public", field -> field.getModifiers().contains(JavaModifier.PUBLIC));
} | Match the public modifier of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has the public modifier. | isPublic | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> isStatic() {
return DescribedPredicate.describe(
"static", field -> field.getModifiers().contains(JavaModifier.STATIC));
} | Match the static modifier of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has the static modifier. | isStatic | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> isNotStatic() {
return DescribedPredicate.describe(
"not static", field -> !field.getModifiers().contains(JavaModifier.STATIC));
} | Match none static modifier of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has no static modifier. | isNotStatic | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> isFinal() {
return DescribedPredicate.describe(
"final", field -> field.getModifiers().contains(JavaModifier.FINAL));
} | Match the final modifier of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has the final modifier. | isFinal | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> ofType(Class<?> clazz) {
return DescribedPredicate.describe(
"of type " + clazz.getSimpleName(),
field -> field.getRawType().isEquivalentTo(clazz));
} | Match the {@link Class} of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if the tested {@link JavaField} has the
same type of the given {@code clazz}. | ofType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> ofType(String fqClassName) {
String className = getClassSimpleNameFromFqName(fqClassName);
return DescribedPredicate.describe(
"of type " + className, field -> field.getType().getName().equals(fqClassName));
} | Match the {@link Class} of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has the same type of the given {@code clazz}. | ofType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> isAssignableTo(Class<?> clazz) {
return DescribedPredicate.describe(
"is assignable to " + clazz.getSimpleName(),
field -> field.getRawType().isAssignableTo(clazz));
} | Match the {@link Class} of the {@link JavaField}'s assignability.
@param clazz the Class type to check for assignability
@return a {@link DescribedPredicate} that returns {@code true}, if the respective {@link
JavaField} is assignable to the supplied {@code clazz}. | isAssignableTo | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> annotatedWith(
Class<? extends Annotation> annotationType) {
return matchAnnotationType(
annotationType.getSimpleName(),
annotation -> annotation.getRawType().isEquivalentTo(annotationType));
} | Match the single Annotation of the {@link JavaField}.
@return A {@link DescribedPredicate} returning true, if and only if the tested {@link
JavaField} has exactly the given Annotation {@code annotationType}. | annotatedWith | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/JavaFieldPredicates.java | Apache-2.0 |
@SafeVarargs
public static DescribedPredicate<JavaClass> areDirectlyAnnotatedWithAtLeastOneOf(
Class<? extends Annotation>... annotations) {
return Arrays.stream(annotations)
.map(CanBeAnnotated.Predicates::annotatedWith)
.reduce((p, pOther) -> p.or(pOther))
.orElseThrow(IllegalArgumentException::new)
.forSubtype();
} | Common predicates for architecture tests.
<p>NOTE: it is recommended to use methods that accept fully qualified class names instead of
{@code Class} objects to reduce the risks of introducing circular dependencies between the
project submodules. | areDirectlyAnnotatedWithAtLeastOneOf | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaClass> containAnyFieldsInClassHierarchyThat(
DescribedPredicate<? super JavaField> predicate) {
return new ContainAnyFieldsThatPredicate<>("fields", JavaClass::getAllFields, predicate);
} | @return A {@link DescribedPredicate} returning true, if and only if the predicate {@link
JavaField} could be found in the {@link JavaClass}. | containAnyFieldsInClassHierarchyThat | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicStaticOfType(String fqClassName) {
return areFieldOfType(fqClassName, JavaModifier.PUBLIC, JavaModifier.STATIC);
} | Tests that the given field is {@code public static} and has the fully qualified type name of
{@code fqClassName}.
<p>Attention: changing the description will add a rule into the stored.rules. | arePublicStaticOfType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> areFieldOfType(
String fqClassName, JavaModifier... modifiers) {
return DescribedPredicate.describe(
String.format(
"are %s, and of type %s",
Arrays.stream(modifiers)
.map(JavaModifier::toString)
.map(String::toLowerCase)
.collect(Collectors.joining(", ")),
getClassSimpleNameFromFqName(fqClassName)),
field ->
field.getModifiers().containsAll(Arrays.asList(modifiers))
&& field.getRawType().getName().equals(fqClassName));
} | Tests that the field has the fully qualified type of {@code fqClassName} with the given
modifiers.
<p>Attention: changing the description will add a rule into the stored.rules. | areFieldOfType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicFinalOfType(String fqClassName) {
return is(ofType(fqClassName)).and(isPublic()).and(isFinal()).and(isNotStatic());
} | Tests that the given field is {@code public final}, not {@code static} and has the given
fully qualified type name of {@code fqClassName}. | arePublicFinalOfType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicStaticFinalAssignableTo(Class<?> clazz) {
return is(isAssignableTo(clazz)).and(isPublic()).and(isStatic()).and(isFinal());
} | Tests that the given field is {@code public static final} and is assignable to the given type
{@code clazz} . | arePublicStaticFinalAssignableTo | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicStaticFinalOfType(String fqClassName) {
return arePublicStaticOfType(fqClassName).and(isFinal());
} | Tests that the field is {@code public static final} and has the fully qualified type name of
{@code fqClassName}. | arePublicStaticFinalOfType | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicFinalOfTypeWithAnnotation(
String fqClassName, Class<? extends Annotation> annotationType) {
return arePublicFinalOfType(fqClassName).and(annotatedWith(annotationType));
} | Tests that the field is {@code public final}, has the fully qualified type name of {@code
fqClassName} and is annotated with the {@code annotationType}. | arePublicFinalOfTypeWithAnnotation | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> arePublicStaticFinalOfTypeWithAnnotation(
String fqClassName, Class<? extends Annotation> annotationType) {
return arePublicStaticFinalOfType(fqClassName).and(annotatedWith(annotationType));
} | Tests that the field is {@code public static final}, has the fully qualified type name of
{@code fqClassName} and is annotated with the {@code annotationType}. | arePublicStaticFinalOfTypeWithAnnotation | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static DescribedPredicate<JavaField> areStaticFinalOfTypeWithAnnotation(
String fqClassName, Class<? extends Annotation> annotationType) {
return areFieldOfType(fqClassName, JavaModifier.STATIC, JavaModifier.FINAL)
.and(annotatedWith(annotationType));
} | Tests that the field is {@code static final}, has the fully qualified type name of {@code
fqClassName} and is annotated with the {@code annotationType}. It doesn't matter if public,
private or protected. | areStaticFinalOfTypeWithAnnotation | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
@SafeVarargs
public static <T> DescribedPredicate<T> exactlyOneOf(
final DescribedPredicate<? super T>... other) {
return DescribedPredicate.describe(
"only one of the following predicates match:\n"
+ Arrays.stream(other)
.map(dp -> "* " + dp + "\n")
.collect(Collectors.joining()),
t -> Arrays.stream(other).map(dp -> dp.test(t)).reduce(false, Boolean::logicalXor));
} | Returns a {@link DescribedPredicate} that returns true if one and only one of the given
predicates match. | exactlyOneOf | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
public static String getClassSimpleNameFromFqName(String fqClassName) {
// Not using Preconditions to avoid adding non-test flink-core dependency
if (fqClassName == null) {
throw new NullPointerException("Fully qualified class name cannot be null");
}
if (fqClassName.trim().isEmpty()) {
throw new IllegalArgumentException("Fully qualified class name cannot be empty");
}
int lastDotIndex = fqClassName.lastIndexOf('.');
int lastDollarIndex = fqClassName.lastIndexOf('$');
int startIndex = Math.max(lastDotIndex, lastDollarIndex) + 1;
String className = fqClassName.substring(startIndex);
if (className.trim().isEmpty()) {
throw new IllegalArgumentException(
"Extracted class name is empty from: " + fqClassName);
}
return className;
} | Extracts the class name from the given fully qualified class name.
<p>Example:
<pre>
getClassFromFqName("com.example.MyClass"); // Returns: "MyClass"
</pre> | getClassSimpleNameFromFqName | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
@Override
public boolean test(JavaClass input) {
for (T member : getFields.apply(input)) {
if (predicate.test(member)) {
return true;
}
}
return false;
} | A predicate to determine if a {@link JavaClass} contains one or more {@link JavaField }
matching the supplied predicate. | test | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/Predicates.java | Apache-2.0 |
static boolean isJavaClass(JavaClass clazz) {
if (!clazz.getSource().isPresent()) {
return false;
}
final Source source = clazz.getSource().get();
if (!source.getFileName().isPresent()) {
return false;
}
return source.getFileName().get().contains(".java");
} | Checks whether the given {@link JavaClass} is actually a Java class, and not a Scala class.
<p>ArchUnit does not yet fully support Scala. Rules should ensure that they restrict
themselves to only Java classes for correct results. | isJavaClass | java | apache/flink | flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/SourcePredicates.java | https://github.com/apache/flink/blob/master/flink-architecture-tests/flink-architecture-tests-base/src/main/java/org/apache/flink/architecture/common/SourcePredicates.java | Apache-2.0 |
public static void waitUntilJobInitializationFinished(
SupplierWithException<JobStatus, Exception> jobStatusSupplier,
SupplierWithException<JobResult, Exception> jobResultSupplier,
ClassLoader userCodeClassloader)
throws JobInitializationException {
LOG.debug("Wait until job initialization is finished");
WaitStrategy waitStrategy = new ExponentialWaitStrategy(50, 2000);
try {
JobStatus status = jobStatusSupplier.get();
long attempt = 0;
while (status == JobStatus.INITIALIZING) {
Thread.sleep(waitStrategy.sleepTime(attempt++));
status = jobStatusSupplier.get();
}
if (status == JobStatus.FAILED) {
JobResult result = jobResultSupplier.get();
Optional<SerializedThrowable> throwable = result.getSerializedThrowable();
if (throwable.isPresent()) {
Throwable t = throwable.get().deserializeError(userCodeClassloader);
if (t instanceof JobInitializationException) {
throw t;
}
}
}
} catch (JobInitializationException initializationException) {
throw initializationException;
} catch (Throwable throwable) {
ExceptionUtils.checkInterrupted(throwable);
throw new RuntimeException("Error while waiting for job to be initialized", throwable);
}
} | This method blocks until the job status is not INITIALIZING anymore.
@param jobStatusSupplier supplier returning the job status.
@param jobResultSupplier supplier returning the job result. This will only be called if the
job reaches the FAILED state.
@throws JobInitializationException If the initialization failed | waitUntilJobInitializationFinished | java | apache/flink | flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java | https://github.com/apache/flink/blob/master/flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java | Apache-2.0 |
public static JobGraph getJobGraph(
ClassLoader userClassloader,
Pipeline pipeline,
Configuration optimizerConfiguration,
int defaultParallelism) {
FlinkPipelineTranslator pipelineTranslator =
getPipelineTranslator(userClassloader, pipeline);
JobGraph jobGraph =
pipelineTranslator.translateToJobGraph(
pipeline, optimizerConfiguration, defaultParallelism);
optimizerConfiguration
.getOptional(PipelineOptions.PARALLELISM_OVERRIDES)
.ifPresent(
map ->
jobGraph.getJobConfiguration()
.set(PipelineOptions.PARALLELISM_OVERRIDES, map));
return jobGraph;
} | Transmogrifies the given {@link Pipeline} to a {@link JobGraph}. | getJobGraph | java | apache/flink | flink-clients/src/main/java/org/apache/flink/client/FlinkPipelineTranslationUtil.java | https://github.com/apache/flink/blob/master/flink-clients/src/main/java/org/apache/flink/client/FlinkPipelineTranslationUtil.java | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.