Skip to content

Commit 6f8bd27

Browse files
authored
Merge pull request #1 from soracom/bootstrap-azures-iot-device
Addition of bootstrap Azure IOT device operation
2 parents 94b1490 + a8cd599 commit 6f8bd27

File tree

8 files changed

+196
-2
lines changed

8 files changed

+196
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
.DS_Store
1010
.gradle
1111
.gradle/
12-
maven-repository
12+
maven-repository
13+
.idea/
14+
*.iml
15+
/out/

src/main/java/io/soracom/krypton/ProvisioningApiEndpoint.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public static String bootstrapAwsIotThing(String baseUrl) {
4545
return trimSlash(baseUrl) + "/v1/provisioning/aws/iot/bootstrap";
4646
}
4747

48+
public static String bootstrapAzureIotDevice(String baseUrl) {
49+
return trimSlash(baseUrl) + "/v1/provisioning/azure/iot/bootstrap";
50+
}
51+
4852
public static String bootstrapInventoryDevice(String baseUrl) {
4953
return trimSlash(baseUrl) + "/v1/provisioning/soracom/inventory/bootstrap";
5054
}

src/main/java/io/soracom/krypton/SORACOMKryptonCLI.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package io.soracom.krypton;
1616

17+
import io.soracom.krypton.cli.BootstrapAzureIotDeviceOperationHandler;
1718
import java.util.ArrayList;
1819
import java.util.Comparator;
1920
import java.util.List;
@@ -59,6 +60,7 @@ public class SORACOMKryptonCLI {
5960
kryptonOptionHanderList.add(new GenerateAmazonCognitoSessionCredentialsOperationHandler());
6061
kryptonOptionHanderList.add(new GenerateAmazonCognitoOpenIdTokenOperationHandler());
6162
kryptonOptionHanderList.add(new BootstrapAwsIotThingOperationHandler());
63+
kryptonOptionHanderList.add(new BootstrapAzureIotDeviceOperationHandler());
6264
}
6365

6466
public static class KryptonCLIOptions {
@@ -70,7 +72,7 @@ public static class KryptonCLIOptions {
7072
OperationInfo info = provisioningApiHandler.getOperationInfo();
7173
optionList.append("[ " + info.getOperation() + " ]: " + info.getDescription() + "\n");
7274
}
73-
optionList.append("(eg. -s getSubscriberMetadata )");
75+
optionList.append("(eg. -o getSubscriberMetadata )");
7476
execOption = Option.builder("o").longOpt("operation").hasArg().required().desc(optionList.toString())
7577
.valueSeparator().build();
7678
}

src/main/java/io/soracom/krypton/SORACOMKryptonClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
import io.soracom.endorse.keycache.AuthResult;
2929
import io.soracom.endorse.utils.Utilities;
3030
import io.soracom.krypton.beans.BootstrapAwsIotThingResult;
31+
import io.soracom.krypton.beans.BootstrapAzureIotDeviceResult;
32+
import io.soracom.krypton.beans.BootstrapAzureRequestParams;
3133
import io.soracom.krypton.beans.BootstrapInventoryDeviceParams;
3234
import io.soracom.krypton.beans.BootstrapInventoryDeviceResult;
3335
import io.soracom.krypton.beans.GenerateAmazonCognitoOpenIdTokenResult;
3436
import io.soracom.krypton.beans.GenerateAmazonCognitoSessionCredentialsResult;
3537
import io.soracom.krypton.beans.GetSubscriberMetadataResult;
3638
import io.soracom.krypton.beans.ProvisioningBean;
3739
import io.soracom.krypton.common.KryptonClientRuntimeException;
40+
import io.soracom.krypton.beans.BootstrapAzureDeviceParams;
3841

