Skip to content

Commit

Permalink
Add test function for listing devices in a site registry (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored May 15, 2024
1 parent 84f293e commit 9234c45
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
19 changes: 19 additions & 0 deletions udmis/.idea/runConfigurations/ClearBladeIotAccessProvider.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.udmi.util.JsonUtil;
import java.util.AbstractMap.SimpleEntry;
import java.util.Base64;
import java.util.Date;
Expand Down Expand Up @@ -95,7 +97,8 @@
public class ClearBladeIotAccessProvider extends IotAccessBase {

public static final String REGISTRIES_FIELD_MASK = "id,name";
private static final Set<String> CLOUD_REGIONS = ImmutableSet.of("us-central1");
public static final String DEFAULT_REGION = "us-central1";
private static final Set<String> CLOUD_REGIONS = ImmutableSet.of(DEFAULT_REGION);
private static final String EMPTY_JSON = "{}";
private static final BiMap<Key_format, PublicKeyFormat> AUTH_TYPE_MAP = ImmutableBiMap.of(
Key_format.RS_256, PublicKeyFormat.RSA_PEM,
Expand All @@ -117,9 +120,31 @@ public class ClearBladeIotAccessProvider extends IotAccessBase {
private static final String UDMI_STATE_TOPIC = "udmi_state"; // TODO: Make this not hardcoded.
private static final String TOPIC_NAME_FORMAT = "projects/%s/topics/%s";
private static final CharSequence BOUND_TO_GATEWAY_MARKER = " it's associated ";
public static final String CONFIG_ENV = "CLEARBLADE_CONFIGURATION";
private final String projectId;
private final DeviceManagerInterface deviceManager;

/**
* Core test function for listing the devices in a registry.
*/
public static void main(String[] args) {
requireNonNull(System.getenv(CONFIG_ENV), CONFIG_ENV + " not defined");
IotAccess iotAccess = new IotAccess();
if (args.length != 1) {
System.err.println("Usage: registry_id");
return;
}
final String registryId = args[0];
Map<String, Object> stringObjectMap = JsonUtil.loadMap(System.getenv(CONFIG_ENV));
iotAccess.project_id = (String) requireNonNull(stringObjectMap.get("project"));
System.err.println("Extracted project from ClearBlade config file: " + iotAccess.project_id);
ClearBladeIotAccessProvider clearBladeIotAccessProvider =
new ClearBladeIotAccessProvider(iotAccess);
clearBladeIotAccessProvider.populateRegistryRegions();
CloudModel cloudModel = clearBladeIotAccessProvider.listDevices(registryId);
System.err.printf("Found %d results%n", cloudModel.device_ids.size());
}

/**
* Create a new instance for interfacing with GCP IoT Core.
*/
Expand Down

0 comments on commit 9234c45

Please sign in to comment.