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 @@ -16,7 +16,7 @@ dependencies {
}

group = 'com.logicmonitor'
version = '0.0.4-alpha'
version = '0.0.5-alpha'
java.sourceCompatibility = JavaVersion.VERSION_1_8


Expand Down
1 change: 1 addition & 0 deletions data-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'javax.validation:validation-api:2.0.1.Final'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.apache.commons:commons-lang3:3.12.0'
compileOnly 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok:1.18.26'
implementation 'org.slf4j:slf4j-api:2.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
* This Class is used to configure the device with account name and Lm access credinatial(by using
Expand All @@ -28,6 +29,7 @@ public class Configuration {
private final String REGEX_AUTH_ID = "^[a-zA-Z0-9]+$";
private final Pattern PatternAuthId = Pattern.compile(REGEX_AUTH_ID);
private static String company;
private static String domainName;
private static String host;
private int connectionPoolMaxsize;

Expand All @@ -50,6 +52,7 @@ public Configuration() {
accessId = System.getenv("LM_ACCESS_ID");
accessKey = System.getenv("LM_ACCESS_KEY");
bearerToken = System.getenv("LM_BEARER_TOKEN");
domainName = System.getenv("LM_DOMAIN_NAME");

checkAuthentication();
}
Expand All @@ -59,12 +62,15 @@ public Configuration() {
* @param accessId
* @param accessKey
* @param bearerToken
* @param domainName
*/
public Configuration(String company, String accessId, String accessKey, String bearerToken) {
public Configuration(
String company, String accessId, String accessKey, String bearerToken, String domainName) {
this.company = (company != null) ? company : System.getenv("LM_COMPANY");
this.accessId = (accessId != null) ? accessId : System.getenv("LM_ACCESS_ID");
this.accessKey = (accessKey != null) ? accessKey : System.getenv("LM_ACCESS_KEY");
this.bearerToken = (bearerToken != null) ? bearerToken : System.getenv("LM_BEARER_TOKEN");
this.domainName = (domainName != null) ? domainName : System.getenv("LM_DOMAIN_NAME");

checkAuthentication();
}
Expand Down Expand Up @@ -109,7 +115,13 @@ public static String encodeSHA256(String key, String text) throws Exception {

public static String setCompany() {
company = getCompany();
host = "https://" + company + ".logicmonitor.com/rest";
domainName = getDomainName();

// host = "https://" + company + ".logicmonitor.com/rest";
if (StringUtils.isBlank(domainName)) {
domainName = "logicmonitor.com";
}
host = "https://" + company + "." + domainName + "/rest";
return host;
}

Expand All @@ -121,6 +133,7 @@ public boolean checkAuthentication() {
if (company == null || company.length() <= 0 || company.equals(" ")) {
throw new IllegalArgumentException("Company must have your account name");
}

if (!isValidCompanyName(company)) {
throw new IllegalArgumentException("Invalid Company Name");
}
Expand Down Expand Up @@ -150,7 +163,11 @@ public boolean checkAuthentication() {
}
}

this.host = "https://" + this.company + ".logicmonitor.com/rest";
// this.host = "https://" + this.company + ".logicmonitor.com/rest";
if (StringUtils.isBlank(domainName)) {
domainName = "logicmonitor.com";
}
this.host = "https://" + company + "." + domainName + "/rest";
this.connectionPoolMaxsize = Runtime.getRuntime().availableProcessors() * 5;
return true;
}
Expand Down Expand Up @@ -217,6 +234,10 @@ public static String getCompany() {
return company;
}

public static String getDomainName() {
return domainName;
}

/** @return gZip */
public static boolean getgZip() {
return gZip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ public void testIsValidAuthId() {

@Test
public void testConfiguration() {
Configuration conf = new Configuration("company01", null, null, "bhasgsyhsjjdbfbhcgyi@1");
Configuration conf =
new Configuration("company01", null, null, "bhasgsyhsjjdbfbhcgyi@1", "logicmonitor.com");
String actualToken = conf.getAuthToken("POST", "POST", "/v2/metric/ingest");
Assertions.assertTrue(true, actualToken);
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidBearerAuth() {
Configuration conf = new Configuration("company01", null, null, " ");
Configuration conf = new Configuration("company01", null, null, " ", "logicmonitor.com");
boolean authentication = conf.checkAuthentication();
Assertions.assertEquals(IllegalArgumentException.class, authentication);
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidLMv1Auth() {
Configuration conf = new Configuration("company01", " ", " ", null);
Configuration conf = new Configuration("company01", " ", " ", null, "logicmonitor.com");
boolean authentication = conf.checkAuthentication();
Assertions.assertEquals(IllegalArgumentException.class, authentication);
}
Expand All @@ -64,14 +65,19 @@ public void testInvalidCompanyName() {
public void testLMv1Auth() {
Configuration conf =
new Configuration(
"company01", "5t5U5jH6Q92P2n8x8tg5", "[KC5sdqL-vX25-35pP2gmPw(f_15W(]LLg(B4Kc8", null);
"company01",
"5t5U5jH6Q92P2n8x8tg5",
"[KC5sdqL-vX25-35pP2gmPw(f_15W(]LLg(B4Kc8",
null,
"logicmonitor.com");
conf.getAuthToken(body, "POST", "/v2/metric/ingest");
Assert.assertTrue("This will succeed.", true);
}

@Test
public void testBearerAuth() {
Configuration conf = new Configuration("company01", null, null, "bhasgsyhsjjdbfbhcgyi@1");
Configuration conf =
new Configuration("company01", null, null, "bhasgsyhsjjdbfbhcgyi@1", "logicmonitor.com");
String expectedToken = "Bearer bhasgsyhsjjdbfbhcgyi@1";
String actualToken = conf.getAuthToken("POST", "POST", "/v2/metric/ingest");
Assertions.assertEquals(expectedToken, actualToken);
Expand Down
Loading