3942
public class SORACOMKryptonClient {
4043

@@ -129,6 +132,13 @@ public BootstrapAwsIotThingResult bootstrapAwsIotThing() {
129132
return invokeKeyDistributionService(request, BootstrapAwsIotThingResult.class);
130133
}
131134

135+
public BootstrapAzureIotDeviceResult bootstrapAzureIotDevice(BootstrapAzureDeviceParams params) {
136+
TrustedEntityRequst request = new TrustedEntityRequst();
137+
request.requestParameters = new BootstrapAzureRequestParams(params);
138+
request.apiEndpointUrl = ProvisioningApiEndpoint.bootstrapAzureIotDevice(kryptonClientConfig.getApiEndpointUrl());
139+
return invokeKeyDistributionService(request, BootstrapAzureIotDeviceResult.class);
140+
}
141+
132142
private <T> T invokeKeyDistributionService(TrustedEntityRequst request, Class<T> resultClass) {
133143
ProvisioningBean invokeProvisioingApiResult = invokeProvisioningApi(request, false);
134144
return Utilities.fromJson(invokeProvisioingApiResult.getServiceProviderResponse(), resultClass);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.soracom.krypton.beans;
2+
3+
public class BootstrapAzureDeviceParams {
4+
5+
private String deviceId;
6+
private String globalEndpoint;
7+
private String idScope;
8+
private String azureIotCredentialId;
9+
private String x509CredentialId;
10+
private boolean registerDevice;
11+
12+
public String getDeviceId() {
13+
return deviceId;
14+
}
15+
16+
public void setDeviceId(String deviceId) {
17+
this.deviceId = deviceId;
18+
}
19+
public String getGlobalEndpoint() {
20+
return globalEndpoint;
21+
}
22+
23+
public void setGlobalEndpoint(String globalEndpoint) {
24+
this.globalEndpoint = globalEndpoint;
25+
}
26+
27+
public String getIdScope() {
28+
return idScope;
29+
}
30+
31+
public void setIdScope(String idScope) {
32+
this.idScope = idScope;
33+
}
34+
35+
public String getAzureIotCredentialId() {
36+
return azureIotCredentialId;
37+
}
38+
39+
public void setAzureIotCredentialId(String azureIotCredentialId) {
40+
this.azureIotCredentialId = azureIotCredentialId;
41+
}
42+
43+
public String getX509CredentialId() {
44+
return x509CredentialId;
45+
}
46+
47+
public void setX509CredentialId(String x509CredentialId) {
48+
this.x509CredentialId = x509CredentialId;
49+
}
50+
51+
public boolean isRegisterDevice() {
52+
return registerDevice;
53+
}
54+
55+
public void setRegisterDevice(boolean registerDevice) {
56+
this.registerDevice = registerDevice;
57+
}
58+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.soracom.krypton.beans;
2+
3+
public class BootstrapAzureIotDeviceResult {
4+
5+
6+
private String certificate;
7+
private String privateKey;
8+
private String deviceId;
9+
private String operationId;
10+
private String status;
11+
12+
public String getCertificate() {
13+
return certificate;
14+
}
15+
16+
public void setCertificate(String certificate) {
17+
this.certificate = certificate;
18+
}
19+
20+
public String getPrivateKey() {
21+
return privateKey;
22+
}
23+
24+
public void setPrivateKey(String privateKey) {
25+
this.privateKey = privateKey;
26+
}
27+
28+
public String getDeviceId() {
29+
return deviceId;
30+
}
31+
32+
public void setDeviceId(String deviceId) {
33+
this.deviceId = deviceId;
34+
}
35+
36+
public String getOperationId() {
37+
return operationId;
38+
}
39+
40+
public void setOperationId(String operationId) {
41+
this.operationId = operationId;
42+
}
43+
44+
public String getStatus() {
45+
return status;
46+
}
47+
48+
public void setStatus(String status) {
49+
this.status = status;
50+
}
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.soracom.krypton.beans;
2+
3+
public class BootstrapAzureRequestParams {
4+
private BootstrapAzureDeviceParams requestParameters;
5+
6+
public BootstrapAzureRequestParams(){
7+
requestParameters = new BootstrapAzureDeviceParams();
8+
}
9+
10+
public BootstrapAzureRequestParams(BootstrapAzureDeviceParams requestParameters){
11+
this.requestParameters = requestParameters;
12+
}
13+
14+
public BootstrapAzureDeviceParams getRequestParameters() {
15+
return requestParameters;
16+
}
17+
18+
public void setRequestParameters(BootstrapAzureDeviceParams requestParameters) {
19+
this.requestParameters = requestParameters;
20+
}
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) 2018 SORACOM, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package io.soracom.krypton.cli;
16+
17+
import io.soracom.endorse.utils.Utilities;
18+
import io.soracom.krypton.SORACOMKryptonClient;
19+
import io.soracom.krypton.SORACOMKryptonClientConfig;
20+
import io.soracom.krypton.beans.BootstrapAzureIotDeviceResult;
21+
import io.soracom.krypton.beans.BootstrapAzureDeviceParams;
22+
23+
/**
24+
* Handler to invoke operation of bootstrapAzureIotDevice
25+
*
26+
* @author olivier-soracom
27+
*
28+
*/
29+
public class BootstrapAzureIotDeviceOperationHandler implements KryptonOperationHandler<BootstrapAzureIotDeviceResult> {
30+
31+
@Override
32+
public OperationInfo getOperationInfo() {
33+
return new OperationInfo("bootstrapAzureIotDevice", "Bootstrap Azure IoT Devices");
34+
}
35+
36+
@Override
37+
public BootstrapAzureIotDeviceResult invoke(SORACOMKryptonClientConfig kryptonClientConfig, String requestParamJson) {
38+
SORACOMKryptonClient client = new SORACOMKryptonClient(kryptonClientConfig);
39+
BootstrapAzureDeviceParams param = Utilities.fromJson(requestParamJson,
40+
BootstrapAzureDeviceParams.class);
41+
BootstrapAzureIotDeviceResult result = client.bootstrapAzureIotDevice(param);
42+
return result;
43+
}
44+
45+
}

0 commit comments

Comments
 (0)