Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ public WallApiClientImpl(final String baseUrl,
}

private String bearerNow() {
final String v = org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_API_TOKEN.value();
final String v = wallTokenNow();
return (v == null || v.isBlank()) ? null : v.trim();
}

private String wallTokenNow() {
// 1) 글로벌 설정(Mold 글로벌 설정값) 우선입니다.
final String fromGlobal = org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_API_TOKEN.value();
if (fromGlobal != null && !fromGlobal.isBlank()) {
return fromGlobal;
}

// 2) 글로벌 설정이 비어있을 때만 환경변수로 폴백합니다.
return System.getenv("WALL_API_TOKEN");
}

// 매 호출 시 글로벌 세팅에서 Base URL을 읽습니다(비어있으면 생성자 값 사용).
private String baseUrlNow() {
final String v = org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_BASE_URL.value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private WallConfigKeys() {}
"Base URL of Wall.", false, WALL_ALERT_ENABLED.key());

public static final ConfigKey<String> WALL_API_TOKEN =
new ConfigKey<>("Secure", String.class, "wall.api.token", "raIpjQklz6EE2aK6YWX1N2KJvyyNrO3mG32nYDmUcEeB5i4NHcGFqIS8V69DWduDZmmWYwXi2TQnZxA4AwaxC5+wsr+EL1EUscc=",
new ConfigKey<>("Advanced", String.class, "wall.api.token", "",
"Service account token for Wall.", true, WALL_ALERT_ENABLED.key());

public static final ConfigKey<Integer> CONNECT_TIMEOUT_MS =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.apache.cloudstack.wallAlerts.service;

import com.cloud.alert.AlertManager;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ManagerBase;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
Expand Down Expand Up @@ -800,28 +799,38 @@ public WallSilenceResponse createWallAlertSilence(final CreateWallAlertSilenceCm
}

private void ensureWallConfiguredForRules() {
final String baseUrl = WallConfigKeys.WALL_BASE_URL.value();
final String token = WallConfigKeys.WALL_API_TOKEN.value();
final String baseUrl = org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_BASE_URL.value();
final String token = wallTokenNow();

if (StringUtils.isBlank(baseUrl)) {
throw new ServerApiException(
ApiErrorCode.INTERNAL_ERROR,
if (org.apache.commons.lang3.StringUtils.isBlank(baseUrl)) {
throw new org.apache.cloudstack.api.ServerApiException(
org.apache.cloudstack.api.ApiErrorCode.INTERNAL_ERROR,
"Wall base URL (wall.base.url) is not configured."
);
}

// ★ 여기: enable=true 인데 토큰이 없으면 바로 오류
if (WallConfigKeys.WALL_ALERT_ENABLED.value()) {
if (StringUtils.isBlank(token)) {
throw new ServerApiException(
ApiErrorCode.UNSUPPORTED_ACTION_ERROR,
// enable=true 인데 토큰이 없으면 바로 오류입니다.
// 여기서 토큰은 “글로벌 설정 우선, 없으면 env 폴백” 결과입니다.
if (org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_ALERT_ENABLED.value()) {
if (org.apache.commons.lang3.StringUtils.isBlank(token)) {
throw new org.apache.cloudstack.api.ServerApiException(
org.apache.cloudstack.api.ApiErrorCode.UNSUPPORTED_ACTION_ERROR,
"Wall API token (wall.api.token) is not configured. " +
"Please set a valid service account token to use Wall Alerts."
"Please set a valid service account token in global settings " +
"or provide WALL_API_TOKEN environment variable."
);
}
}
}

private String wallTokenNow() {
final String fromGlobal = org.apache.cloudstack.wallAlerts.config.WallConfigKeys.WALL_API_TOKEN.value();
if (fromGlobal != null && !fromGlobal.isBlank()) {
return fromGlobal;
}
return System.getenv("WALL_API_TOKEN");
}

private void maybeSendWallAlert(final String uid,
final String ruleName,
final String operator,
Expand Down
Loading