From df0edfa992ae30b2f816bdb9548253c6ceecfc05 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:01:30 +0000 Subject: [PATCH 01/10] vied to use request builder --- .../main/java/com/oracle/timg/oci/networking/VCNProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/networking/VCNProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/networking/VCNProcessor.java index 6284a6c..9cd7730 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/networking/VCNProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/networking/VCNProcessor.java @@ -209,7 +209,7 @@ public List listVcns(@NonNull Compartment parentCompartment) { */ public List listVcns(@NonNull String parentCompartmentOcid) { Iterable vcns = vcnClient.getPaginators() - .listVcnsRecordIterator(new ListVcnsRequest().builder().compartmentId(parentCompartmentOcid) + .listVcnsRecordIterator(ListVcnsRequest.builder().compartmentId(parentCompartmentOcid) .lifecycleState(Vcn.LifecycleState.Available).lifecycleState(Vcn.LifecycleState.Provisioning) .lifecycleState(Vcn.LifecycleState.Updating).build()); return StreamSupport.stream(vcns.spliterator(), false).toList(); From 24e7911e2a48f1aacf143a9e3cb4937a96a14717 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:02:07 +0000 Subject: [PATCH 02/10] first pass of IoT support --- .../com/oracle/timg/oci/iot/IoTProcessor.java | 1182 +++++++++++++++++ 1 file changed, 1182 insertions(+) create mode 100644 oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java new file mode 100644 index 0000000..310f472 --- /dev/null +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java @@ -0,0 +1,1182 @@ +/*Copyright (c) 2025 Oracle and/or its affiliates. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any +person obtaining a copy of this software, associated documentation and/or data +(collectively the "Software"), free of charge and under any and all copyright +rights in the Software, and any and all patent rights owned or freely +licensable by each licensor hereunder covering either (i) the unmodified +Software as contributed to or provided by such licensor, or (ii) the Larger +Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +one is included with the Software (each a "Larger Work" to which the Software +is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create +derivative works of, display, perform, and distribute the Software and make, +use, sell, offer for sale, import, export, have made, and have sold the +Software and the Larger Work(s), and to sublicense the foregoing rights on +either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at +a minimum a reference to the UPL must be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ +package com.oracle.timg.oci.iot; + +import java.util.List; +import java.util.Map; +import java.util.stream.StreamSupport; + +import org.apache.http.HttpStatus; + +import com.oracle.bmc.identity.model.Compartment; +import com.oracle.bmc.iot.IotClient; +import com.oracle.bmc.iot.model.CreateDigitalTwinInstanceDetails; +import com.oracle.bmc.iot.model.DigitalTwinAdapter; +import com.oracle.bmc.iot.model.DigitalTwinAdapterSummary; +import com.oracle.bmc.iot.model.DigitalTwinInstance; +import com.oracle.bmc.iot.model.DigitalTwinInstanceSummary; +import com.oracle.bmc.iot.model.DigitalTwinModel; +import com.oracle.bmc.iot.model.DigitalTwinModelSummary; +import com.oracle.bmc.iot.model.IotDomain; +import com.oracle.bmc.iot.model.IotDomainGroup; +import com.oracle.bmc.iot.model.IotDomainGroupSummary; +import com.oracle.bmc.iot.model.IotDomainSummary; +import com.oracle.bmc.iot.requests.CreateDigitalTwinInstanceRequest; +import com.oracle.bmc.iot.requests.DeleteDigitalTwinInstanceRequest; +import com.oracle.bmc.iot.requests.GetDigitalTwinAdapterRequest; +import com.oracle.bmc.iot.requests.GetDigitalTwinInstanceContentRequest; +import com.oracle.bmc.iot.requests.GetDigitalTwinInstanceRequest; +import com.oracle.bmc.iot.requests.GetDigitalTwinModelRequest; +import com.oracle.bmc.iot.requests.GetIotDomainGroupRequest; +import com.oracle.bmc.iot.requests.GetIotDomainRequest; +import com.oracle.bmc.iot.requests.ListDigitalTwinAdaptersRequest; +import com.oracle.bmc.iot.requests.ListDigitalTwinInstancesRequest; +import com.oracle.bmc.iot.requests.ListDigitalTwinModelsRequest; +import com.oracle.bmc.iot.requests.ListIotDomainGroupsRequest; +import com.oracle.bmc.iot.requests.ListIotDomainsRequest; +import com.oracle.bmc.iot.responses.CreateDigitalTwinInstanceResponse; +import com.oracle.bmc.iot.responses.DeleteDigitalTwinInstanceResponse; +import com.oracle.bmc.iot.responses.GetDigitalTwinAdapterResponse; +import com.oracle.bmc.iot.responses.GetDigitalTwinInstanceContentResponse; +import com.oracle.bmc.iot.responses.GetDigitalTwinInstanceResponse; +import com.oracle.bmc.iot.responses.GetDigitalTwinModelResponse; +import com.oracle.bmc.iot.responses.GetIotDomainGroupResponse; +import com.oracle.bmc.iot.responses.GetIotDomainResponse; +import com.oracle.bmc.vault.model.Secret; +import com.oracle.timg.oci.authentication.AuthenticationProcessor; + +import lombok.Getter; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; + +/** + * this class provides a wrapper around the oci sdk for iot and makes things + * easier + */ +@Slf4j +public class IoTProcessor { + private final AuthenticationProcessor authProcessor; + @Getter + private final IotClient iotClient; + + /** + * creates an instance which will use the provided AuthenticationProcessor for + * authentication + * + * @param authProcessor + */ + public IoTProcessor(AuthenticationProcessor authProcessor) { + this.authProcessor = authProcessor; + iotClient = IotClient.builder().region(authProcessor.getRegionName()).build(authProcessor.getProvider()); + } + + /** + * allows you to change the region form the default provided by the + * AuthenticationProcessor + * + * @param regionName + */ + public void setRegion(@NonNull String regionName) { + iotClient.setRegion(regionName); + } + + /** + * gets a list of summaries of all IotDomainGroups in the tenancy root + * compartment + * + * @return + */ + public List listIoTDomainGroupSummariesInTenancy() { + return listIoTDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); + } + + /** + * gets a list of summaries of all IotDomainGroups in the specified parent + * compartment + * + * @param parentCompartment + * @return + */ + public List listIoTDomainGroupSummariesInCompartment( + @NonNull Compartment parentCompartment) { + return listIoTDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); + } + + /** + * gets a list of summaries of all IotDomainGroups in the compartment with the + * specified parent compartment ocid + * + * @param parentCompartmentOcid + * @return + */ + public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid) { + return listIoTDomainGroupSummariesInCompartment(parentCompartmentOcid, null); + } + + /** + * generate a list of all domain group summaries in a compartment, if + * displayName is not null limits it to only those matching the display name + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public List listIoTDomainGroupSummariesInCompartment(@NonNull Compartment parentCompartment, + String displayName) { + return listIoTDomainGroupSummariesInCompartment(parentCompartment.getId(), displayName); + } + + /** + * generate a list of all domain group summaries in a compartment, if + * displayName is not null limits it to only those matching the display name + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, + String displayName) { + ListIotDomainGroupsRequest.Builder requestBuilder = ListIotDomainGroupsRequest.builder() + .compartmentId(parentCompartmentOcid); + if (displayName != null) { + requestBuilder.displayName(displayName); + } + Iterable domainGroupsSummaries = iotClient.getPaginators() + .listIotDomainGroupsRecordIterator(requestBuilder.build()); + return StreamSupport.stream(domainGroupsSummaries.spliterator(), false).toList(); + } + + /** + * gets a list of all IotDomainGroups in the tenancy root compartment + * + * @return + */ + public List listIoTDomainGroupsInTenancy() { + return listIoTDomainGroupsInCompartment(authProcessor.getTenancyOCID()); + } + + /** + * returns a list of all IotDomainGroups in the compartment with the specified + * parent compartment ocid + * + * @param parentCompartmentOcid + * @return + */ + public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid) { + return listIoTDomainGroupsInCompartment(parentCompartmentOcid, null); + } + + /** + * returns a list of all IotDomainGroups in the specified parent compartment + * + * @param parentCompartmentOcid + * @return + */ + public List listIoTDomainGroupsInCompartment(@NonNull Compartment parentCompartment) { + return listIoTDomainGroupsInCompartment(parentCompartment.getId(), null); + } + + /** + * * returns a list of all IotDomainGroups with a matching displayName in the + * compartment with the specified parent compartment ocid. If displayName is + * null returns all domain groups + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, + String displayName) { + List domainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + parentCompartmentOcid, displayName); + return domainGroupSummaries.stream().map(dsg -> getIotDomainGroup(dsg)).toList(); + } + + /** + * gets the **FIRST** IotDomainGroupSummary with a matching display name in the + * compartment with the specified OCID, or null if there are no matches + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentCompartmentOcid, + @NonNull String displayName) { + List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + parentCompartmentOcid, displayName); + if (iotDomainGroupSummaries.isEmpty()) { + return null; + } + return iotDomainGroupSummaries.getFirst(); + } + + /** + * gets the **FIRST** IotDomainGroup with matching displayName in the + * compartment with the specified parent compartment ocid, or null if there are + * no matches + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @NonNull String displayName) { + List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + parentCompartmentOcid, displayName); + if (iotDomainGroupSummaries.isEmpty()) { + return null; + } + return getIotDomainGroup(iotDomainGroupSummaries.getFirst()); + } + + /** + * gets the IotDomainGroup details from the provided summary + * + * @param iotDomainGroupSummary + * @return + */ + public IotDomainGroup getIotDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary) { + GetIotDomainGroupResponse resp = iotClient.getIotDomainGroup( + GetIotDomainGroupRequest.builder().iotDomainGroupId(iotDomainGroupSummary.getId()).build()); + return resp.getIotDomainGroup(); + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup + * + * @param iotDomainGroupSummary + * @return + */ + public List listIotDomainSummariesInIotDomainGroup( + @NonNull IotDomainGroupSummary iotDomainGroupSummary) { + return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getId()); + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup + * + * @param iotDomainGroup + * @return + */ + + public List listIotDomainSummariesInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup) { + return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getId()); + + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup + * + * @param iotDomainGroupOcid + * @return + */ + public List listIotDomainSummariesInIotDomainGroup(@NonNull String iotDomainGroupOcid) { + return listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, null); + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomainGroupSummary + * @Param displayName + * @return + */ + public List listIotDomainSummariesInIotDomainGroup( + @NonNull IotDomainGroupSummary iotDomainGroupSummary, String displayName) { + return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getId(), displayName); + + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomainGroup + * @Param displayName + * @return + */ + public List listIotDomainSummariesInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup, + String displayName) { + return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getId(), displayName); + } + + /** + * get a summary of all IotDomains in the specified IoTDomainGroup, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomainGroupSummaryOcid + * @Param displayName + * @return + */ + public List listIotDomainSummariesInIotDomainGroup(@NonNull String iotDomainGroupOcid, + String displayName) { + ListIotDomainsRequest.Builder requestBuilder = ListIotDomainsRequest.builder() + .iotDomainGroupId(iotDomainGroupOcid); + if (displayName != null) { + requestBuilder.displayName(displayName); + } + Iterable domainGroupSummaries = iotClient.getPaginators() + .listIotDomainsRecordIterator(requestBuilder.build()); + return StreamSupport.stream(domainGroupSummaries.spliterator(), false).toList(); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroupSummary + * + * @param iotDomainGroupSummary + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary) { + return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getId()); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup + * + * @param iotDomainGroup + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup) { + return listIotDomainsInIotDomainGroup(iotDomainGroup.getId()); + + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroupSummary + * + * @param iotDomainGroupOcid + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull String iotDomainGroupOcid) { + return listIotDomainsInIotDomainGroup(iotDomainGroupOcid, null); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroupSummary, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomainGroupSummary + * @Param displayName + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary, + String displayName) { + return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getId(), displayName); + + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup, if displayName + * is not null limits on only domains with a matching name + * + * @param iotDomainGroup + * @Param displayName + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup, String displayName) { + return listIotDomainsInIotDomainGroup(iotDomainGroup.getId(), displayName); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup, if displayName + * is not null limits on only domains with a matching name + * + * @param iotDomainGroupOcid + * @Param displayName + * @return + */ + public List listIotDomainsInIotDomainGroup(@NonNull String iotDomainGroupOcid, String displayName) { + List domainSummaries = listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, + displayName); + return domainSummaries.stream().map(ds -> getIotDomain(ds)).toList(); + } + + /** + * get the iotdomain (i.e. with full details) from the specified summary + * + * @param iotDomainSummary + * @return + */ + public IotDomain getIotDomain(@NonNull IotDomainSummary iotDomainSummary) { + GetIotDomainResponse resp = iotClient + .getIotDomain(GetIotDomainRequest.builder().iotDomainId(iotDomainSummary.getId()).build()); + return resp.getIotDomain(); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup, if displayName + * is not null limits on only domains with a matching name + * + * @param iotDomainGroup + * @Param displayName + * @return + */ + public IotDomain getIotDomain(@NonNull IotDomainGroup iotDomainGroup, @NonNull String displayName) { + return getIotDomain(iotDomainGroup.getId(), displayName); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup, if displayName + * is not null limits on only domains with a matching name + * + * @param iotDomainGroup + * @Param displayName + * @return + */ + public IotDomain getIotDomain(@NonNull IotDomainGroupSummary iotDomainGroupSummary, @NonNull String displayName) { + return getIotDomain(iotDomainGroupSummary.getId(), displayName); + } + + /** + * get a list of all IotDomains in the specified IoTDomainGroup, if displayName + * is not null limits on only domains with a matching name + * + * @param iotDomainGroupOcid + * @Param displayName + * @return + */ + public IotDomain getIotDomain(@NonNull String iotDomainGroupOcid, @NonNull String displayName) { + List iotDomainSummaries = listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, + displayName); + if (iotDomainSummaries.isEmpty()) { + return null; + } + return getIotDomain(iotDomainSummaries.getFirst()); + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinModelSummaries(iotDomainSummary.getId()); + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull IotDomain iotDomain) { + return listDigitalTwinModelSummaries(iotDomain.getId()); + + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull String iotDomainOcid) { + return listDigitalTwinModelSummaries(iotDomainOcid, null); + + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomainSummary, + * if displayName is not null limits on only domains with a matching name + * + * @param iotDomainSummary + * @Param displayName + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinModelSummaries(iotDomainSummary.getId(), displayName); + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomain, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomain + * @Param displayName + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull IotDomain iotDomain, + String displayName) { + return listDigitalTwinModelSummaries(iotDomain.getId(), displayName); + + } + + /** + * get a list of all DigitalTwinModelSummary in the specified IoTDomain, if + * displayName is not null limits on only domains with a matching name + * + * @param iotDomainOcid + * @Param displayName + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull String iotDomainOcid, + String displayName) { + ListDigitalTwinModelsRequest.Builder requestBuilder = ListDigitalTwinModelsRequest.builder() + .iotDomainId(iotDomainOcid); + if (displayName != null) { + requestBuilder.displayName(displayName); + } + Iterable digitalTwinModelSummaries = iotClient.getPaginators() + .listDigitalTwinModelsRecordIterator(requestBuilder.build()); + return StreamSupport.stream(digitalTwinModelSummaries.spliterator(), false).toList(); + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinModels(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinModels(iotDomainSummary.getId()); + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinModels(@NonNull IotDomain iotDomain) { + return listDigitalTwinModels(iotDomain.getId()); + + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinModels(@NonNull String iotDomainOcid) { + return listDigitalTwinModels(iotDomainOcid, null); + + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomainSummary, if + * displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public List listDigitalTwinModels(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinModels(iotDomainSummary.getId(), displayName); + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName + * is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ + public List listDigitalTwinModels(@NonNull IotDomain iotDomain, String displayName) { + return listDigitalTwinModels(iotDomain.getId(), displayName); + + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName + * is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinModels(@NonNull String iotDomainOcid, String displayName) { + List modelSummaries = listDigitalTwinModelSummaries(iotDomainOcid, displayName); + return modelSummaries.stream().map(ms -> getDigitalTwinModel(ms)).toList(); + } + + /** + * get gets DigitalTwinModel in the specified IoTDomainSummary, with the + * specified displayName, if there are no matches returns null + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public DigitalTwinModel getDigitalTwinModel(@NonNull IotDomainSummary iotDomainSummary, + @NonNull String displayName) { + return getDigitalTwinModel(iotDomainSummary.getId(), displayName); + } + + /** + * get gets DigitalTwinModel in the specified IoTDomain, with the specified + * displayName, if there are no matches returns null + * + * @param iotDomain + * @param displayName + * @return + */ + public DigitalTwinModel getDigitalTwinModel(@NonNull IotDomain iotDomain, @NonNull String displayName) { + return getDigitalTwinModel(iotDomain.getId(), displayName); + + } + + /** + * get gets DigitalTwinModel in the specified IoTDomain, with the specified + * displayName, if there are no matches returns null + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public DigitalTwinModel getDigitalTwinModel(@NonNull String iotDomainOcid, @NonNull String displayName) { + List digitalTwinModelSummaries = listDigitalTwinModelSummaries(iotDomainOcid, + displayName); + if (digitalTwinModelSummaries.isEmpty()) { + return null; + } + return getDigitalTwinModel(digitalTwinModelSummaries.getFirst()); + } + + /** + * get gets DigitalTwinModel from the specified DigitalTwinModelSummary + * + * @param digitalTwinModelSummary + * @return + */ + public DigitalTwinModel getDigitalTwinModel(@NonNull DigitalTwinModelSummary digitalTwinModelSummary) { + GetDigitalTwinModelResponse resp = iotClient.getDigitalTwinModel( + GetDigitalTwinModelRequest.builder().digitalTwinModelId(digitalTwinModelSummary.getId()).build()); + return resp.getDigitalTwinModel(); + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinAdapterSummaries(iotDomainSummary.getId()); + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull IotDomain iotDomain) { + return listDigitalTwinAdapterSummaries(iotDomain.getId()); + + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull String iotDomainOcid) { + return listDigitalTwinAdapterSummaries(iotDomainOcid, null); + + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinAdapterSummaries(iotDomainSummary.getId(), displayName); + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomain + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull IotDomain iotDomain, + String displayName) { + return listDigitalTwinAdapterSummaries(iotDomain.getId(), displayName); + + } + + /** + * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull String iotDomainOcid, + String displayName) { + ListDigitalTwinAdaptersRequest.Builder requestBuilder = ListDigitalTwinAdaptersRequest.builder() + .iotDomainId(iotDomainOcid); + if (displayName != null) { + requestBuilder.displayName(displayName); + } + Iterable digitalTwinAdapterSummaries = iotClient.getPaginators() + .listDigitalTwinAdaptersRecordIterator(requestBuilder.build()); + return StreamSupport.stream(digitalTwinAdapterSummaries.spliterator(), false).toList(); + } + + /** + * get a list of all DigitalTwinAdapter in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinAdapters(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinAdapters(iotDomainSummary.getId()); + } + + /** + * get a list of all DigitalTwinAdapter in the specified IoTDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinAdapters(@NonNull IotDomain iotDomain) { + return listDigitalTwinAdapters(iotDomain.getId()); + + } + + /** + * get a list of all DigitalTwinAdapter in the specified IoTDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinAdapters(@NonNull String iotDomainOcid) { + return listDigitalTwinAdapters(iotDomainOcid, null); + + } + + /** + * get a list of all DigitalTwinAdapter in the specified IoTDomainSummary, if + * displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public List listDigitalTwinAdapters(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinAdapters(iotDomainSummary.getId(), displayName); + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName + * is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ + public List listDigitalTwinAdapters(@NonNull IotDomain iotDomain, String displayName) { + return listDigitalTwinAdapters(iotDomain.getId(), displayName); + + } + + /** + * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName + * is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinAdapters(@NonNull String iotDomainOcid, String displayName) { + List modelSummaries = listDigitalTwinAdapterSummaries(iotDomainOcid, displayName); + return modelSummaries.stream().map(ms -> getDigitalTwinAdapter(ms)).toList(); + } + + /** + * get the DigitalTwinAdapter in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull IotDomainSummary iotDomainSummary, + @NonNull String displayName) { + return getDigitalTwinAdapter(iotDomainSummary.getId(), displayName); + } + + /** + * get the DigitalTwinAdapter in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomain + * @param displayName + * @return + */ + public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull IotDomain iotDomain, @NonNull String displayName) { + return getDigitalTwinAdapter(iotDomain.getId(), displayName); + + } + + /** + * get the DigitalTwinAdapter in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull String iotDomainOcid, @NonNull String displayName) { + List digitalTwinAdapterSummaries = listDigitalTwinAdapterSummaries(iotDomainOcid, + displayName); + if (digitalTwinAdapterSummaries.isEmpty()) { + return null; + } + return getDigitalTwinAdapter(digitalTwinAdapterSummaries.getFirst()); + } + + /** + * get the DigitalTwinAdapter from the specified summary + * + * @param digitalTwinAdapterSummary + * @return + */ + public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull DigitalTwinAdapterSummary digitalTwinAdapterSummary) { + GetDigitalTwinAdapterResponse resp = iotClient.getDigitalTwinAdapter( + GetDigitalTwinAdapterRequest.builder().digitalTwinAdapterId(digitalTwinAdapterSummary.getId()).build()); + return resp.getDigitalTwinAdapter(); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceSummaries( + @NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstanceSummaries(iotDomainSummary.getId()); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain) { + return listDigitalTwinInstanceSummaries(iotDomain.getId()); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid) { + return listDigitalTwinInstanceSummaries(iotDomainOcid, null); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinInstanceSummaries(iotDomainSummary.getId(), displayName); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, + String displayName) { + return listDigitalTwinInstanceSummaries(iotDomain.getId(), displayName); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + String displayName) { + ListDigitalTwinInstancesRequest.Builder requestBuilder = ListDigitalTwinInstancesRequest.builder() + .iotDomainId(iotDomainOcid); + if (displayName != null) { + requestBuilder.displayName(displayName); + } + Iterable digitalTwinInstanceSummaries = iotClient.getPaginators() + .listDigitalTwinInstancesRecordIterator(requestBuilder.build()); + return StreamSupport.stream(digitalTwinInstanceSummaries.spliterator(), false).toList(); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstances(iotDomainSummary.getId()); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomain iotDomain) { + return listDigitalTwinInstances(iotDomain.getId()); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstances(@NonNull String iotDomainOcid) { + return listDigitalTwinInstances(iotDomainOcid, null); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary, if + * displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinInstances(iotDomainSummary.getId(), displayName); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, String displayName) { + return listDigitalTwinInstances(iotDomain.getId(), displayName); + + } + + /** + * get a list of all DigitalTwinInstanceSummary in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull String iotDomainOcid, String displayName) { + List modelSummaries = listDigitalTwinInstanceSummaries(iotDomainOcid, displayName); + return modelSummaries.stream().map(ms -> getDigitalTwinInstance(ms)).toList(); + } + + /** + * get the DigitalTwinInstance in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public DigitalTwinInstance getDigitalTwinInstance(@NonNull IotDomainSummary iotDomainSummary, + @NonNull String displayName) { + return getDigitalTwinInstance(iotDomainSummary.getId(), displayName); + } + + /** + * get the DigitalTwinInstance in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomain + * @param displayName + * @return + */ + public DigitalTwinInstance getDigitalTwinInstance(@NonNull IotDomain iotDomain, @NonNull String displayName) { + return getDigitalTwinInstance(iotDomain.getId(), displayName); + + } + + /** + * get the DigitalTwinAdapter in the specified IotDomain with the displayName, + * returns null of there are no matches + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public DigitalTwinInstance getDigitalTwinInstance(@NonNull String iotDomainOcid, @NonNull String displayName) { + List digitalTwinInstanceSummaries = listDigitalTwinInstanceSummaries(iotDomainOcid, + displayName); + if (digitalTwinInstanceSummaries.isEmpty()) { + return null; + } + return getDigitalTwinInstance(digitalTwinInstanceSummaries.getFirst()); + } + + /** + * get the DigitalTwinInstance from the specified summary + * + * @param digitalTwinAdapterSummary + * @return + */ + public DigitalTwinInstance getDigitalTwinInstance(@NonNull DigitalTwinInstanceSummary digitalTwinInstanceSummary) { + GetDigitalTwinInstanceResponse resp = iotClient.getDigitalTwinInstance(GetDigitalTwinInstanceRequest.builder() + .digitalTwinInstanceId(digitalTwinInstanceSummary.getId()).build()); + return resp.getDigitalTwinInstance(); + } + + /** + * gets a map of name / value pairs for the latest data for the specified + * DigitalTwinInstance. Note that it's up to the caller to know what type of + * data each key represents and to convert that into an appropriate object + * + * @param digitalTwinInstanceSummary + * @return + */ + public Map getDigitalTwinInstanceContent( + @NonNull DigitalTwinInstanceSummary digitalTwinInstanceSummary) { + return getDigitalTwinInstanceContent(digitalTwinInstanceSummary.getId()); + } + + /** + * gets a map of name / value pairs for the latest data for the specified + * DigitalTwinInstance. Note that it's up to the caller to know what type of + * data each key represents and to convert that into an appropriate object + * + * @param digitalTwinInstance + * @return + */ + public Map getDigitalTwinInstanceContent(@NonNull DigitalTwinInstance digitalTwinInstance) { + return getDigitalTwinInstanceContent(digitalTwinInstance.getId()); + } + + /** + * gets a map of name / value pairs for the latest data for the specified + * DigitalTwinInstance. Note that it's up to the caller to know what type of + * data each key represents and to convert that into an appropriate object + * + * @param digitalTwinInstanceOcid + * @return + */ + public Map getDigitalTwinInstanceContent(@NonNull String digitalTwinInstanceOcid) { + GetDigitalTwinInstanceContentRequest request = GetDigitalTwinInstanceContentRequest.builder() + .digitalTwinInstanceId(digitalTwinInstanceOcid).build(); + GetDigitalTwinInstanceContentResponse resp = iotClient.getDigitalTwinInstanceContent(request); + return resp.getMap(); + } + + public DigitalTwinInstance createDigitalTwinInstance(@NonNull IotDomain iotDomain, @NonNull String displayName, + @NonNull Secret vaultSecret, String externalKey, String description, DigitalTwinModel digitalTwinModel, + DigitalTwinAdapter digitalTwinAdapter) { + return createDigitalTwinInstance(iotDomain.getId(), displayName, vaultSecret.getId(), externalKey, description, + (digitalTwinModel == null ? null : digitalTwinModel.getId()), + (digitalTwinAdapter == null ? null : digitalTwinAdapter.getId())); + } + + public DigitalTwinInstance createDigitalTwinInstance(@NonNull String iotDomainOcid, @NonNull String displayName, + @NonNull String authOcid, String externalKey, String description, String digitalTwinModelOcid, + String digitalTwinAdapterOcid) { + CreateDigitalTwinInstanceDetails.Builder detailsBuilder = CreateDigitalTwinInstanceDetails.builder() + .iotDomainId(iotDomainOcid).displayName(displayName).authId(authOcid); + if (externalKey != null) { + detailsBuilder.externalKey(externalKey); + } + if (description != null) { + detailsBuilder.description(description); + } + if (digitalTwinModelOcid != null) { + detailsBuilder.digitalTwinModelId(digitalTwinModelOcid); + } + if (digitalTwinAdapterOcid != null) { + detailsBuilder.digitalTwinAdapterId(digitalTwinAdapterOcid); + } + CreateDigitalTwinInstanceRequest request = CreateDigitalTwinInstanceRequest.builder() + .createDigitalTwinInstanceDetails(detailsBuilder.build()).build(); + CreateDigitalTwinInstanceResponse resp = iotClient.createDigitalTwinInstance(request); + return resp.getDigitalTwinInstance(); + } + + public boolean deleteDigitalTwinInstance(@NonNull DigitalTwinInstanceSummary digitalTwinInstanceSummary) { + return deleteDigitalTwinInstance(digitalTwinInstanceSummary.getId()); + } + + public boolean deleteDigitalTwinInstance(@NonNull DigitalTwinInstance digitalTwinInstance) { + return deleteDigitalTwinInstance(digitalTwinInstance.getId()); + } + + private boolean deleteDigitalTwinInstance(String digitalTwinInstanceOcid) { + DeleteDigitalTwinInstanceRequest request = DeleteDigitalTwinInstanceRequest.builder() + .digitalTwinInstanceId(digitalTwinInstanceOcid).build(); + DeleteDigitalTwinInstanceResponse resp = iotClient.deleteDigitalTwinInstance(request); + return resp.get__httpStatusCode__() == HttpStatus.SC_OK; + } + +} From 8c4507a4f9642ce0d6b3a1097202603b9250314b Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:21:42 +0000 Subject: [PATCH 03/10] make the auth provider generic to assist in later changes to add more provider types --- .../timg/oci/authentication/AuthenticationProcessor.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/authentication/AuthenticationProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/authentication/AuthenticationProcessor.java index 434253e..10c6bf7 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/authentication/AuthenticationProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/authentication/AuthenticationProcessor.java @@ -52,7 +52,7 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on public class AuthenticationProcessor { - private final ConfigFileAuthenticationDetailsProvider provider; + private final AuthenticationDetailsProvider provider; @Getter @Setter private String regionName; @@ -84,12 +84,14 @@ public AuthenticationProcessor(@NonNull String providerName) throws IllegalArgum public AuthenticationProcessor(@NonNull String providerName, String regionName) throws IllegalArgumentException, IOException { // get and save the provider away - provider = new ConfigFileAuthenticationDetailsProvider(providerName); + ConfigFileAuthenticationDetailsProvider configFileProvider = new ConfigFileAuthenticationDetailsProvider( + providerName); if (regionName != null) { this.regionName = regionName; } else { - this.regionName = provider.getRegion().getRegionId(); + this.regionName = configFileProvider.getRegion().getRegionId(); } + this.provider = configFileProvider; } /** From 516f30e164e80dc2a1fa17b6daf2da994b70765a Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Wed, 11 Feb 2026 15:50:10 +0000 Subject: [PATCH 04/10] various updates to cover the core vault / secrets / versions --- .../.classpath | 9 +- .../.factorypath | 40 +- oci-java-sdk-simple-wrappers-testing/pom.xml | 4 +- .../timg/demo/examples/vault/TestVault.java | 315 +++ oci-java-sdk-simple-wrappers/.classpath | 13 +- oci-java-sdk-simple-wrappers/.factorypath | 28 +- .../.settings/org.eclipse.jdt.core.prefs | 7 +- oci-java-sdk-simple-wrappers/ReadME.md | 15 + oci-java-sdk-simple-wrappers/pom.xml | 26 +- .../oracle/timg/oci/vault/VaultProcessor.java | 2006 +++++++++++++++++ 10 files changed, 2411 insertions(+), 52 deletions(-) create mode 100644 oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java create mode 100644 oci-java-sdk-simple-wrappers/ReadME.md create mode 100644 oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java diff --git a/oci-java-sdk-simple-wrappers-testing/.classpath b/oci-java-sdk-simple-wrappers-testing/.classpath index 6fe96f9..0b9f24c 100644 --- a/oci-java-sdk-simple-wrappers-testing/.classpath +++ b/oci-java-sdk-simple-wrappers-testing/.classpath @@ -14,20 +14,21 @@ + - - + - + + @@ -43,8 +44,8 @@ - + diff --git a/oci-java-sdk-simple-wrappers-testing/.factorypath b/oci-java-sdk-simple-wrappers-testing/.factorypath index e6eef8b..e5823d2 100644 --- a/oci-java-sdk-simple-wrappers-testing/.factorypath +++ b/oci-java-sdk-simple-wrappers-testing/.factorypath @@ -1,22 +1,19 @@ - - - - - - - + + + + - - - + + + - - + + @@ -37,14 +34,18 @@ + - - - - - - - + + + + + + + + + + @@ -54,6 +55,5 @@ - diff --git a/oci-java-sdk-simple-wrappers-testing/pom.xml b/oci-java-sdk-simple-wrappers-testing/pom.xml index 065ff01..a2a914b 100644 --- a/oci-java-sdk-simple-wrappers-testing/pom.xml +++ b/oci-java-sdk-simple-wrappers-testing/pom.xml @@ -8,8 +8,8 @@ OciTesting UTF-8 - 1.0.1 - 1.0.9 + 1.1.0 + 1.0.13 17 ${maven.compiler.source} diff --git a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java new file mode 100644 index 0000000..c5182ec --- /dev/null +++ b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java @@ -0,0 +1,315 @@ +package com.oracle.timg.demo.examples.vault; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.stream.Collectors; + +import com.oracle.bmc.identity.model.Compartment; +import com.oracle.bmc.keymanagement.model.Key; +import com.oracle.bmc.keymanagement.model.KeySummary; +import com.oracle.bmc.keymanagement.model.KeyVersion; +import com.oracle.bmc.keymanagement.model.Vault; +import com.oracle.bmc.vault.model.Secret; +import com.oracle.bmc.vault.model.SecretGenerationContext; +import com.oracle.bmc.vault.model.SecretVersion; +import com.oracle.timg.oci.authentication.AuthenticationProcessor; +import com.oracle.timg.oci.identity.IdentityProcessor; +import com.oracle.timg.oci.vault.VaultProcessor; + +import timgutilities.textio.ChoiceDescription; +import timgutilities.textio.ChoiceDescriptionData; +import timgutilities.textio.TextIOUtils; +import timgutilities.textio.TextIOUtils.NUM_TYPE; + +public class TestVault { + public static void main(String args[]) throws IllegalArgumentException, Exception { + TextIOUtils.doOutput("Configuring OCI connection"); + AuthenticationProcessor authenticationProcessor = new AuthenticationProcessor("DEFAULT"); + IdentityProcessor identityProcessor = new IdentityProcessor(authenticationProcessor); + VaultProcessor vaultProcessor = new VaultProcessor(authenticationProcessor); + String compartmentPath = TextIOUtils.getString("Please enter the compartment path to operate in", + "/domain-specialists/tim.graves"); + Compartment compartment = identityProcessor.locateCompartmentByPath(compartmentPath); + if (compartment == null) { + TextIOUtils.doOutput("Can't locate compartment " + compartmentPath + ", cannot continue"); + System.exit(0); + } + TextIOUtils.doOutput("OCID of " + compartmentPath + " is " + compartment.getId()); + List vaults = vaultProcessor.listVaults(compartment); + if (vaults.isEmpty()) { + TextIOUtils.doOutput("No vaults found in compartment, cannot continue"); + return; + } + ChoiceDescriptionData vaultCdd = new ChoiceDescriptionData<>( + vaults.stream().map(vault -> new ChoiceDescription(vault.getDisplayName(), vault)).toList()); + Vault vault = TextIOUtils.getParamChoice("Please chose the vault", vaultCdd); + TextIOUtils.doOutput("You chose vault " + vault.getDisplayName()); + List keySummaries = vaultProcessor.listKeySummaries(vault); + if (keySummaries.isEmpty()) { + TextIOUtils.doOutput("No key found in vault, cannot continue"); + return; + } + ChoiceDescriptionData keySummaryCdd = new ChoiceDescriptionData<>(keySummaries.stream() + .map(keySummary -> new ChoiceDescription(keySummary.getDisplayName(), keySummary)) + .toList()); + KeySummary keySummary = TextIOUtils.getParamChoice("Please chose the key", keySummaryCdd); + TextIOUtils.doOutput("You chose key summary " + keySummary.getDisplayName()); + Key key = vaultProcessor.getKey(vault, keySummary); + TextIOUtils.doOutput("The summary is for key " + key.toString()); + List keyVersions = vaultProcessor.listKeyVersions(vault, key, null); + if (keyVersions.isEmpty()) { + TextIOUtils.doOutput("No versions found for key, cannot continue"); + return; + } + ChoiceDescriptionData keyVersionCdd = new ChoiceDescriptionData<>(keyVersions.stream() + .map(keyVersion -> new ChoiceDescription(keyVersion.toString(), keyVersion)).toList()); + KeyVersion keyVersion = TextIOUtils.getParamChoice("Please chose the key version", keyVersionCdd); + TextIOUtils.doOutput("You chose key version " + keyVersion.toString()); + + List secrets = vaultProcessor.listSecrets(vault); + + ChoiceDescriptionData secretCdd = new ChoiceDescriptionData<>( + secrets.stream().map(secret -> new ChoiceDescription(secret.getSecretName(), secret)).toList()); + Secret secret = TextIOUtils.getParamChoice("Please chose the secret", secretCdd); + TextIOUtils.doOutput("You chose secret " + secret.toString()); + + SecretVersion secretVersion = listAndChoseSecretVersion(vaultProcessor, secret); + TextIOUtils.doOutput("You chose secret version " + secretVersion.toString()); + TextIOUtils.doOutput("getting contents of current version"); + + String secretVersionContents = vaultProcessor.getSecretContents(secretVersion); + TextIOUtils.doOutput("The secret version contents are " + secretVersionContents); + + SecretVersion secretVersionCurrent = vaultProcessor.getSecretVersionCurrent(secret); + TextIOUtils.doOutput("Current version of secret is " + secretVersionCurrent); + SecretVersion secretVersionLatest = vaultProcessor.getSecretVersionLatest(secret); + TextIOUtils.doOutput("Latest version of secret is " + secretVersionLatest); + List secretVersionsPending = vaultProcessor.listSecretVersionsPending(secret); + TextIOUtils.doOutput("Pending versions of secret is " + + secretVersionsPending.stream().map(sv -> "V " + sv.getVersionNumber() + "(" + sv.getStages() + ")") + .collect(Collectors.joining("\n"))); + List secretVersionsDeleted = vaultProcessor.listSecretVersionsDeleted(secret); + TextIOUtils.doOutput("Deprecated versions of secret are " + + secretVersionsDeleted.stream().map(sv -> "V " + sv.getVersionNumber() + "(" + sv.getStages() + ")") + .collect(Collectors.joining("\n"))); + + Secret testSecret = null; + SecretVersion testSecretVersionRetrieved = null; + SecretVersion updatedSecretVersion = null; + if (TextIOUtils.getYN("Do you want to test creating a secret using the vault & key you identified above ?", + false)) { + if (TextIOUtils.getYN("Do you want to test creating a manually specified secret?", false)) { + String testSecretName = TextIOUtils.getString("Please enter the secret name"); + String testSecretVersionContents = TextIOUtils.getString("Please enter the secrets initial contents"); + String testSecretVersionName = TextIOUtils + .getString("Please enter the secrets initial version name (or empty string for no name)", ""); + if (testSecretVersionName.isEmpty()) { + testSecretVersionName = null; + } + String testSecretDescription = TextIOUtils + .getString("Please enter the secrets initial description (or empty string for no name)", ""); + if (testSecretDescription.isEmpty()) { + testSecretDescription = null; + } + testSecret = vaultProcessor.createSecretManual(compartment.getId(), testSecretName, key.getId(), + vault.getId(), testSecretVersionContents, testSecretVersionName, testSecretDescription); + testSecretVersionRetrieved = vaultProcessor.getSecretVersionCurrent(testSecret); + String testSecretVersionRetrievedContents = vaultProcessor + .getSecretContents(testSecretVersionRetrieved); + TextIOUtils.doOutput("You created the secret " + testSecret.toString()); + TextIOUtils.doOutput("It's current version is " + testSecretVersionRetrieved.toString()); + TextIOUtils.doOutput("It's current version contents is " + testSecretVersionRetrievedContents); + } else if (TextIOUtils.getYN("Do you want to test creating a generated pass phrase secret?", false)) { + String testSecretName = TextIOUtils.getString("Please enter the secret name"); + int testSecretLength = TextIOUtils.getInt("Please enter the secrets length contents", + NUM_TYPE.AT_OR_ABOVE, 14, 128); + String testSecretDescription = TextIOUtils + .getString("Please enter the secrets initial description (or empty string for no name)", ""); + if (testSecretDescription.isEmpty()) { + testSecretDescription = null; + } + testSecret = vaultProcessor.createSecretGeneratedPassphrase(compartment.getId(), testSecretName, + key.getId(), vault.getId(), testSecretLength, testSecretDescription, null); + testSecretVersionRetrieved = vaultProcessor.getSecretVersionCurrent(testSecret); + String testSecretVersionRetrievedContents = vaultProcessor + .getSecretContents(testSecretVersionRetrieved); + TextIOUtils.doOutput("You created the secret " + testSecret.toString()); + TextIOUtils.doOutput("It's current version is " + testSecretVersionRetrieved.toString()); + TextIOUtils.doOutput("It's current version contents is " + testSecretVersionRetrievedContents); + } + } + // check for it still being in the creating state + if (testSecret != null) { + while (!testSecret.getLifecycleState().equals(Secret.LifecycleState.Active)) { + TextIOUtils.doOutput("Secret is not active, waiting 10 secs before retry"); + Thread.sleep(10000); + testSecret = vaultProcessor.getSecret(testSecret.getId()); + } + } + TextIOUtils.doOutput("Loading versions of secret"); + SecretVersion initialSecretVersion = listAndChoseSecretVersion(vaultProcessor, testSecret); + String initialSecretVersionContents = vaultProcessor.getSecretContents(initialSecretVersion); + TextIOUtils.doOutput("Version is " + initialSecretVersion.toString()); + TextIOUtils.doOutput("Content is " + initialSecretVersionContents); + if (testSecret != null) { + if (TextIOUtils.getYN("Do you want to test creating a secret version of the secret you just created ?", + false)) { + Secret updateSecret; + SecretGenerationContext secretGenerationContextRetrieved = testSecret.getSecretGenerationContext(); + if (secretGenerationContextRetrieved != null) { + TextIOUtils.doOutput( + "Secret generation details are " + testSecret.getSecretGenerationContext().toString()); + } else { + TextIOUtils.doOutput("Secret generation details are not present, probabaly manuall entered"); + + } + if (!testSecret.getIsAutoGenerationEnabled()) { + String updateSecretContents = TextIOUtils.getString("Please enter the new contents for the secret"); + String updateSecretName = TextIOUtils.getString( + "Please enter the name for the secret version (or empty string for no name)", ""); + if (updateSecretName.isEmpty()) { + updateSecretName = null; + } + String updateSecretDescription = TextIOUtils + .getString("Please enter the secrets new description (or empty string for no name)", ""); + if (updateSecretDescription.isEmpty()) { + updateSecretDescription = null; + } + boolean setToCurrent = TextIOUtils + .getYN("Do you want to make this the current version (Y) or pending (N)", true); + if (setToCurrent) { + updateSecret = vaultProcessor.createSecretVersionManualAsCurrent(testSecret.getId(), + updateSecretContents, updateSecretName, updateSecretDescription); + } else { + updateSecret = vaultProcessor.createSecretVersionManualAsPending(testSecret.getId(), + updateSecretContents, updateSecretName, updateSecretDescription); + } + // get the latest version we just created + updatedSecretVersion = vaultProcessor.getSecretVersionLatest(updateSecret); + TextIOUtils.doOutput("You updated the secret " + updateSecret.toString()); + TextIOUtils.doOutput("It's latest version is " + updatedSecretVersion.toString()); + TextIOUtils.doOutput("Waiting up to 120 seconds for secret to become active"); + Boolean updatesSecretStatus = vaultProcessor.waitForSecretToBecomeActive(updateSecret); + if (updatesSecretStatus == null) { + TextIOUtils.doOutput("Secret is not found or update times out"); + } else if (updatesSecretStatus) { + TextIOUtils.doOutput("Secret update timed out"); + } else { + String updatedSecretVersionRetrievedContents = vaultProcessor + .getSecretContents(updatedSecretVersion); + TextIOUtils.doOutput("Secret updated, it's current version contents is " + + updatedSecretVersionRetrievedContents); + } + } else { + TextIOUtils.doOutput("Secret was generated"); + String updateSecretDescription = TextIOUtils + .getString("Please enter the secrets new description (or empty string for no name)", ""); + if (updateSecretDescription.isEmpty()) { + updateSecretDescription = null; + } + // at least for now there seems to be no way (or at least nothing documented) on + // making a generated secret version pending (vs current) - this is despite the + // oci cli and web ui supporting creating a pending version + updateSecret = vaultProcessor.createSecretVersionGeneratedCurrent(testSecret.getId(), + updateSecretDescription); + // get the latest version we just created + updatedSecretVersion = vaultProcessor.getSecretVersionLatest(updateSecret); + TextIOUtils.doOutput("You updated the secret " + updateSecret.toString()); + TextIOUtils.doOutput("It's latest version is " + updatedSecretVersion.toString()); + TextIOUtils.doOutput("Waiting up to 120 seconds for secret to become active"); + Boolean updatesSecretStatus = vaultProcessor.waitForSecretToBecomeActive(updateSecret); + if (updatesSecretStatus == null) { + TextIOUtils.doOutput("Secret is not found or update times out"); + } else if (updatesSecretStatus) { + TextIOUtils.doOutput("Secret update timed out"); + } else { + String updatedSecretVersionRetrievedContents = vaultProcessor + .getSecretContents(updatedSecretVersion); + TextIOUtils.doOutput("Secret updated, it's current version contents is " + + updatedSecretVersionRetrievedContents); + } + } + TextIOUtils.doOutput("Loading versions of secret"); + SecretVersion newSecretVersion = listAndChoseSecretVersion(vaultProcessor, testSecret); + String newSecretVersionContents = vaultProcessor.getSecretContents(newSecretVersion); + TextIOUtils.doOutput("Version is " + newSecretVersion.toString()); + TextIOUtils.doOutput("Content is " + newSecretVersionContents); + } + } + if (updatedSecretVersion != null) { + if (updatedSecretVersion.getStages().contains(SecretVersion.Stages.Pending)) { + if (TextIOUtils.getYN("New version is pending, do you want to make it current", true)) { + Secret updatedSecret = vaultProcessor.updateSecretVersionPendingToCurrent(updatedSecretVersion); + updatedSecretVersion = vaultProcessor.getSecretVersionCurrent(updatedSecretVersion.getSecretId()); + TextIOUtils.doOutput("new version details are " + updatedSecretVersion); + Boolean updatesSecretStatus = vaultProcessor.waitForSecretToBecomeActive(updatedSecret); + if (updatesSecretStatus == null) { + TextIOUtils.doOutput("Secret is not found or update times out"); + } else if (updatesSecretStatus) { + TextIOUtils.doOutput("Secret update timed out"); + } else { + String updatedSecretVersionRetrievedContents = vaultProcessor + .getSecretContents(updatedSecretVersion); + TextIOUtils.doOutput("Secret updated, it's current version contents is " + + updatedSecretVersionRetrievedContents); + } + + TextIOUtils + .doOutput("Secret contents is " + vaultProcessor.getSecretContents(updatedSecretVersion)); + } else { + TextIOUtils.doOutput("OK, leaving new version as pending"); + } + } else { + TextIOUtils.doOutput("New version is already current, can't promote it from pending "); + } + } + if (updatedSecretVersion != null) { + if (updatedSecretVersion.getStages().contains(SecretVersion.Stages.Current)) { + TextIOUtils.doOutput("Can't delete just created version as it's current"); + } else { + if (TextIOUtils.getYN("Do you want to delete the non current secret version you just created ?", + true)) { + ZonedDateTime manualSecretDeletionDTG = TextIOUtils.getISOZonedDateTimeTimeZone( + "Please enter the deletion time (should be at least one day in the future!)", + ZoneId.systemDefault(), LocalDateTime.now().plusDays(1).plusMinutes(10), + LocalDateTime.now().plusWeeks(4)); + boolean deleteTestSecretVersionResp = vaultProcessor.scheduleSecretVersionDeletion(testSecret, + updatedSecretVersion.getVersionNumber(), manualSecretDeletionDTG); + TextIOUtils.doOutput("Delete request reponse was " + deleteTestSecretVersionResp); + } + } + } + if (testSecret != null) { + if (TextIOUtils.getYN("Do you want to delete the manual contents secret you just created ?", true)) { + ZonedDateTime manualSecretDeletionDTG = TextIOUtils.getISOZonedDateTimeTimeZone( + "Please enter the deletion time (should be at least one day in the future!)", + ZoneId.systemDefault(), LocalDateTime.now().plusDays(1).plusMinutes(10), + LocalDateTime.now().plusWeeks(4)); + boolean deleteManualSecretResp = vaultProcessor.scheduleSecretDeletion(testSecret, + manualSecretDeletionDTG); + TextIOUtils.doOutput("Delete request reponse was " + deleteManualSecretResp); + } + } + } + + /** + * @param vaultProcessor + * @param secret + * @return + * @throws IOException + */ + private static SecretVersion listAndChoseSecretVersion(VaultProcessor vaultProcessor, Secret secret) + throws IOException { + List secretVersions = vaultProcessor.listSecretVersions(secret); + ChoiceDescriptionData secretVersionCdd = new ChoiceDescriptionData<>(secretVersions.stream() + .map(secretVersion -> new ChoiceDescription( + "Version " + secretVersion.getVersionNumber() + "(" + secretVersion.getStages() + ")", + secretVersion)) + .toList()); + SecretVersion secretVersion = TextIOUtils.getParamChoice("Please chose the secret version", secretVersionCdd); + return secretVersion; + } +} diff --git a/oci-java-sdk-simple-wrappers/.classpath b/oci-java-sdk-simple-wrappers/.classpath index 7a9a105..96c6daa 100644 --- a/oci-java-sdk-simple-wrappers/.classpath +++ b/oci-java-sdk-simple-wrappers/.classpath @@ -26,7 +26,7 @@ - + @@ -36,5 +36,16 @@ + + + + + + + + + + + diff --git a/oci-java-sdk-simple-wrappers/.factorypath b/oci-java-sdk-simple-wrappers/.factorypath index 5f841c5..6bbed36 100644 --- a/oci-java-sdk-simple-wrappers/.factorypath +++ b/oci-java-sdk-simple-wrappers/.factorypath @@ -1,15 +1,15 @@ - - + + - + - - - + + + @@ -36,13 +36,15 @@ - - - - - - - + + + + + + + + + diff --git a/oci-java-sdk-simple-wrappers/.settings/org.eclipse.jdt.core.prefs b/oci-java-sdk-simple-wrappers/.settings/org.eclipse.jdt.core.prefs index cf2cd45..29f57ea 100644 --- a/oci-java-sdk-simple-wrappers/.settings/org.eclipse.jdt.core.prefs +++ b/oci-java-sdk-simple-wrappers/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,9 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 -org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=enabled org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=17 +org.eclipse.jdt.core.compiler.source=21 diff --git a/oci-java-sdk-simple-wrappers/ReadME.md b/oci-java-sdk-simple-wrappers/ReadME.md new file mode 100644 index 0000000..3774a4f --- /dev/null +++ b/oci-java-sdk-simple-wrappers/ReadME.md @@ -0,0 +1,15 @@ +# OCI Simple Wrappers + +## What are they +These classes provide a simpler way to use the OCI Java SDK, in particular it handles things like retrieving data without the caller needing to know the details of the core OCI Java SDK but instead to focus more on the objects themselves. In some cases that may mean that additional API calls need to be made to the OCI server. Please be aware of the limitations below. + +## Why were they created +The OCI Java SDK is very powerful, but it is very much structured around REST API concepts, for example retrieving a set of objects requires the users to construct requests using the request builders which don't use the returned objects (and in some cases there are multiple levels of builder / details / needed to create the request). Then after submitting a request to manage pagination (or at least to use a pagination class in the API) and so on. These classes make it a lot easier to interact with OCI, and to reduce the complexity of the code you'd need to write, though they do however reduce the flexibility. Fortunately however it's perfectly possible to mix these classes and the underlying OCI Java SDK for the situations where you do need the additional flexibility, and are willing to do the additional work to use the OCI Java SDK directly. + +## Limitations (deliberate and otherwise) +This code does not even attempt to provide access to the full API, it was created to make my life easier when doing things that I needed. Usually this is retrieving information, and creating some resources. This however does not mean that all associated resources can be created, for example with the IoT service you are able to retrieve most information around IoT Domain Groups, IoT Domains etc, but you can't currently create them as that tends to be a one off exercise, usually done by terraform or similar. However for tasks that may well be done programmatically there is usually support for doing so (e.g. creating a IoT Digital Twin Instance) + +## License +These are covered by the **The Universal Permissive License (UPL), Version 1.0** There is absolutely no support or responsibility taken for any of this code, you use totally at your own risk. + +Copyright (c) 2026 Oracle and/or its affiliates. \ No newline at end of file diff --git a/oci-java-sdk-simple-wrappers/pom.xml b/oci-java-sdk-simple-wrappers/pom.xml index ea153f6..dd96ff2 100644 --- a/oci-java-sdk-simple-wrappers/pom.xml +++ b/oci-java-sdk-simple-wrappers/pom.xml @@ -1,4 +1,4 @@ - com.oracle.timg.demo oci-java-sdk-simple-wrappers ocicore - 1.0.1 + 1.1.0 - jar - 21 - 21 + jar + 21 + 21 UTF-8 - 3.77.0 + 3.80.1 1.18.42 2.0.7 21 @@ -87,14 +87,22 @@ SOFTWARE. --> com.oracle.oci.sdk oci-java-sdk-identity + + com.oracle.oci.sdk + oci-java-sdk-keymanagement + com.oracle.oci.sdk oci-java-sdk-vault - com.oracle.oci.sdk - oci-java-sdk-iot - + com.oracle.oci.sdk + oci-java-sdk-secrets + + + com.oracle.oci.sdk + oci-java-sdk-iot + org.projectlombok diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java new file mode 100644 index 0000000..45af66f --- /dev/null +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java @@ -0,0 +1,2006 @@ +/*Copyright (c) 2026 Oracle and/or its affiliates. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any +person obtaining a copy of this software, associated documentation and/or data +(collectively the "Software"), free of charge and under any and all copyright +rights in the Software, and any and all patent rights owned or freely +licensable by each licensor hereunder covering either (i) the unmodified +Software as contributed to or provided by such licensor, or (ii) the Larger +Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +one is included with the Software (each a "Larger Work" to which the Software +is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create +derivative works of, display, perform, and distribute the Software and make, +use, sell, offer for sale, import, export, have made, and have sold the +Software and the Larger Work(s), and to sublicense the foregoing rights on +either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at +a minimum a reference to the UPL must be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ +package com.oracle.timg.oci.vault; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Base64; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.StreamSupport; + +import org.apache.http.HttpStatus; + +import com.oracle.bmc.identity.model.Compartment; +import com.oracle.bmc.keymanagement.KmsManagementClient; +import com.oracle.bmc.keymanagement.KmsVaultClient; +import com.oracle.bmc.keymanagement.model.Key; +import com.oracle.bmc.keymanagement.model.KeySummary; +import com.oracle.bmc.keymanagement.model.KeyVersion; +import com.oracle.bmc.keymanagement.model.KeyVersionSummary; +import com.oracle.bmc.keymanagement.model.Vault; +import com.oracle.bmc.keymanagement.model.VaultSummary; +import com.oracle.bmc.keymanagement.requests.GetKeyRequest; +import com.oracle.bmc.keymanagement.requests.GetKeyVersionRequest; +import com.oracle.bmc.keymanagement.requests.GetVaultRequest; +import com.oracle.bmc.keymanagement.requests.ListKeyVersionsRequest; +import com.oracle.bmc.keymanagement.requests.ListKeysRequest; +import com.oracle.bmc.keymanagement.requests.ListVaultsRequest; +import com.oracle.bmc.keymanagement.responses.GetKeyResponse; +import com.oracle.bmc.keymanagement.responses.GetKeyVersionResponse; +import com.oracle.bmc.keymanagement.responses.GetVaultResponse; +import com.oracle.bmc.secrets.SecretsClient; +import com.oracle.bmc.secrets.model.Base64SecretBundleContentDetails; +import com.oracle.bmc.secrets.requests.GetSecretBundleRequest; +import com.oracle.bmc.secrets.responses.GetSecretBundleResponse; +import com.oracle.bmc.vault.VaultsClient; +import com.oracle.bmc.vault.model.Base64SecretContentDetails; +import com.oracle.bmc.vault.model.BytesGenerationContext; +import com.oracle.bmc.vault.model.CreateSecretDetails; +import com.oracle.bmc.vault.model.PassphraseGenerationContext; +import com.oracle.bmc.vault.model.ScheduleSecretDeletionDetails; +import com.oracle.bmc.vault.model.ScheduleSecretVersionDeletionDetails; +import com.oracle.bmc.vault.model.Secret; +import com.oracle.bmc.vault.model.SecretGenerationContext; +import com.oracle.bmc.vault.model.SecretSummary; +import com.oracle.bmc.vault.model.SecretVersion; +import com.oracle.bmc.vault.model.SecretVersionSummary; +import com.oracle.bmc.vault.model.SshKeyGenerationContext; +import com.oracle.bmc.vault.model.UpdateSecretDetails; +import com.oracle.bmc.vault.requests.CancelSecretDeletionRequest; +import com.oracle.bmc.vault.requests.CancelSecretVersionDeletionRequest; +import com.oracle.bmc.vault.requests.CreateSecretRequest; +import com.oracle.bmc.vault.requests.GetSecretRequest; +import com.oracle.bmc.vault.requests.GetSecretVersionRequest; +import com.oracle.bmc.vault.requests.ListSecretVersionsRequest; +import com.oracle.bmc.vault.requests.ListSecretsRequest; +import com.oracle.bmc.vault.requests.ListSecretsRequest.SortBy; +import com.oracle.bmc.vault.requests.ScheduleSecretDeletionRequest; +import com.oracle.bmc.vault.requests.ScheduleSecretVersionDeletionRequest; +import com.oracle.bmc.vault.requests.UpdateSecretRequest; +import com.oracle.bmc.vault.responses.CancelSecretDeletionResponse; +import com.oracle.bmc.vault.responses.CancelSecretVersionDeletionResponse; +import com.oracle.bmc.vault.responses.CreateSecretResponse; +import com.oracle.bmc.vault.responses.GetSecretResponse; +import com.oracle.bmc.vault.responses.GetSecretVersionResponse; +import com.oracle.bmc.vault.responses.ScheduleSecretDeletionResponse; +import com.oracle.bmc.vault.responses.ScheduleSecretVersionDeletionResponse; +import com.oracle.bmc.vault.responses.UpdateSecretResponse; +import com.oracle.timg.oci.authentication.AuthenticationProcessor; + +import lombok.Getter; +import lombok.NonNull; + +public class VaultProcessor { + private final AuthenticationProcessor authProcessor; + @Getter + private final KmsVaultClient kmsVaultClient; + @Getter + private final VaultsClient vaultClient; + @Getter + private final SecretsClient secretsClient; + + /** + * Creates a VCNProcessor which will use the supplied AuthenticationProcessor + * + * @param authProcessor + * @throws IllegalArgumentException + * @throws IOException + */ + public VaultProcessor(AuthenticationProcessor authProcessor) throws IllegalArgumentException, IOException { + this.authProcessor = authProcessor; + kmsVaultClient = KmsVaultClient.builder().region(this.authProcessor.getRegionName()) + .build(this.authProcessor.getProvider()); + vaultClient = VaultsClient.builder().region(this.authProcessor.getRegionName()) + .build(this.authProcessor.getProvider()); + secretsClient = SecretsClient.builder().region(this.authProcessor.getRegionName()) + .build(this.authProcessor.getProvider()); + } + + /** + * allows you to change the region form the default provided by the + * AuthenticationProcessor + * + * @param regionName + */ + public void setRegion(@NonNull String regionName) { + kmsVaultClient.setRegion(regionName); + vaultClient.setRegion(regionName); + } + + /** + * + * get the active vault summaries in the tenancy root in the active state only + * + * @param parentCompartmentOcid - must not be null + * @return + */ + public List listVaultSummaries() { + return listVaultSummaries(authProcessor.getTenancyOCID(), null, VaultSummary.LifecycleState.Active); + } + + /** + * + * get the active vault summaries in the compartment with the specified ocid in + * the active state only + * + * @param parentCompartment - must not be null + * @return + */ + public List listVaultSummaries(@NonNull Compartment parentCompartment) { + return listVaultSummaries(parentCompartment.getId()); + } + + /** + * + * get the active vault summaries in the compartment with the specified ocid in + * the active state only 720/4.8 + * + * @param parentCompartmentOcid - must not be null + * @return + */ + public List listVaultSummaries(@NonNull String parentCompartmentOcid) { + return listVaultSummaries(parentCompartmentOcid, null, VaultSummary.LifecycleState.Active); + } + + /** + * + * get the active vault summaries in the compartment with the specified ocid in + * the active state and if it's not null matching the displayName only + * + * @param parentCompartmentOcid - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaultSummaries(@NonNull String parentCompartmentOcid, String displayName) { + return listVaultSummaries(parentCompartmentOcid, displayName, VaultSummary.LifecycleState.Active); + } + + /** + * + * get the vault summaries in the compartment with the specified ocid in the + * specified state if null in all states) and with the displayName (if null all + * names) + * + * @param parentCompartment - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaultSummaries(@NonNull Compartment parentCompartment, String displayName, + VaultSummary.LifecycleState livecycleState) { + return listVaultSummaries(parentCompartment.getId(), displayName, livecycleState); + } + + /** + * + * get the vault summaries in the compartment with the specified ocid in the + * specified state only + * + * @param parentCompartmentOcid - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaultSummaries(@NonNull String parentCompartmentOcid, String displayName, + VaultSummary.LifecycleState livecycleState) { + ListVaultsRequest.Builder requestBuilder = ListVaultsRequest.builder().compartmentId(parentCompartmentOcid) + .sortBy(ListVaultsRequest.SortBy.Displayname).sortOrder(ListVaultsRequest.SortOrder.Asc); + Iterable vaultsResponse = kmsVaultClient.getPaginators() + .listVaultsRecordIterator(requestBuilder.build()); + return StreamSupport.stream(vaultsResponse.spliterator(), false).filter((vaultSummary) -> { + return (livecycleState == null) || (vaultSummary.getLifecycleState() == livecycleState); + }).filter((vaultsummary) -> { + return ((displayName == null) || (vaultsummary.getDisplayName().equals(displayName))); + }).toList(); + } + + /** + * + * get the active vaults in the tenancy root in the active state only + * + * @param parentCompartmentOcid - must not be null + * @return + */ + public List listVaults() { + return listVaults(authProcessor.getTenancyOCID(), null, Vault.LifecycleState.Active); + } + + /** + * + * get the active vaults in the compartment with the specified ocid in the + * active state only + * + * @param parentCompartment - must not be null + * @return + */ + public List listVaults(@NonNull Compartment parentCompartment) { + return listVaults(parentCompartment.getId()); + } + + /** + * + * get the active vaults in the compartment with the specified ocid in the + * active state only + * + * @param parentCompartmentOcid - must not be null + * @return + */ + public List listVaults(@NonNull String parentCompartmentOcid) { + return listVaults(parentCompartmentOcid, null, Vault.LifecycleState.Active); + } + + /** + * + * get the active vault in the compartment with the specified ocid in the active + * state and if it's not null matching the displayName only + * + * @param parentCompartment - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaults(@NonNull Compartment parentCompartment, String displayName) { + return listVaults(parentCompartment.getId(), displayName, Vault.LifecycleState.Active); + } + + /** + * + * get the active vaults in the compartment with the specified ocid in the + * active state and if it's not null matching the displayName only + * + * @param parentCompartmentOcid - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaults(@NonNull String parentCompartmentOcid, String displayName) { + return listVaults(parentCompartmentOcid, displayName, Vault.LifecycleState.Active); + } + + /** + * + * get the vaults in the compartment with the specified ocid in the specified + * state if null in all states) and with the displayName (if null all names) + * + * @param parentCompartment - must not be null + * @param displayName the name to look for (or all if not specified) + * @return + */ + public List listVaults(@NonNull Compartment parentCompartment, String displayName, + Vault.LifecycleState livecycleState) { + return listVaults(parentCompartment.getId(), displayName, livecycleState); + } + + /** + * + * get the vaults in the compartment with the specified ocid in the specified + * state and matching the displayName if it's non null + * + * @param parentCompartmentOcid - must not be null + * @return + */ + public List listVaults(@NonNull String parentCompartmentOcid, String displayName, + Vault.LifecycleState lifecycleState) { + VaultSummary.LifecycleState vaultSummaryLifecycleState = lifecycleState == null ? null + : VaultSummary.LifecycleState.create(lifecycleState.getValue()); + List vaultSummaries = listVaultSummaries(parentCompartmentOcid, displayName, + vaultSummaryLifecycleState); + return vaultSummaries.stream().map(vs -> getVaultFromVaultSummary(vs)).toList(); + } + + public Vault getVaultFromVaultSummary(@NonNull VaultSummary vaultSummary) { + return getVaultFromVaultSummary(vaultSummary.getId()); + } + + public Vault getVaultFromVaultSummary(@NonNull String vaultSummaryOcid) { + return getVault(vaultSummaryOcid); + } + + public Vault getVault(@NonNull String vaultOcid) { + GetVaultRequest request = GetVaultRequest.builder().vaultId(vaultOcid).build(); + GetVaultResponse response = kmsVaultClient.getVault(request); + return response.getVault(); + } + + private Map perVaultKmsManagementClient = new HashMap<>(); + + private KmsManagementClient getKmsManagementClientForVault(@NonNull VaultSummary vaultSummary) { + return getKmsManagementClientForVault(vaultSummary.getId(), vaultSummary.getManagementEndpoint()); + } + + private KmsManagementClient getKmsManagementClientForVault(@NonNull Vault vault) { + return getKmsManagementClientForVault(vault.getId(), vault.getManagementEndpoint()); + } + + private KmsManagementClient getKmsManagementClientForVault(@NonNull String vaultOcid, + @NonNull String vaultEndpoint) { + if (perVaultKmsManagementClient.containsKey(vaultOcid)) { + return perVaultKmsManagementClient.get(vaultOcid); + } else { + KmsManagementClient kmc = KmsManagementClient.builder().endpoint(vaultEndpoint) + .build(this.authProcessor.getProvider()); + this.perVaultKmsManagementClient.put(vaultOcid, kmc); + return kmc; + } + } + + /** + * return all master keys in the vault which are enabled and the same + * compartment as the vault + * + * @param vault + * @return + */ + public List listKeySummaries(@NonNull VaultSummary vaultSummary) { + return listKeySummaries(vaultSummary, vaultSummary.getCompartmentId(), null, KeySummary.LifecycleState.Enabled); + } + + /** + * return all master keys in the vault which are enabled and the same + * compartment as the vault and have the specified name, of all if displayName + * is null + * + * @param vault + * @return + */ + public List listKeySummaries(@NonNull VaultSummary vaultSummary, String displayName) { + return listKeySummaries(vaultSummary, vaultSummary.getCompartmentId(), displayName, + KeySummary.LifecycleState.Enabled); + } + + public List listKeySummaries(@NonNull VaultSummary vaultSummary, @NonNull String parentCompartmentOcid, + String displayName, KeySummary.LifecycleState lifecycleState) { + // this is vault specific, so we need one for each vault + KmsManagementClient kmsManagementClient = getKmsManagementClientForVault(vaultSummary); + return listKeySummaries(kmsManagementClient, parentCompartmentOcid, displayName, lifecycleState); + } + + private List listKeySummaries(@NonNull KmsManagementClient kmsManagementClient, + @NonNull String parentCompartmentOcid, String displayName, KeySummary.LifecycleState lifecycleState) { + + // keys are in a compartment and a vault, the key management client is + // associated to the vault. + ListKeysRequest request = ListKeysRequest.builder().compartmentId(parentCompartmentOcid) + .sortBy(ListKeysRequest.SortBy.Displayname).sortOrder(ListKeysRequest.SortOrder.Asc).build(); + // this is vault specific, so we need one for each vault + Iterable response = kmsManagementClient.getPaginators().listKeysRecordIterator(request); + return StreamSupport.stream(response.spliterator(), false).filter((keySummary) -> { + return ((lifecycleState == null) || (keySummary.getLifecycleState() == lifecycleState)); + }).filter((vaultsummary) -> { + return ((displayName == null) || (vaultsummary.getDisplayName().equals(displayName))); + }).toList(); + } + + /** + * return all master keys in the vault which are enabled and the same + * compartment as the vault + * + * @param vault + * @return + */ + public List listKeySummaries(@NonNull Vault vault) { + return listKeySummaries(vault, vault.getCompartmentId(), null, KeySummary.LifecycleState.Enabled); + } + + /** + * return all master keys in the vault which are enabled and the same + * compartment as the vault and have the specified name, of all if displayName + * is null + * + * @param vault + * @return + */ + public List listKeySummaries(@NonNull Vault vault, String displayName) { + return listKeySummaries(vault, vault.getCompartmentId(), displayName, KeySummary.LifecycleState.Enabled); + } + + public List listKeySummaries(@NonNull Vault vault, @NonNull String parentCompartmentOcid, + String displayName, KeySummary.LifecycleState lifecycleState) { + KmsManagementClient kmsManagementClient = getKmsManagementClientForVault(vault); + return listKeySummaries(kmsManagementClient, parentCompartmentOcid, displayName, lifecycleState); + } + + public Key getKey(@NonNull VaultSummary vaultSummary, @NonNull KeySummary keySummary) { + return getKey(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keySummary.getId()); + } + + public Key getKey(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid) { + return getKey(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keyOcid); + } + + public Key getKey(@NonNull Vault vault, @NonNull KeySummary keySummary) { + return getKey(vault.getId(), vault.getManagementEndpoint(), keySummary.getId()); + } + + public Key getKey(@NonNull Vault vault, @NonNull String keyOcid) { + return getKey(vault.getId(), vault.getManagementEndpoint(), keyOcid); + } + + public Key getKey(@NonNull String vaultOcid, @NonNull String vaultEndpoint, @NonNull String keyOcid) { + GetKeyRequest request = GetKeyRequest.builder().keyId(keyOcid).build(); + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); + GetKeyResponse response = kmvManagementClient.getKey(request); + return response.getKey(); + } + + public List listKeyVersionSummaries(@NonNull VaultSummary vaultSummary, + @NonNull KeySummary keySummary) { + return listKeyVersionSummaries(vaultSummary, keySummary.getId(), KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull VaultSummary vaultSummary, @NonNull Key key) { + return listKeyVersionSummaries(vaultSummary, key.getId(), KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull VaultSummary vaultSummary, + @NonNull String keyOcid) { + return listKeyVersionSummaries(vaultSummary, keyOcid, KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull Vault vault, @NonNull KeySummary keySummary) { + return listKeyVersionSummaries(vault, keySummary, KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull Vault vault, @NonNull Key key) { + return listKeyVersionSummaries(vault, key.getId(), KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull Vault vault, @NonNull String keyOcid) { + return listKeyVersionSummaries(vault, keyOcid, KeyVersionSummary.LifecycleState.Enabled); + } + + public List listKeyVersionSummaries(@NonNull VaultSummary vaultSummary, + @NonNull KeySummary keySummary, @NonNull KeyVersionSummary.LifecycleState lifecycleState) { + return listKeyVersionSummaries(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keySummary.getId(), + lifecycleState); + } + + public List listKeyVersionSummaries(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid, + @NonNull KeyVersionSummary.LifecycleState lifecycleState) { + return listKeyVersionSummaries(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keyOcid, + lifecycleState); + } + + public List listKeyVersionSummaries(@NonNull Vault vault, @NonNull KeySummary keySummary, + @NonNull KeyVersionSummary.LifecycleState lifecycleState) { + return listKeyVersionSummaries(vault.getId(), vault.getManagementEndpoint(), keySummary.getId(), + lifecycleState); + } + + public List listKeyVersionSummaries(@NonNull Vault vault, @NonNull String keyOcid, + @NonNull KeyVersionSummary.LifecycleState lifecycleState) { + return listKeyVersionSummaries(vault.getId(), vault.getManagementEndpoint(), keyOcid, lifecycleState); + } + + public List listKeyVersionSummaries(@NonNull String vaultOcid, @NonNull String vaultEndpoint, + @NonNull String keyId, KeyVersionSummary.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); + return listKeyVersionSummaries(kmvManagementClient, keyId, lifecycleState); + } + + private List listKeyVersionSummaries(@NonNull KmsManagementClient kmsManagementClient, + @NonNull String keyId, KeyVersionSummary.LifecycleState lifecycleState) { + ListKeyVersionsRequest request = ListKeyVersionsRequest.builder().keyId(keyId) + .sortBy(ListKeyVersionsRequest.SortBy.Timecreated).sortOrder(ListKeyVersionsRequest.SortOrder.Desc) + .build(); + // this is vault specific, so we need one for each vault + Iterable response = kmsManagementClient.getPaginators() + .listKeyVersionsRecordIterator(request); + return StreamSupport.stream(response.spliterator(), false).filter((keyVersionSummary) -> { + return ((lifecycleState == null) || (keyVersionSummary.getLifecycleState() == lifecycleState)); + }).toList(); + } + + public List listKeyVersions(@NonNull VaultSummary vaultSummary, @NonNull KeySummary keySummary) { + return listKeyVersions(vaultSummary, keySummary.getId(), KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersions(@NonNull VaultSummary vaultSummary, @NonNull Key key) { + return listKeyVersions(vaultSummary, key.getId(), KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersions(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid) { + return listKeyVersions(vaultSummary, keyOcid, KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersions(@NonNull Vault vault, @NonNull KeySummary keySummary) { + return listKeyVersions(vault, keySummary, KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersions(@NonNull Vault vault, @NonNull Key key) { + return listKeyVersions(vault, key.getId(), KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersion(@NonNull Vault vault, @NonNull String keyOcid) { + return listKeyVersions(vault, keyOcid, KeyVersion.LifecycleState.Enabled); + } + + public List listKeyVersions(@NonNull VaultSummary vaultSummary, @NonNull KeySummary keySummary, + KeyVersion.LifecycleState lifecycleState) { + return listKeyVersions(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keySummary.getId(), + lifecycleState); + } + + public List listKeyVersions(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + return listKeyVersions(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keyOcid, lifecycleState); + } + + public List listKeyVersions(@NonNull Vault vault, @NonNull KeySummary keySummary, + KeyVersion.LifecycleState lifecycleState) { + return listKeyVersions(vault.getId(), vault.getManagementEndpoint(), keySummary.getId(), lifecycleState); + } + + public List listKeyVersions(@NonNull Vault vault, @NonNull Key key, + KeyVersion.LifecycleState lifecycleState) { + return listKeyVersions(vault.getId(), vault.getManagementEndpoint(), key.getId(), lifecycleState); + } + + public List listKeyVersions(@NonNull Vault vault, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + return listKeyVersions(vault.getId(), vault.getManagementEndpoint(), keyOcid, lifecycleState); + } + + public List listKeyVersions(@NonNull String vaultOcid, @NonNull String vaultEndpoint, String keyId, + KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); + return listKeyVersions(kmvManagementClient, keyId, lifecycleState); + } + + private List listKeyVersions(@NonNull KmsManagementClient kmsManagementClient, @NonNull String keyId, + KeyVersion.LifecycleState lifecycleState) { + KeyVersionSummary.LifecycleState kvsLifecycleState = lifecycleState == null ? null + : KeyVersionSummary.LifecycleState.create(lifecycleState.getValue()); + List keyVersionSummaries = listKeyVersionSummaries(kmsManagementClient, keyId, + kvsLifecycleState); + return keyVersionSummaries.stream() + .map(keyVersionSummary -> getKeyVersion(kmsManagementClient, keyId, keyVersionSummary.getId())) + .toList(); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param vault + * @param key + * @param lifecycleState + * @return + */ + public KeyVersion getKeyVersion(@NonNull Vault vault, @NonNull Key key, KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vault.getId(), + vault.getManagementEndpoint()); + return getKeyVersion(kmvManagementClient, key.getId(), lifecycleState); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param vaultSummary + * @param key + * @param lifecycleState + * @return + */ + public KeyVersion getKeyVersion(@NonNull VaultSummary vaultSummary, @NonNull Key key, + KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultSummary.getId(), + vaultSummary.getManagementEndpoint()); + return getKeyVersion(kmvManagementClient, key.getId(), lifecycleState); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param vault + * @param keyOcid + * @param lifecycleState + * @return + */ + public KeyVersion getKeyVersion(@NonNull Vault vault, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vault.getId(), + vault.getManagementEndpoint()); + return getKeyVersion(kmvManagementClient, keyOcid, lifecycleState); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param vaultSummary + * @param keyOcid + * @param lifecycleState + * @return + */ + public KeyVersion getKeyVersion(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultSummary.getId(), + vaultSummary.getManagementEndpoint()); + return getKeyVersion(kmvManagementClient, keyOcid, lifecycleState); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param vaultOcid + * @param vaultEndpoint + * @param keyOcid + * @param lifecycleState + * @return + */ + public KeyVersion getKeyVersion(@NonNull String vaultOcid, @NonNull String vaultEndpoint, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); + return getKeyVersion(kmvManagementClient, keyOcid, lifecycleState); + } + + /** + * gets the first keyVersion of the key in the lifecycle state or if that's null + * the first version in the returned list (which is sorted by creation time in + * descending order, do this basically means the most recent version) + * + * @param kmvManagementClient + * @param keyOcid + * @param lifecycleState + * @return + */ + private KeyVersion getKeyVersion(@NonNull KmsManagementClient kmvManagementClient, @NonNull String keyOcid, + KeyVersion.LifecycleState lifecycleState) { + KeyVersionSummary.LifecycleState kvsLifecycleState = lifecycleState == null ? null + : KeyVersionSummary.LifecycleState.create(lifecycleState.getValue()); + List keyVersionSummaries = listKeyVersionSummaries(kmvManagementClient, keyOcid, + kvsLifecycleState); + if (keyVersionSummaries.size() == 0) { + return null; + } else { + return getKeyVersion(kmvManagementClient, keyOcid, keyVersionSummaries.getFirst().getId()); + } + } + + /** + * get the key version from it's OCID in the specified key / vault + * + * @param vaultSummary + * @param key + * @param keyVersionOcid + * @return + */ + public KeyVersion getKeyVersion(@NonNull VaultSummary vaultSummary, @NonNull Key key, + @NonNull String keyVersionOcid) { + return getKeyVersion(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), key.getId(), keyVersionOcid); + } + + /** + * get the key version from it's OCID in the specified key / vault + * + * @param vault + * @param key + * @param keyVersionOcid + * @return + */ + public KeyVersion getKeyVersion(@NonNull Vault vault, @NonNull Key key, @NonNull String keyVersionOcid) { + return getKeyVersion(vault.getId(), vault.getManagementEndpoint(), key.getId(), keyVersionOcid); + } + + /** + * get the key version from it's OCID in the specified key / vault (as per the + * vault id / endpoint) + * + * @param vaultOcid + * @param vaultEndpoint + * @param key + * @param keyVersionOcid + * @return + */ + public KeyVersion getKeyVersion(@NonNull String vaultOcid, @NonNull String vaultEndpoint, @NonNull String keyOcid, + @NonNull String keyVersionOcid) { + KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); + return getKeyVersion(kmvManagementClient, keyOcid, keyVersionOcid); + } + + /** + * get the key version from it's OCID in the specified key / vault ar per the + * provided management client + * + * @param kmvManagementClient + * @param key + * @param keyVersionOcid + * @return + */ + private KeyVersion getKeyVersion(@NonNull KmsManagementClient kmvManagementClient, @NonNull String keyOcid, + @NonNull String keyVersionOcid) { + GetKeyVersionRequest request = GetKeyVersionRequest.builder().keyId(keyOcid).keyVersionId(keyVersionOcid) + .build(); + GetKeyVersionResponse response = kmvManagementClient.getKeyVersion(request); + return response.getKeyVersion(); + } + + /** + * Get a list of the active secret summaries in the specified compartment, if + * any of the vault / name are specified then the returned list if filtered + * against those. The result is ordered by the secret name + * + * @param compartmentOcid + * @param vaultOcid + * @param name + * @return + */ + public List listSecretSummaries(@NonNull String compartmentOcid, String vaultOcid, String name) { + return listSecretSummaries(compartmentOcid, vaultOcid, name, SecretSummary.LifecycleState.Active); + } + + /** + * Get a list of the secret summaries in the specified compartment, if any of + * the vault / name / lifecycle state are specified then the returned list if + * filtered against those. The result is ordered by the secret name + * + * @param compartmentOcid + * @param vaultOcid + * @param name + * @param lifecycleState + * @return + */ + public List listSecretSummaries(@NonNull String compartmentOcid, String vaultOcid, String name, + SecretSummary.LifecycleState lifecycleState) { + ListSecretsRequest.Builder requestBuilder = ListSecretsRequest.builder().compartmentId(compartmentOcid) + .sortBy(SortBy.Name).sortOrder(ListSecretsRequest.SortOrder.Asc); + if (vaultOcid != null) { + requestBuilder.vaultId(vaultOcid); + } + if (name != null) { + requestBuilder.name(name); + } + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } + Iterable response = vaultClient.getPaginators() + .listSecretsRecordIterator(requestBuilder.build()); + return StreamSupport.stream(response.spliterator(), false).toList(); + } + + /** + * Get a list of the active secret summaries in the specified vault against + * that. The result is ordered by the secret name. The secrets must be in the + * same compartment as the vault + * + * @param vaultSummary + * @param name + * @return + */ + public List listSecrets(@NonNull VaultSummary vaultSummary) { + return listSecrets(vaultSummary, null); + } + + /** + * Get a list of the active secret summaries in the specified vault against + * that. The result is ordered by the secret name. The secrets must be in the + * same compartment as the vault + * + * @param vault + * @param name + * @return + */ + public List listSecrets(@NonNull Vault vault) { + return listSecrets(vault, null); + } + + /** + * Get a list of the active secret summaries in the specified vault, if name is + * non null then the returned list is filtered against that. The result is + * ordered by the secret name. The secrets must be in the same compartment as + * the vault + * + * @param vaultSummary + * @param name + * @return + */ + public List listSecrets(@NonNull VaultSummary vaultSummary, String name) { + return listSecrets(vaultSummary.getCompartmentId(), vaultSummary.getId(), name); + } + + /** + * Get a list of the active secret summaries in the specified vault, if name is + * non null then the returned list is filtered against that. The result is + * ordered by the secret name. The secrets must be in the same compartment as + * the vault + * + * @param vault + * @param name + * @return + */ + public List listSecrets(@NonNull Vault vault, String name) { + return listSecrets(vault.getCompartmentId(), vault.getId(), name); + } + + /** + * Get a list of the active secret summaries in the specified compartment, if + * any of the vault / name are specified then the returned list if filtered + * against those. The result is ordered by the secret name + * + * @param compartmentOcid + * @param vaultOcid + * @param name + * @return + */ + public List listSecrets(@NonNull String compartmentOcid, String vaultOcid, String name) { + return listSecrets(compartmentOcid, vaultOcid, name, Secret.LifecycleState.Active); + } + + /** + * Get a list of the secrets in the specified compartment, if any of the vault / + * name / lifecycle state are specified then the returned list if filtered + * against those. The result is ordered by the secret name + * + * @param compartmentOcid + * @param vaultOcid + * @param name + * @param lifecycleState + * @return + */ + public List listSecrets(@NonNull String compartmentOcid, String vaultOcid, String name, + Secret.LifecycleState lifecycleState) { + SecretSummary.LifecycleState secretSummaryLifecycleState = lifecycleState == null ? null + : SecretSummary.LifecycleState.create(lifecycleState.getValue()); + List secretSummaries = listSecretSummaries(compartmentOcid, vaultOcid, name, + secretSummaryLifecycleState); + return secretSummaries.stream().map(secretSummary -> getSecret(secretSummary)).toList(); + } + + /** + * gets the first secret in the provided vault with a matching name. Note that + * the secret must be in the same compartment as the vault + * + * @param vaultSummary + * @param name + * @return + */ + public Secret getSecret(@NonNull VaultSummary vaultSummary, @NonNull String name) { + return getSecret(vaultSummary.getCompartmentId(), vaultSummary.getId(), name); + } + + /** + * gets the first secret in the provided vault with a matching name. Note that + * the secret must be in the same compartment as the vault + * + * @param vault + * @param name + * @return + */ + public Secret getSecret(@NonNull Vault vault, @NonNull String name) { + return getSecret(vault.getCompartmentId(), vault.getId(), name); + } + + /** + * gets the **first** (as defined by name order ascending) active secret in the + * compartment with the given name, if vaultOcid is null allows for any vault + * + * @param compartmentOcid + * @param vaultOcid + * @param name + * @return + */ + public Secret getSecret(@NonNull String compartmentOcid, String vaultOcid, @NonNull String name) { + List secretSummaries = listSecretSummaries(compartmentOcid, vaultOcid, name, + SecretSummary.LifecycleState.Active); + if (secretSummaries.isEmpty()) { + return null; + } + return getSecret(secretSummaries.getFirst()); + } + + /** + * gets the secret from the summary + * + * @param secretSummary + * @return + */ + public Secret getSecret(@NonNull SecretSummary secretSummary) { + return getSecret(secretSummary.getId()); + } + + /** + * gets the secret by it's OCID + * + * @param secretOcid + * @return + */ + public Secret getSecret(@NonNull String secretOcid) { + GetSecretRequest request = GetSecretRequest.builder().secretId(secretOcid).build(); + GetSecretResponse response = vaultClient.getSecret(request); + return response.getSecret(); + } + + /** + * create a secret with an initial version containing bytes if + * generationTemplate is null this will use the Bytes512 template + * + * @param compartmentOcid + * @param name + * @param encryptionKeyOcid + * @param vaultOcid + * @param length + * @param secretDescription + * @param generationTemplate + * @return + */ + public Secret createSecretGeneratedBytes(@NonNull String compartmentOcid, @NonNull String name, + @NonNull String encryptionKeyOcid, @NonNull String vaultOcid, String secretDescription, + BytesGenerationContext.GenerationTemplate generationTemplate) { + + SecretGenerationContext generationContext = BytesGenerationContext.builder().generationTemplate( + generationTemplate == null ? BytesGenerationContext.GenerationTemplate.Bytes512 : generationTemplate) + .build(); + return createSecretGenerated(compartmentOcid, name, encryptionKeyOcid, vaultOcid, generationContext, + secretDescription); + } + + /** + * create a secret with an initial version containing a ssh key, if the + * generationTemplate is null use the Rsa3072 template + * + * @param compartmentOcid + * @param name + * @param encryptionKeyOcid + * @param vaultOcid + * @param length + * @param secretDescription + * @param generationTemplate + * @return + */ + public Secret createSecretGeneratedSSHKey(@NonNull String compartmentOcid, @NonNull String name, + @NonNull String encryptionKeyOcid, @NonNull String vaultOcid, String secretDescription, + SshKeyGenerationContext.GenerationTemplate generationTemplate) { + SecretGenerationContext generationContext = SshKeyGenerationContext.builder().generationTemplate( + generationTemplate == null ? SshKeyGenerationContext.GenerationTemplate.Rsa3072 : generationTemplate) + .build(); + return createSecretGenerated(compartmentOcid, name, encryptionKeyOcid, vaultOcid, generationContext, + secretDescription); + } + + /** + * create a secret with an initial version containing a random password using + * the passprase of the specified length. if generationTemplate is null will use + * the SecretsDefaultPassword template + * + * @param compartmentOcid + * @param name + * @param encryptionKeyOcid + * @param vaultOcid + * @param length + * @param secretDescription + * @return + */ + public Secret createSecretGeneratedPassphrase(@NonNull String compartmentOcid, @NonNull String name, + @NonNull String encryptionKeyOcid, @NonNull String vaultOcid, @NonNull Integer length, + String secretDescription, PassphraseGenerationContext.GenerationTemplate generationTemplate) { + SecretGenerationContext generationContext = PassphraseGenerationContext.builder() + .generationTemplate(generationTemplate == null + ? PassphraseGenerationContext.GenerationTemplate.SecretsDefaultPassword + : generationTemplate) + .passphraseLength(length).build(); + return createSecretGenerated(compartmentOcid, name, encryptionKeyOcid, vaultOcid, generationContext, + secretDescription); + } + + private Secret createSecretGenerated(@NonNull String compartmentOcid, @NonNull String name, + @NonNull String encryptionKeyOcid, @NonNull String vaultOcid, + @NonNull SecretGenerationContext generationContext, String secretDescription) { + CreateSecretDetails.Builder createSecretDetailsBuilder = CreateSecretDetails.builder() + .compartmentId(compartmentOcid).secretName(name).vaultId(vaultOcid).keyId(encryptionKeyOcid) + .enableAutoGeneration(true).secretGenerationContext(generationContext); + if (secretDescription != null) { + createSecretDetailsBuilder.description(secretDescription); + } + CreateSecretDetails createSecretDetails = createSecretDetailsBuilder.build(); + CreateSecretRequest request = CreateSecretRequest.builder().createSecretDetails(createSecretDetails).build(); + CreateSecretResponse response = vaultClient.createSecret(request); + return response.getSecret(); + } + + /** + * + * create a secret with an initial version containing the contents supplied by + * the caller. + * + * @param compartmentOcid + * @param name + * @param encryptionKeyOcid + * @param vaultOcid + * @param secretContents + * @param secretContentsVersionName if null will not be set + * @param secretDescription if null will not be set + * @return + */ + public Secret createSecretManual(@NonNull String compartmentOcid, @NonNull String name, + @NonNull String encryptionKeyOcid, @NonNull String vaultOcid, @NonNull String secretContents, + String secretContentsVersionName, String secretDescription) { + CreateSecretDetails.Builder createSecretDetailsBuilder = CreateSecretDetails.builder() + .compartmentId(compartmentOcid).secretName(name).vaultId(vaultOcid).keyId(encryptionKeyOcid) + .enableAutoGeneration(false); + if (secretDescription != null) { + createSecretDetailsBuilder.description(secretDescription); + } + String base64SecretContents = Base64.getEncoder().encodeToString(secretContents.getBytes()); + Base64SecretContentDetails.Builder base64SecretContentDetailsBuilder = Base64SecretContentDetails.builder() + .content(base64SecretContents); + if (secretContentsVersionName != null) { + base64SecretContentDetailsBuilder.name(secretContentsVersionName); + } + Base64SecretContentDetails base64SecretContentDetails = base64SecretContentDetailsBuilder.build(); + createSecretDetailsBuilder.secretContent(base64SecretContentDetails); + CreateSecretDetails createSecretDetails = createSecretDetailsBuilder.build(); + CreateSecretRequest request = CreateSecretRequest.builder().createSecretDetails(createSecretDetails).build(); + CreateSecretResponse response = vaultClient.createSecret(request); + return response.getSecret(); + } + + /** + * waits for the secret to become active, return null if there is no secret or + * an interruption, return true if it becomes active in the time window, or + * false if not. checkes every 10 seconds for upto 120 seconds + * + * @param secret + * @return + */ + public Boolean waitForSecretToBecomeActive(@NonNull Secret secret) { + return waitForSecretToBecomeActive(secret, 10, 120); + } + + /** + * waits for the secret to become active, return null if there is no secret or + * an interruption, return true if it becomes active in the time window, or + * false if not. checkes every 10 seconds for upto 120 seconds + * + * @param secret + * @return + */ + public Boolean waitForSecretToBecomeActive(@NonNull Secret secret, int secondsBetweenChecks, int secondsToWait) { + Secret secretToTest = secret; + int remainingSeconds = secondsToWait; + while ((remainingSeconds > 0) && (!secretToTest.getLifecycleState().equals(Secret.LifecycleState.Active))) { + remainingSeconds -= secondsBetweenChecks; + try { + Thread.sleep(secondsBetweenChecks); + } catch (InterruptedException e) { + return null; + } + secretToTest = getSecret(secret.getId()); + } + return secretToTest.getLifecycleState().equals(Secret.LifecycleState.Active); + } + + /** + * waits for the secret to become active, return null if there is no secret or + * an interruption, return true if it becomes active in the time window, or + * false if not + * + * @param secret + * @param secondsBetweenChecks + * @param secondsToWait + * @return + */ + public Boolean waitForSecretToBecomeActive(@NonNull String secretOcid, int secondsBetweenChecks, + int secondsToWait) { + Secret secretToTest = getSecret(secretOcid); + // if it's not there then give up + if (secretToTest == null) { + return null; + } + return waitForSecretToBecomeActive(secretToTest, secondsBetweenChecks, secondsToWait); + } + + /** + * waits for the secret to become active, return null if there is no secret or + * an interruption, return true if it becomes active in the time window, or + * false if not + * + * @param secretOcid + * @param secondsBetweenChecks + * @param secondsToWait + * @return + */ + public Boolean waitForSecretToBecomeActive(@NonNull String secretOcid) { + return waitForSecretToBecomeActive(secretOcid, 10, 120); + } + + public boolean scheduleSecretDeletion(@NonNull SecretSummary secretSummary, @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretDeletion(secretSummary.getId(), Date.from(deletionDTG.toInstant())); + } + + public boolean scheduleSecretDeletion(@NonNull Secret secret, @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretDeletion(secret.getId(), Date.from(deletionDTG.toInstant())); + } + + public boolean scheduleSecretDeletion(@NonNull String secretOcid, @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretDeletion(secretOcid, Date.from(deletionDTG.toInstant())); + } + + public boolean scheduleSecretDeletion(@NonNull SecretSummary secretSummary, @NonNull Date deletionDTG) { + return scheduleSecretDeletion(secretSummary.getId(), deletionDTG); + } + + public boolean scheduleSecretDeletion(@NonNull Secret secret, @NonNull Date deletionDTG) { + return scheduleSecretDeletion(secret.getId(), deletionDTG); + } + + public boolean scheduleSecretDeletion(@NonNull String secretOcid, @NonNull Date deletionDTG) { + ScheduleSecretDeletionDetails details = ScheduleSecretDeletionDetails.builder().timeOfDeletion(deletionDTG) + .build(); + ScheduleSecretDeletionRequest request = ScheduleSecretDeletionRequest.builder().secretId(secretOcid) + .scheduleSecretDeletionDetails(details).build(); + ScheduleSecretDeletionResponse response = vaultClient.scheduleSecretDeletion(request); + return response.get__httpStatusCode__() == HttpStatus.SC_OK; + } + + public boolean cancelSecretDeletion(@NonNull SecretSummary secretSummary) { + return cancelSecretDeletion(secretSummary.getId()); + } + + public boolean cancelSecretDeletion(@NonNull Secret secret) { + return cancelSecretDeletion(secret.getId()); + } + + public boolean cancelSecretDeletion(@NonNull String secretOcid) { + CancelSecretDeletionRequest request = CancelSecretDeletionRequest.builder().secretId(secretOcid).build(); + CancelSecretDeletionResponse response = vaultClient.cancelSecretDeletion(request); + return response.get__httpStatusCode__() == HttpStatus.SC_OK; + } + + /** + * lists all pending SecretVersionSummary for the provided secret + * + * @param secret + * @return + */ + public List listSecretVersionSummariesPending(@NonNull Secret secret) { + return listSecretVersionSummaries(secret, SecretVersionSummary.Stages.Pending); + } + + /** + * lists all pending SecretVersion for the provided secret + * + * @param secret + * @return + */ + public List listSecretVersionsPending(@NonNull Secret secret) { + return listSecretVersions(secret, SecretVersion.Stages.Pending); + } + + /** + * lists all deleted SecretVersionSummary for the provided secret + * + * @param secret + * @return + */ + public List listSecretVersionSummariesDeleted(@NonNull Secret secret) { + return listSecretVersionSummaries(secret, SecretVersionSummary.Stages.Deprecated); + } + + /** + * lists all deleted SecretVersionSummary for the provided secret + * + * @param secret + * @return + */ + public List listSecretVersionsDeleted(@NonNull Secret secret) { + return listSecretVersions(secret, SecretVersion.Stages.Deprecated); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersion getSecretVersionCurrent(@NonNull SecretSummary secretSummary) { + return getSecretVersionCurrent(secretSummary.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersion getSecretVersionCurrent(@NonNull Secret secret) { + return getSecretVersionCurrent(secret.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersion getSecretVersionCurrent(@NonNull String secretOcid) { + SecretVersionSummary secretVersionSummary = getSecretVersionSummaryCurrent(secretOcid); + if (secretVersionSummary == null) { + return null; + } + return getSecretVersion(secretVersionSummary); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersionSummary getSecretVersionSummaryCurrent(@NonNull SecretSummary secretSummary) { + return getSecretVersionSummaryCurrent(secretSummary.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersionSummary getSecretVersionSummaryCurrent(@NonNull Secret secret) { + return getSecretVersionSummaryCurrent(secret.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * current or null if there are no current versions + * + * @param secret + * @return + */ + public SecretVersionSummary getSecretVersionSummaryCurrent(@NonNull String secretOcid) { + List secretVersionSummaries = listSecretVersionSummaries(secretOcid, + SecretVersionSummary.Stages.Current); + if (secretVersionSummaries.isEmpty()) { + return null; + } + return secretVersionSummaries.getFirst(); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secretSummary + * @return + */ + public SecretVersionSummary getSecretVersionSummaryLatest(@NonNull SecretSummary secretSummary) { + return getSecretVersionSummaryLatest(secretSummary.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secret + * @return + */ + public SecretVersionSummary getSecretVersionSummaryLatest(@NonNull Secret secret) { + return getSecretVersionSummaryLatest(secret.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secretOcid + * @return + */ + public SecretVersionSummary getSecretVersionSummaryLatest(@NonNull String secretOcid) { + List secretVersionSummaries = listSecretVersionSummaries(secretOcid, + SecretVersionSummary.Stages.Latest); + if (secretVersionSummaries.isEmpty()) { + return null; + } + return secretVersionSummaries.getFirst(); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secretSummary + * @return + */ + public SecretVersion getSecretVersionLatest(@NonNull SecretSummary secretSummary) { + return getSecretVersionLatest(secretSummary.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secret + * @return + */ + public SecretVersion getSecretVersionLatest(@NonNull Secret secret) { + return getSecretVersionLatest(secret.getId()); + } + + /** + * Gets the **first** (most recent) secret version summary which is in the state + * latest or null if there are no versions + * + * @param secretOcid + * @return + */ + public SecretVersion getSecretVersionLatest(@NonNull String secretOcid) { + List secretVersionSummaries = listSecretVersionSummaries(secretOcid, + SecretVersionSummary.Stages.Latest); + if (secretVersionSummaries.isEmpty()) { + return null; + } + return getSecretVersion(secretVersionSummaries.getFirst()); + } + + /** + * returns a list of SecretVersionSummary for the secret. if lifecycleStage is + * not null limits the list to only versions where the version has a stage that + * matches the lifecycleStage. E.g. if the version has stages CURRENT and LATEST + * then both of those will have to be set, but just one or a different stage + * such as PENDING will not + * + * @param secretOcid + * @param lifecycleStage + * @return + */ + public List listSecretVersionSummaries(@NonNull Secret secret, + SecretVersionSummary.Stages... lifecycleStages) { + return listSecretVersionSummaries(secret.getId(), lifecycleStages); + } + + /** + * returns a list of SecretVersionSummary for the secret. if lifecycleStage is + * not null limits the list to only versions where the version has a stage that + * matches the lifecycleStage. E.g. if the version has stages CURRENT and LATEST + * then both of those will have to be set, but just one or a different stage + * such as PENDING will not + * + * @param secretOcid + * @param lifecycleStage + * @return + */ + public List listSecretVersionSummaries(@NonNull SecretSummary secretSummary, + SecretVersionSummary.Stages... lifecycleStages) { + return listSecretVersionSummaries(secretSummary.getId(), lifecycleStages); + } + + /** + * returns a list of SecretVersion for the secret. if lifecycleStage is not null + * limits the list to only versions where the version has a stage that matches + * all of the lifecycleStage. E.g. if the version has stages CURRENT and LATEST + * then both of those will have to be set, but just one or a different stage + * such as PENDING will not + * + * @param secretOcid + * @param lifecycleStage + * @return + */ + public List listSecretVersions(@NonNull Secret secret, SecretVersion.Stages... lifecycleStages) { + return listSecretVersions(secret.getId(), lifecycleStages); + } + + /** + * returns a list of SecretVersion for the secret. if lifecycleStage is not null + * limits the list to only versions where the version has a stage that matches + * all of the lifecycleStage. E.g. if the version has stages CURRENT and LATEST + * then both of those will have to be set, but just one or a different stage + * such as PENDING will not + * + * @param secretOcid + * @param lifecycleStage + * @return + */ + public List listSecretVersions(@NonNull String secretOcid, SecretVersion.Stages... lifecycleStages) { + SecretVersionSummary.Stages secretVersionLifecycleStages[]; + if (lifecycleStages == null) { + secretVersionLifecycleStages = null; + } else { + secretVersionLifecycleStages = new SecretVersionSummary.Stages[lifecycleStages.length]; + for (int i = 0; i < lifecycleStages.length; i++) { + secretVersionLifecycleStages[i] = SecretVersionSummary.Stages.create(lifecycleStages[i].getValue()); + } + } + List secretVersionSummaries = listSecretVersionSummaries(secretOcid, + secretVersionLifecycleStages); + return secretVersionSummaries.stream() + .map(secretVersionSummary -> getSecretVersion(secretVersionSummary.getSecretId(), + secretVersionSummary.getVersionNumber())) + .toList(); + } + + /** + * returns a list of SecretVersionSummary for the secret. if lifecycleStage is + * not null limits the list to only versions where the version has a stage that + * matches all of the lifecycleStage. E.g. if the lifecycleStages has stages + * CURRENT and LATEST then both of those will have to be set (any othewrs may or + * may not be present), but just one or a different stage such as PENDING will + * not, if lifecycleStages has only one value, say DELETED then versions with + * that will be returned even if they have other stage values as well. + * + * @param secretOcid + * @param lifecycleStage + * @return + */ + public List listSecretVersionSummaries(@NonNull String secretOcid, + SecretVersionSummary.Stages... lifecycleStages) { + ListSecretVersionsRequest request = ListSecretVersionsRequest.builder().secretId(secretOcid) + .sortBy(ListSecretVersionsRequest.SortBy.VersionNumber) + .sortOrder(ListSecretVersionsRequest.SortOrder.Desc).build(); + List stages = ((lifecycleStages == null) || (lifecycleStages.length == 0)) ? null + : Arrays.asList(lifecycleStages); + Iterable secretVersionSummaries = vaultClient.getPaginators() + .listSecretVersionsRecordIterator(request); + return StreamSupport.stream(secretVersionSummaries.spliterator(), false).filter((secretVersionSummary) -> { + return stages == null ? true : secretVersionSummary.getStages().containsAll(stages); + }).toList(); + } + + /** + * gets the secret version + * + * @param secret + * @param secretVersionNumber + * @return + */ + public SecretVersion getSecretVersion(@NonNull SecretVersionSummary secretVersionSummary) { + return getSecretVersion(secretVersionSummary.getSecretId(), secretVersionSummary.getVersionNumber()); + } + + /** + * gets the secret version + * + * @param secret + * @param secretVersionNumber + * @return + */ + public SecretVersion getSecretVersion(@NonNull Secret secret, @NonNull Long secretVersionNumber) { + return getSecretVersion(secret.getId(), secretVersionNumber); + } + + /** + * gets the secret version + * + * @param secretSummary + * @param secretVersionNumber + * @return + */ + public SecretVersion getSecretVersion(@NonNull SecretSummary secretSummary, @NonNull Long secretVersionNumber) { + return getSecretVersion(secretSummary.getId(), secretVersionNumber); + } + + /** + * gets the secret version + * + * @param secretOcid + * @param secretVersionNumber + * @return + */ + public SecretVersion getSecretVersion(@NonNull String secretOcid, @NonNull Long secretVersionNumber) { + GetSecretVersionRequest request = GetSecretVersionRequest.builder().secretId(secretOcid) + .secretVersionNumber(secretVersionNumber).build(); + GetSecretVersionResponse response = vaultClient.getSecretVersion(request); + return response.getSecretVersion(); + } + + /** + * gets the contents of the CURRENT version of the secret + * + * @param secretOcid + * @return + */ + public String getSecretContents(@NonNull String secretOcid) { + return getSecretContentsReal(secretOcid, null, null, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secretOcid + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull String secretOcid, @NonNull Long secretVersionNumber) { + return getSecretContentsReal(secretOcid, secretVersionNumber, null, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secret + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull SecretSummary secret, @NonNull Long secretVersionNumber) { + return getSecretContentsReal(secret.getId(), secretVersionNumber, null, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secret + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull Secret secret, @NonNull Long secretVersionNumber) { + return getSecretContentsReal(secret.getId(), secretVersionNumber, null, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secretOcid + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull String secretOcid, @NonNull String secretVersionName) { + return getSecretContentsReal(secretOcid, null, secretVersionName, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secret + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull SecretSummary secret, @NonNull String secretVersionName) { + return getSecretContentsReal(secret.getId(), null, secretVersionName, null); + } + + /** + * gets the contents of the specified version of the secret + * + * @param secret + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull Secret secret, @NonNull String secretVersionName) { + return getSecretContentsReal(secret.getId(), null, secretVersionName, null); + } + + /** + * gets the contents of the version of the secret in the specified stage + * + * @param secretOcid + * @param secretVersionNumber + * @return + */ + public String getSecretContents(@NonNull String secretOcid, @NonNull GetSecretBundleRequest.Stage stage) { + return getSecretContentsReal(secretOcid, null, null, stage); + } + + /** + * gets the contents of the version of the secret + * + * @param secretVersion + * @return + */ + public String getSecretContents(@NonNull SecretVersion secretVersion) { + return getSecretContentsReal(secretVersion.getSecretId(), secretVersion.getVersionNumber(), null, null); + } + + public String getSecretContents(@NonNull String secretOcid, Long secretVersionNumber, String secretVersionName, + SecretVersion.Stages stage) { + + GetSecretBundleRequest.Stage requestStage = stage == null ? null + : GetSecretBundleRequest.Stage.create(stage.getValue()); + return getSecretContentsReal(secretOcid, secretVersionNumber, secretVersionName, requestStage); + } + + /** + * Gets the secret contents. If all of secretVersionNumber, secretVersionName + * and stage are null the CURRENT version is returned. If one is set then the + * results will filter based on that. Only one of them should be set + * (unpredictable behaviour otherwise) + * + * @param secretOcid + * @param secretVersionNumber + * @param secretVersionName + * @param stage + * @return null if there isn't a match (e.g. secretVersionNumber is set but + * there is no version with that number) + */ + private String getSecretContentsReal(@NonNull String secretOcid, Long secretVersionNumber, String secretVersionName, + GetSecretBundleRequest.Stage stage) { + GetSecretBundleRequest.Builder getSecretBundleRequestBuilder = GetSecretBundleRequest.builder() + .secretId(secretOcid); + if (secretVersionNumber != null) { + getSecretBundleRequestBuilder.versionNumber(secretVersionNumber); + } + if (secretVersionName != null) { + getSecretBundleRequestBuilder.secretVersionName(secretVersionName); + } + if (stage != null) { + getSecretBundleRequestBuilder.stage(stage); + } + + GetSecretBundleRequest getSecretBundleRequest = getSecretBundleRequestBuilder.build(); + GetSecretBundleResponse response = secretsClient.getSecretBundle(getSecretBundleRequest); + if (response.getSecretBundle() == null) { + return null; + } + Base64SecretBundleContentDetails contentDetails = (Base64SecretBundleContentDetails) response.getSecretBundle() + .getSecretBundleContent(); + + String base64Content = contentDetails.getContent(); + byte[] decodedBytes = Base64.getDecoder().decode(base64Content); + return new String(decodedBytes); + } + + /** + * create a new version of the generated secret using the template specified + * when the origional was created and set the new version to be the current + * version, the description can be null if desired + * + * @param secretOcid + * @param secretDescription + * @return + */ + public Secret createSecretVersionGeneratedCurrent(@NonNull String secretOcid, String secretDescription) { + Secret secret = getSecret(secretOcid); + return createSecretVersionGeneratedCurrent(secret, secretDescription); + } + + /** + * create a new version of the generated secret using the template specified + * when the origional was created and set the new version to be the current + * version, the description can be null if desired + * + * @param secret + * @param secretDescription + * @return + */ + public Secret createSecretVersionGeneratedCurrent(@NonNull Secret secret, String secretDescription) { + return createSecretVersionGenerated(secret, Base64SecretContentDetails.Stage.Current, secretDescription); + } + + /** + * create a new version of the genrated secret, not tat at the moment there + * seems to be no way to set the stage gor generated secrets, this private to + * let me later change the code without breaking callers. + * + * @param secret + * @param stage + * @param secretDescription + * @return + */ + private Secret createSecretVersionGenerated(@NonNull Secret secret, @NonNull Base64SecretContentDetails.Stage stage, + String secretDescription) { + Base64SecretContentDetails base64SecretContentDetails = Base64SecretContentDetails.builder() + .stage(Base64SecretContentDetails.Stage.Current).build(); + UpdateSecretDetails.Builder updateSecretDetailsBuilder = UpdateSecretDetails.builder() + .secretContent(base64SecretContentDetails).enableAutoGeneration(true) + .secretGenerationContext(secret.getSecretGenerationContext()); + if (secretDescription != null) { + updateSecretDetailsBuilder.description(secretDescription); + } + UpdateSecretDetails updateSecretDetails = updateSecretDetailsBuilder.build(); + UpdateSecretRequest request = UpdateSecretRequest.builder().secretId(secret.getId()) + .updateSecretDetails(updateSecretDetails).build(); + UpdateSecretResponse response = vaultClient.updateSecret(request); + return response.getSecret(); + } + + /** + * Create a new version of the secret with the provided contents and make it the + * current version, the name and description can be null which means they won't + * be set in the new version + * + * @param secretOcid + * @param secretContents + * @param secretContentsVersionName + * @param secretDescription + * @return + */ + public Secret createSecretVersionManualAsCurrent(@NonNull String secretOcid, @NonNull String secretContents, + String secretContentsVersionName, String secretDescription) { + return createSecretVersionManual(secretOcid, secretContents, Base64SecretContentDetails.Stage.Current, + secretContentsVersionName, secretDescription); + } + + /** + * + * Create a new version of the secret with the provided contents and make it + * pending, the name and description can be null which means they won't be set + * in the new version + * + * @param secretOcid + * @param secretContents + * @param secretContentsVersionName + * @param secretDescription + * @return + */ + public Secret createSecretVersionManualAsPending(@NonNull String secretOcid, @NonNull String secretContents, + String secretContentsVersionName, String secretDescription) { + return createSecretVersionManual(secretOcid, secretContents, Base64SecretContentDetails.Stage.Pending, + secretContentsVersionName, secretDescription); + } + + /** + * + * Create a new version of the secret with the provided contents and set it to + * the provided stage, the name and description can be null which means they + * won't be set in the new version + * + * @param secretOcid + * @param secretContents + * @param stage + * @param secretContentsVersionName + * @param secretDescription + * @return + */ + public Secret createSecretVersionManual(@NonNull String secretOcid, @NonNull String secretContents, + Base64SecretContentDetails.Stage stage, String secretContentsVersionName, String secretDescription) { + UpdateSecretDetails.Builder updateSecretDetailsBuilder = UpdateSecretDetails.builder() + .enableAutoGeneration(false); + if (secretDescription != null) { + updateSecretDetailsBuilder.description(secretDescription); + } + String base64SecretContents = Base64.getEncoder().encodeToString(secretContents.getBytes()); + Base64SecretContentDetails.Builder base64SecretContentDetailsBuilder = Base64SecretContentDetails.builder() + .content(base64SecretContents); + if (secretContentsVersionName != null) { + base64SecretContentDetailsBuilder.name(secretContentsVersionName); + } + if (stage != null) { + base64SecretContentDetailsBuilder.stage(stage); + } + Base64SecretContentDetails base64SecretContentDetails = base64SecretContentDetailsBuilder.build(); + updateSecretDetailsBuilder.secretContent(base64SecretContentDetails); + UpdateSecretDetails updateSecretDetails = updateSecretDetailsBuilder.build(); + UpdateSecretRequest request = UpdateSecretRequest.builder().secretId(secretOcid) + .updateSecretDetails(updateSecretDetails).build(); + UpdateSecretResponse response = vaultClient.updateSecret(request); + return response.getSecret(); + } + + /** + * update the secret version to current + * + * @param secretVersion + * @return + */ + public Secret updateSecretVersionPendingToCurrent(@NonNull SecretVersion secretVersion) { + return updateSecretVersionPendingToCurrent(secretVersion.getSecretId(), secretVersion.getVersionNumber()); + } + + /** + * update the secret version to current + * + * @param secretOcid + * @param secretVersionNumber + * @return + */ + public Secret updateSecretVersionPendingToCurrent(@NonNull String secretOcid, @NonNull Long secretVersionNumber) { + UpdateSecretDetails updateSecretDetails = UpdateSecretDetails.builder() + .currentVersionNumber(secretVersionNumber).build(); + UpdateSecretRequest request = UpdateSecretRequest.builder().secretId(secretOcid) + .updateSecretDetails(updateSecretDetails).build(); + UpdateSecretResponse response = vaultClient.updateSecret(request); + return response.getSecret(); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretSummary + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull SecretSummary secretSummary, + @NonNull Long secretVersionNumber, @NonNull LocalDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secretSummary.getId(), secretVersionNumber, + ZonedDateTime.of(deletionDTG, ZoneId.systemDefault())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secret + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull Secret secret, @NonNull Long secretVersionNumber, + @NonNull LocalDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secret.getId(), secretVersionNumber, + ZonedDateTime.of(deletionDTG, ZoneId.systemDefault())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretOcid + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull String secretOcid, @NonNull Long secretVersionNumber, + @NonNull LocalDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secretOcid, secretVersionNumber, + ZonedDateTime.of(deletionDTG, ZoneId.systemDefault())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretSummary + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull SecretSummary secretSummary, + @NonNull Long secretVersionNumber, @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secretSummary.getId(), secretVersionNumber, + Date.from(deletionDTG.toInstant())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secret + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull Secret secret, @NonNull Long secretVersionNumber, + @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secret.getId(), secretVersionNumber, Date.from(deletionDTG.toInstant())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretOcid + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull String secretOcid, @NonNull Long secretVersionNumber, + @NonNull ZonedDateTime deletionDTG) { + return scheduleSecretVersionDeletion(secretOcid, secretVersionNumber, Date.from(deletionDTG.toInstant())); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretSummary + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull SecretSummary secretSummary, + @NonNull Long secretVersionNumber, @NonNull Date deletionDTG) { + return scheduleSecretVersionDeletion(secretSummary.getId(), secretVersionNumber, deletionDTG); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secret + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull Secret secret, @NonNull Long secretVersionNumber, + @NonNull Date deletionDTG) { + return scheduleSecretVersionDeletion(secret.getId(), secretVersionNumber, deletionDTG); + } + + /** + * schedule the deletion of the secret version, this will fail if it's the + * current version + * + * @param secretVersionOcid + * @param secretVersionNumber + * @param deletionDTG + * @return + */ + public boolean scheduleSecretVersionDeletion(@NonNull String secretVersionOcid, @NonNull Long secretVersionNumber, + @NonNull Date deletionDTG) { + ScheduleSecretVersionDeletionDetails details = ScheduleSecretVersionDeletionDetails.builder() + .timeOfDeletion(deletionDTG).build(); + ScheduleSecretVersionDeletionRequest request = ScheduleSecretVersionDeletionRequest.builder() + .secretId(secretVersionOcid).secretVersionNumber(secretVersionNumber) + .scheduleSecretVersionDeletionDetails(details).build(); + ScheduleSecretVersionDeletionResponse response = vaultClient.scheduleSecretVersionDeletion(request); + return response.get__httpStatusCode__() == HttpStatus.SC_OK; + } + + /** + * cancel the scheduled deletion of the secret version + * + * @param secretVersionSummary + * @param secretVersionNumber + * @return + */ + public boolean cancelSecretVersionDeletion(@NonNull SecretVersionSummary secretVersionSummary, + @NonNull Long secretVersionNumber) { + return cancelSecretVersionDeletion(secretVersionSummary.getSecretId(), secretVersionNumber); + } + + /** + * cancel the scheduled deletion of the secret version + * + * @param secretVersion + * @param secretVersionNumber + * @return + */ + public boolean cancelSecretVersionDeletion(@NonNull SecretVersion secretVersion, + @NonNull Long secretVersionNumber) { + return cancelSecretVersionDeletion(secretVersion.getSecretId(), secretVersionNumber); + } + + /** + * cancel the scheduled deletion of the secret version + * + * @param secretVersionOcid + * @param secretVersionNumber + * @return + */ + public boolean cancelSecretVersionDeletion(@NonNull String secretVersionOcid, @NonNull Long secretVersionNumber) { + CancelSecretVersionDeletionRequest request = CancelSecretVersionDeletionRequest.builder() + .secretId(secretVersionOcid).secretVersionNumber(secretVersionNumber).build(); + CancelSecretVersionDeletionResponse response = vaultClient.cancelSecretVersionDeletion(request); + return response.get__httpStatusCode__() == HttpStatus.SC_OK; + } + +} From 7999f8bed7c2dca0ebb550a652d023d12b7d2235 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:17:16 +0000 Subject: [PATCH 05/10] fixed testvault copyright --- .../timg/demo/examples/vault/TestVault.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java index c5182ec..f753826 100644 --- a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java +++ b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/vault/TestVault.java @@ -1,3 +1,39 @@ +/*Copyright (c) 2026 Oracle and/or its affiliates. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any +person obtaining a copy of this software, associated documentation and/or data +(collectively the "Software"), free of charge and under any and all copyright +rights in the Software, and any and all patent rights owned or freely +licensable by each licensor hereunder covering either (i) the unmodified +Software as contributed to or provided by such licensor, or (ii) the Larger +Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +one is included with the Software (each a "Larger Work" to which the Software +is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create +derivative works of, display, perform, and distribute the Software and make, +use, sell, offer for sale, import, export, have made, and have sold the +Software and the Larger Work(s), and to sublicense the foregoing rights on +either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at +a minimum a reference to the UPL must be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ package com.oracle.timg.demo.examples.vault; import java.io.IOException; From 34ca4bc5deddf21788a32ca8d820b07c7c5f8321 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Mon, 16 Feb 2026 17:13:59 +0000 Subject: [PATCH 06/10] rev version, include iot instance creation and testing --- .../.classpath | 5 +- oci-java-sdk-simple-wrappers-testing/pom.xml | 4 +- .../timg/demo/examples/iot/TestIoT.java | 227 ++++++ oci-java-sdk-simple-wrappers/pom.xml | 2 +- .../com/oracle/timg/oci/iot/IoTProcessor.java | 676 +++++++++++++----- 5 files changed, 746 insertions(+), 168 deletions(-) create mode 100644 oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java diff --git a/oci-java-sdk-simple-wrappers-testing/.classpath b/oci-java-sdk-simple-wrappers-testing/.classpath index 0b9f24c..28d610f 100644 --- a/oci-java-sdk-simple-wrappers-testing/.classpath +++ b/oci-java-sdk-simple-wrappers-testing/.classpath @@ -26,9 +26,8 @@ - + - @@ -44,8 +43,8 @@ - + diff --git a/oci-java-sdk-simple-wrappers-testing/pom.xml b/oci-java-sdk-simple-wrappers-testing/pom.xml index a2a914b..a0fc0d6 100644 --- a/oci-java-sdk-simple-wrappers-testing/pom.xml +++ b/oci-java-sdk-simple-wrappers-testing/pom.xml @@ -8,9 +8,9 @@ OciTesting UTF-8 - 1.1.0 + 1.2.0 1.0.13 - 17 + 21 ${maven.compiler.source} diff --git a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java new file mode 100644 index 0000000..33d8f34 --- /dev/null +++ b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java @@ -0,0 +1,227 @@ +/*Copyright (c) 2026 Oracle and/or its affiliates. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any +person obtaining a copy of this software, associated documentation and/or data +(collectively the "Software"), free of charge and under any and all copyright +rights in the Software, and any and all patent rights owned or freely +licensable by each licensor hereunder covering either (i) the unmodified +Software as contributed to or provided by such licensor, or (ii) the Larger +Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +one is included with the Software (each a "Larger Work" to which the Software +is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create +derivative works of, display, perform, and distribute the Software and make, +use, sell, offer for sale, import, export, have made, and have sold the +Software and the Larger Work(s), and to sublicense the foregoing rights on +either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at +a minimum a reference to the UPL must be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ +package com.oracle.timg.demo.examples.iot; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Base64; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.oracle.bmc.identity.model.Compartment; +import com.oracle.bmc.iot.model.DigitalTwinAdapter; +import com.oracle.bmc.iot.model.DigitalTwinInstance; +import com.oracle.bmc.iot.model.DigitalTwinModel; +import com.oracle.bmc.iot.model.IotDomain; +import com.oracle.bmc.iot.model.IotDomainGroup; +import com.oracle.timg.oci.authentication.AuthenticationProcessor; +import com.oracle.timg.oci.identity.IdentityProcessor; +import com.oracle.timg.oci.iot.IoTProcessor; +import com.oracle.timg.oci.vault.VaultProcessor; + +import timgutilities.textio.ChoiceDescription; +import timgutilities.textio.ChoiceDescriptionData; +import timgutilities.textio.TextIOUtils; + +public class TestIoT { + static AuthenticationProcessor authenticationProcessor; + static IdentityProcessor identityProcessor; + static IoTProcessor iotProcessor; + static VaultProcessor vaultProcessor; + + public static void main(String[] args) throws Exception { + TextIOUtils.doOutput("Configuring OCI connection"); + authenticationProcessor = new AuthenticationProcessor("DEFAULT"); + identityProcessor = new IdentityProcessor(authenticationProcessor); + iotProcessor = new IoTProcessor(authenticationProcessor); + vaultProcessor = new VaultProcessor(authenticationProcessor); + + String compartmentPath = TextIOUtils.getString("Please enter the compartment path to operate in", + "/domain-specialists/tim.graves/iot"); + Compartment compartment = identityProcessor.locateCompartmentByPath(compartmentPath); + if (compartment == null) { + TextIOUtils.doOutput("Can't locate compartment " + compartmentPath + ", cannot continue"); + System.exit(0); + } + TextIOUtils.doOutput("OCID of " + compartmentPath + " is " + compartment.getId()); + + List iotDomainGroups = iotProcessor.listIoTDomainGroupsInCompartment(compartment); + if (iotDomainGroups.isEmpty()) { + TextIOUtils.doOutput("No Iot Domain Groups found in compartment " + compartmentPath + ", cannot continue"); + return; + } + ChoiceDescriptionData iotDomainGroupCdd = new ChoiceDescriptionData<>(iotDomainGroups.stream() + .map(iotDomainGroup -> new ChoiceDescription(iotDomainGroup.getDisplayName(), + iotDomainGroup)) + .toList()); + IotDomainGroup iotDomainGroup = TextIOUtils.getParamChoice("Please chose the IoT domain group", + iotDomainGroupCdd); + TextIOUtils.doOutput("You chose IoT Domain Group " + iotDomainGroup.getDisplayName()); + + List iotDomains = iotProcessor.listIotDomainsInIotDomainGroup(iotDomainGroup); + if (iotDomains.isEmpty()) { + TextIOUtils.doOutput( + "No Iot Domains found in IotDomainGroup " + iotDomainGroup.getDisplayName() + ", cannot continue"); + return; + } + ChoiceDescriptionData iotDomainCdd = new ChoiceDescriptionData<>(iotDomains.stream() + .map(iotDomain -> new ChoiceDescription(iotDomain.getDisplayName(), iotDomain)).toList()); + IotDomain iotDomain = TextIOUtils.getParamChoice("Please chose the IoT domain group", iotDomainCdd); + TextIOUtils.doOutput("You chose IoT Domain " + iotDomain.getDisplayName()); + + List digitalTwinModels = iotProcessor.listDigitalTwinModels(iotDomain); + DigitalTwinModel digitalTwinModel = null; + if (digitalTwinModels.isEmpty()) { + TextIOUtils.doOutput("No Digital Twin Models found in IotDomain " + iotDomain.getDisplayName()); + } else { + ChoiceDescriptionData digitalTwinModelCdd = new ChoiceDescriptionData<>(digitalTwinModels + .stream().map(dtm -> new ChoiceDescription(dtm.getDisplayName(), dtm)).toList()); + digitalTwinModel = TextIOUtils.getParamChoice("Please chose the IoT domain group", digitalTwinModelCdd); + TextIOUtils.doOutput("You chose Digital Twin Model " + digitalTwinModel.getDisplayName()); + } + + List digitalTwinAdapters = iotProcessor.listDigitalTwinAdapters(iotDomain); + DigitalTwinAdapter digitalTwinAdapter = null; + if (digitalTwinAdapters.isEmpty()) { + TextIOUtils.doOutput("No Digital Twin Adapters found in IotDomain " + iotDomain.getDisplayName()); + } else { + ChoiceDescriptionData digitalTwinAdaptorsCdd = new ChoiceDescriptionData<>( + digitalTwinAdapters.stream() + .map(dta -> new ChoiceDescription(dta.getDisplayName(), dta)).toList()); + digitalTwinAdapter = TextIOUtils.getParamChoice("Please chose the IoT domain group", + digitalTwinAdaptorsCdd); + TextIOUtils.doOutput("You chose Digital Twin Adapter " + digitalTwinAdapter.getDisplayName()); + } + + List digitalTwinInstances = iotProcessor.listDigitalTwinInstances(iotDomain); + DigitalTwinInstance digitalTwinInstance = null; + if (digitalTwinInstances.isEmpty()) { + TextIOUtils.doOutput("No Digital Twin Instances found in IotDomain " + iotDomain.getDisplayName()); + } else { + ChoiceDescriptionData digitalTwinInstancesCdd = new ChoiceDescriptionData<>( + digitalTwinInstances.stream() + .map(dti -> new ChoiceDescription(dti.getDisplayName(), dti)) + .toList()); + digitalTwinInstance = TextIOUtils.getParamChoice("Please chose the IoT domain group", + digitalTwinInstancesCdd); + TextIOUtils.doOutput("You chose Digital Twin Instance " + digitalTwinInstance.getDisplayName()); + } + + if (digitalTwinInstance != null) { + getAndPrintLatestInstanceData(digitalTwinInstance); + } + DigitalTwinInstance newDigitalTwinInstance = null; + if ((digitalTwinInstance != null) && (digitalTwinAdapter != null) && (digitalTwinModel != null)) { + if (TextIOUtils.getYN( + "Do you want to create a digital twin instance using the model, adaptor, and auth detials of the digital twin you just chose (model=" + + digitalTwinModel.getDisplayName() + ", adaptor=" + digitalTwinAdapter.getDisplayName() + + ")", + false)) { + String displayName = TextIOUtils.getString("Please enter the display name (alpha numeric only)"); + String description = TextIOUtils.getString("Please enter the description or empty string for none", ""); + if (description.length() == 0) { + description = null; + } + String externalKey = TextIOUtils + .getString("Please enter the external key, or empty string for a system assigned one", ""); + if (externalKey.length() == 0) { + externalKey = null; + } + String authOcid = digitalTwinInstance.getAuthId(); + newDigitalTwinInstance = iotProcessor.createDigitalTwinInstance(iotDomain.getId(), displayName, + authOcid, externalKey, description, digitalTwinModel.getId(), digitalTwinAdapter.getId()); + TextIOUtils.doOutput("DigitalTwinInstance just created is " + newDigitalTwinInstance); + getAndPrintLatestInstanceData(newDigitalTwinInstance); + } + } + if ((newDigitalTwinInstance != null) + && (TextIOUtils.getYN("Do you want to send some test data to this instance ?", true))) { + sendTestDataInstance(iotDomain, newDigitalTwinInstance); + getAndPrintLatestInstanceData(newDigitalTwinInstance); + } + if (newDigitalTwinInstance != null) { + if (TextIOUtils.getYN("Do you want to delete the digital twin instance you just created ?", true)) { + iotProcessor.deleteDigitalTwinInstance(newDigitalTwinInstance); + } + } + } + + private static void sendTestDataInstance(IotDomain iotDomain, DigitalTwinInstance digitalTwinInstance) + throws IOException { + // send data, similar to this + // curl -i -X POST -u "$DEVICE_EXTERNAL_KEY:$DEVICE_SECRET" + // https://$IOT_DOMAIN_HOST/home/sonnenstatus/$DEVICE_ID -H + // "Content-Type:application/json" -d + // '{"consumptionAvgWattsLastMinute":488,"consumptionWattsPointInTime":517,"currentBatteryCapacityPercentage":25,"currentBatteryCapacitySystemPercentage":30,"gridConsumptionWattsPointInTime":44,"operatingMode":10,"remainingBatteryCapacityWattHours":4775,"reservedBatteryCapacityPercentage":5,"solarProductionWattsPointInTime":0,"time":1764004104225,"timestamp":"2025-11-24T17:08:24.225022Z[Europe/London]","batteryCharging":false,"batteryDischarging":true}' + + String externalKey = digitalTwinInstance.getExternalKey(); + String deviceSecret = vaultProcessor.getSecretContents(digitalTwinInstance.getAuthId()); + String iotDomainHost = iotDomain.getDeviceHost(); + String devicePath = TextIOUtils.getString("Please enter the absolute (startes with /) path on the host " + + iotDomainHost + " to send date to (this may need to include the device details)"); + String jsonPayload = TextIOUtils.getString("Please enter the data to send (this should be in JSON format"); + String url = "https://" + iotDomainHost + devicePath; + String auth = externalKey + ":" + deviceSecret; + TextIOUtils.doOutput("Sending to url " + url); + TextIOUtils.doOutput("With credentials " + auth); + String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); + String authHeader = "Basic " + encodedAuth; + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).header("Content-Type", "application/json") + .header("Authorization", authHeader).POST(HttpRequest.BodyPublishers.ofString(jsonPayload)).build(); + + try { + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + TextIOUtils.doOutput("Status Code: " + response.statusCode()); + TextIOUtils.doOutput("Response Body: " + response.body()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void getAndPrintLatestInstanceData(DigitalTwinInstance digitalTwinInstance) { + Map latestData = iotProcessor.getDigitalTwinInstanceContent(digitalTwinInstance); + String resp = latestData.entrySet().stream().map(e -> e.getKey() + " - " + e.getValue().toString()) + .collect(Collectors.joining("\n")); + TextIOUtils.doOutput("Most recent data for instance is\n" + resp); + } +} diff --git a/oci-java-sdk-simple-wrappers/pom.xml b/oci-java-sdk-simple-wrappers/pom.xml index dd96ff2..967f421 100644 --- a/oci-java-sdk-simple-wrappers/pom.xml +++ b/oci-java-sdk-simple-wrappers/pom.xml @@ -41,7 +41,7 @@ SOFTWARE. --> com.oracle.timg.demo oci-java-sdk-simple-wrappers ocicore - 1.1.0 + 1.2.0 jar 21 diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java index 310f472..7ca3426 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java @@ -1,4 +1,4 @@ -/*Copyright (c) 2025 Oracle and/or its affiliates. +/*Copyright (c) 2026 Oracle and/or its affiliates. The Universal Permissive License (UPL), Version 1.0 @@ -66,6 +66,8 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on import com.oracle.bmc.iot.requests.ListDigitalTwinAdaptersRequest; import com.oracle.bmc.iot.requests.ListDigitalTwinInstancesRequest; import com.oracle.bmc.iot.requests.ListDigitalTwinModelsRequest; +import com.oracle.bmc.iot.requests.ListDigitalTwinModelsRequest.SortBy; +import com.oracle.bmc.iot.requests.ListDigitalTwinModelsRequest.SortOrder; import com.oracle.bmc.iot.requests.ListIotDomainGroupsRequest; import com.oracle.bmc.iot.requests.ListIotDomainsRequest; import com.oracle.bmc.iot.responses.CreateDigitalTwinInstanceResponse; @@ -115,7 +117,7 @@ public void setRegion(@NonNull String regionName) { } /** - * gets a list of summaries of all IotDomainGroups in the tenancy root + * gets a list of summaries of all active IotDomainGroups in the tenancy root * compartment * * @return @@ -125,8 +127,8 @@ public List listIoTDomainGroupSummariesInTenancy() { } /** - * gets a list of summaries of all IotDomainGroups in the specified parent - * compartment + * gets a list of summaries of all active IotDomainGroups in the specified + * parent compartment * * @param parentCompartment * @return @@ -137,8 +139,8 @@ public List listIoTDomainGroupSummariesInCompartment( } /** - * gets a list of summaries of all IotDomainGroups in the compartment with the - * specified parent compartment ocid + * gets a list of summaries of all active IotDomainGroups in the compartment + * with the specified parent compartment ocid * * @param parentCompartmentOcid * @return @@ -148,7 +150,7 @@ public List listIoTDomainGroupSummariesInCompartment(@Non } /** - * generate a list of all domain group summaries in a compartment, if + * generate a list of all active domain group summaries in a compartment, if * displayName is not null limits it to only those matching the display name * * @param parentCompartmentOcid @@ -162,7 +164,7 @@ public List listIoTDomainGroupSummariesInCompartment(@Non } /** - * generate a list of all domain group summaries in a compartment, if + * generate a list of all active domain group summaries in a compartment, if * displayName is not null limits it to only those matching the display name * * @param parentCompartmentOcid @@ -172,8 +174,28 @@ public List listIoTDomainGroupSummariesInCompartment(@Non */ public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, String displayName) { + return listIoTDomainGroupSummariesInCompartment(parentCompartmentOcid, displayName, + IotDomainGroup.LifecycleState.Active); + } + + /** + * generate a list of all domain group summaries ordered by displayName in a + * compartment in the lifecycle state, if displayName is not null limits it to + * only those matching the display name. if lifecycle states is null + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, + String displayName, IotDomainGroup.LifecycleState lifecycleState) { ListIotDomainGroupsRequest.Builder requestBuilder = ListIotDomainGroupsRequest.builder() - .compartmentId(parentCompartmentOcid); + .compartmentId(parentCompartmentOcid).sortBy(ListIotDomainGroupsRequest.SortBy.DisplayName) + .sortOrder(ListIotDomainGroupsRequest.SortOrder.Asc); + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } if (displayName != null) { requestBuilder.displayName(displayName); } @@ -183,7 +205,7 @@ public List listIoTDomainGroupSummariesInCompartment(@Non } /** - * gets a list of all IotDomainGroups in the tenancy root compartment + * gets a list of all active IotDomainGroups in the tenancy root compartment * * @return */ @@ -192,8 +214,8 @@ public List listIoTDomainGroupsInTenancy() { } /** - * returns a list of all IotDomainGroups in the compartment with the specified - * parent compartment ocid + * returns a list of all active IotDomainGroups in the compartment with the + * specified parent compartment ocid * * @param parentCompartmentOcid * @return @@ -203,7 +225,8 @@ public List listIoTDomainGroupsInCompartment(@NonNull String par } /** - * returns a list of all IotDomainGroups in the specified parent compartment + * returns a list of all active IotDomainGroups in the specified parent + * compartment * * @param parentCompartmentOcid * @return @@ -213,8 +236,8 @@ public List listIoTDomainGroupsInCompartment(@NonNull Compartmen } /** - * * returns a list of all IotDomainGroups with a matching displayName in the - * compartment with the specified parent compartment ocid. If displayName is + * * returns a list of all active IotDomainGroups with a matching displayName in + * the compartment with the specified parent compartment ocid. If displayName is * null returns all domain groups * * @param parentCompartmentOcid @@ -224,14 +247,30 @@ public List listIoTDomainGroupsInCompartment(@NonNull Compartmen */ public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, String displayName) { + return listIoTDomainGroupsInCompartment(parentCompartmentOcid, displayName, + IotDomainGroup.LifecycleState.Active); + } + + /** + * * returns a list of all IotDomainGroups in the lifecycleState with a matching + * displayName in the compartment with the specified parent compartment ocid. If + * displayName is null returns all domain groups + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, + String displayName, IotDomainGroup.LifecycleState lifecycleState) { List domainGroupSummaries = listIoTDomainGroupSummariesInCompartment( - parentCompartmentOcid, displayName); + parentCompartmentOcid, displayName, lifecycleState); return domainGroupSummaries.stream().map(dsg -> getIotDomainGroup(dsg)).toList(); } /** - * gets the **FIRST** IotDomainGroupSummary with a matching display name in the - * compartment with the specified OCID, or null if there are no matches + * gets the **FIRST** active IotDomainGroupSummary with a matching display name + * in the compartment with the specified OCID, or null if there are no matches * * @param parentCompartmentOcid * @param displayName @@ -240,8 +279,24 @@ public List listIoTDomainGroupsInCompartment(@NonNull String par */ public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentCompartmentOcid, @NonNull String displayName) { + return getIotDomainGroupSummary(parentCompartmentOcid, displayName, IotDomainGroup.LifecycleState.Active); + } + + /** + * gets the **FIRST** IotDomainGroupSummary with a state as specified and a + * matching display name in the compartment with the specified OCID, or null if + * there are no matches. If the lifecycleStates is null then all states are + * allowed. + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentCompartmentOcid, + @NonNull String displayName, IotDomainGroup.LifecycleState lifecycleState) { List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( - parentCompartmentOcid, displayName); + parentCompartmentOcid, displayName, lifecycleState); if (iotDomainGroupSummaries.isEmpty()) { return null; } @@ -249,9 +304,9 @@ public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentComp } /** - * gets the **FIRST** IotDomainGroup with matching displayName in the - * compartment with the specified parent compartment ocid, or null if there are - * no matches + * gets the **FIRST** (by displayName ascending) active IotDomainGroup with + * matching displayName in the compartment with the specified parent compartment + * ocid, or null if there are no matches * * @param parentCompartmentOcid * @param displayName @@ -259,8 +314,24 @@ public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentComp * @return */ public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @NonNull String displayName) { + return getIotDomainGroup(parentCompartmentOcid, displayName, IotDomainGroup.LifecycleState.Active); + } + + /** + * gets the **FIRST** IotDomainGroup with matching displayName and status in + * lifecycleStates in the compartment with the specified parent compartment + * ocid, or null if there are no matches. If lifecycleState is null all states + * are allowed + * + * @param parentCompartmentOcid + * @param displayName + * + * @return + */ + public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @NonNull String displayName, + IotDomainGroup.LifecycleState lifecycleState) { List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( - parentCompartmentOcid, displayName); + parentCompartmentOcid, displayName, lifecycleState); if (iotDomainGroupSummaries.isEmpty()) { return null; } @@ -268,7 +339,8 @@ public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @ } /** - * gets the IotDomainGroup details from the provided summary + * gets the IotDomainGroup details from the provided summary, regardless of the + * state * * @param iotDomainGroupSummary * @return @@ -280,41 +352,44 @@ public IotDomainGroup getIotDomainGroup(@NonNull IotDomainGroupSummary iotDomain } /** - * get a summary of all IotDomains in the specified IoTDomainGroup + * get a summary of all active IotDomains in the specified IoTDomainGroup * * @param iotDomainGroupSummary * @return */ public List listIotDomainSummariesInIotDomainGroup( @NonNull IotDomainGroupSummary iotDomainGroupSummary) { - return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getId()); + return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getCompartmentId(), + iotDomainGroupSummary.getId()); } /** - * get a summary of all IotDomains in the specified IoTDomainGroup + * get a summary of all active IotDomains in the specified IoTDomainGroup * * @param iotDomainGroup * @return */ public List listIotDomainSummariesInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup) { - return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getId()); + return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId()); } /** - * get a summary of all IotDomains in the specified IoTDomainGroup + * get a summary of all active IotDomains in the specified IoTDomainGroup * * @param iotDomainGroupOcid * @return */ - public List listIotDomainSummariesInIotDomainGroup(@NonNull String iotDomainGroupOcid) { - return listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, null); + public List listIotDomainSummariesInIotDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid) { + return listIotDomainSummariesInIotDomainGroup(compartmentOcid, iotDomainGroupOcid, null); } /** - * get a summary of all IotDomains in the specified IoTDomainGroup, if - * displayName is not null limits on only domains with a matching name + * get a summary of all active IotDomains in the specified IoTDomainGroup and + * it's compartment, if displayName is not null limits on only domains with a + * matching name * * @param iotDomainGroupSummary * @Param displayName @@ -322,13 +397,16 @@ public List listIotDomainSummariesInIotDomainGroup(@NonNull St */ public List listIotDomainSummariesInIotDomainGroup( @NonNull IotDomainGroupSummary iotDomainGroupSummary, String displayName) { - return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getId(), displayName); + return listIotDomainSummariesInIotDomainGroup(iotDomainGroupSummary.getCompartmentId(), + iotDomainGroupSummary.getId(), displayName); } /** - * get a summary of all IotDomains in the specified IoTDomainGroup, if - * displayName is not null limits on only domains with a matching name + * get a summary of all active IotDomains in the specified IoTDomainGroup and + * its compartment, if displayName is not null limits on only domains with a + * matching name, assumes that the iod domain is in the same compartment as the + * iot domain group * * @param iotDomainGroup * @Param displayName @@ -336,63 +414,126 @@ public List listIotDomainSummariesInIotDomainGroup( */ public List listIotDomainSummariesInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup, String displayName) { - return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getId(), displayName); + return listIotDomainSummariesInIotDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId(), + displayName, IotDomain.LifecycleState.Active); } /** - * get a summary of all IotDomains in the specified IoTDomainGroup, if - * displayName is not null limits on only domains with a matching name + * get a summary of all active IotDomains in the specified IoTDomainGroup and + * compartment, if displayName is not null limits on only domains with a + * matching name * + * @param compartmentOcid * @param iotDomainGroupSummaryOcid * @Param displayName * @return */ - public List listIotDomainSummariesInIotDomainGroup(@NonNull String iotDomainGroupOcid, - String displayName) { - ListIotDomainsRequest.Builder requestBuilder = ListIotDomainsRequest.builder() - .iotDomainGroupId(iotDomainGroupOcid); + public List listIotDomainSummariesInIotDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid, String displayName) { + return listIotDomainSummariesInIotDomainGroup(compartmentOcid, iotDomainGroupOcid, displayName, + IotDomain.LifecycleState.Active); + } + + /** + * get a summary of all IotDomains with the lifecycle state in the specified + * IoTDomainGroup and compartment, if displayName is not null limits on only + * domains with a matching name if lifecycleState is null then all states are + * allowed + * + * @param compartmentOcid + * @param iotDomainGroupSummaryOcid + * @Param displayName + * @return + */ + public List listIotDomainSummariesInIotDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid, String displayName, IotDomain.LifecycleState lifecycleState) { + return listIotDomainSummaries(compartmentOcid, iotDomainGroupOcid, displayName, lifecycleState); + } + + /** + * get a summary of all IotDomains with the lifecycle state in the specified + * compartment, if displayName is not null limits on only domains with a + * matching name if lifecycleState is null then all states are allowed + * + * @param compartmentOcid + * @Param displayName + * @return + */ + public List listIotDomainSummariesInCompartment(@NonNull Compartment compartment, + String displayName, IotDomain.LifecycleState lifecycleState) { + return listIotDomainSummariesInCompartment(compartment.getId(), displayName, lifecycleState); + + } + + /** + * get a summary of all IotDomains with the lifecycle state in the specified + * compartment, if displayName is not null limits on only domains with a + * matching name if lifecycleState is null then all states are allowed + * + * @param compartmentOcid + * @Param displayName + * @return + */ + public List listIotDomainSummariesInCompartment(@NonNull String compartmentOcid, + String displayName, IotDomain.LifecycleState lifecycleState) { + return listIotDomainSummaries(compartmentOcid, null, displayName, lifecycleState); + + } + + private List listIotDomainSummaries(String compartmentOcid, String iotDomainGroupOcid, + String displayName, IotDomain.LifecycleState lifecycleState) { + ListIotDomainsRequest.Builder requestBuilder = ListIotDomainsRequest.builder().compartmentId(compartmentOcid) + .sortBy(ListIotDomainsRequest.SortBy.DisplayName).sortOrder(ListIotDomainsRequest.SortOrder.Asc); + if (iotDomainGroupOcid != null) { + requestBuilder.iotDomainGroupId(iotDomainGroupOcid); + } + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } if (displayName != null) { requestBuilder.displayName(displayName); } Iterable domainGroupSummaries = iotClient.getPaginators() .listIotDomainsRecordIterator(requestBuilder.build()); return StreamSupport.stream(domainGroupSummaries.spliterator(), false).toList(); + } /** - * get a list of all IotDomains in the specified IoTDomainGroupSummary + * get a list of all active IotDomains in the specified IoTDomainGroupSummary * * @param iotDomainGroupSummary * @return */ public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary) { - return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getId()); + return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getCompartmentId(), iotDomainGroupSummary.getId()); } /** - * get a list of all IotDomains in the specified IoTDomainGroup + * get a list of all active IotDomains in the specified IoTDomainGroup * * @param iotDomainGroup * @return */ public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup) { - return listIotDomainsInIotDomainGroup(iotDomainGroup.getId()); + return listIotDomainsInIotDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId()); } /** - * get a list of all IotDomains in the specified IoTDomainGroupSummary + * get a list of all active IotDomains in the specified IoTDomainGroupSummary * * @param iotDomainGroupOcid * @return */ - public List listIotDomainsInIotDomainGroup(@NonNull String iotDomainGroupOcid) { - return listIotDomainsInIotDomainGroup(iotDomainGroupOcid, null); + public List listIotDomainsInIotDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid) { + return listIotDomainsInIotDomainGroup(compartmentOcid, iotDomainGroupOcid, null); } /** - * get a list of all IotDomains in the specified IoTDomainGroupSummary, if - * displayName is not null limits on only domains with a matching name + * get a list of all active IotDomains in the specified IoTDomainGroupSummary, + * if displayName is not null limits on only domains with a matching name * * @param iotDomainGroupSummary * @Param displayName @@ -400,91 +541,186 @@ public List listIotDomainsInIotDomainGroup(@NonNull String iotDomainG */ public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary, String displayName) { - return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getId(), displayName); + return listIotDomainsInIotDomainGroup(iotDomainGroupSummary.getCompartmentId(), iotDomainGroupSummary.getId(), + displayName); } /** - * get a list of all IotDomains in the specified IoTDomainGroup, if displayName - * is not null limits on only domains with a matching name + * get a list of all active IotDomains in the specified IoTDomainGroup, if + * displayName is not null limits on only domains with a matching name * * @param iotDomainGroup * @Param displayName * @return */ public List listIotDomainsInIotDomainGroup(@NonNull IotDomainGroup iotDomainGroup, String displayName) { - return listIotDomainsInIotDomainGroup(iotDomainGroup.getId(), displayName); + return listIotDomainsInIotDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId(), displayName); } /** - * get a list of all IotDomains in the specified IoTDomainGroup, if displayName - * is not null limits on only domains with a matching name + * get a list of all active IotDomains in the specified IoTDomainGroup, if + * displayName is not null limits on only domains with a matching name * * @param iotDomainGroupOcid * @Param displayName * @return */ - public List listIotDomainsInIotDomainGroup(@NonNull String iotDomainGroupOcid, String displayName) { - List domainSummaries = listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, - displayName); + public List listIotDomainsInIotDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid, String displayName) { + List domainSummaries = listIotDomainSummariesInIotDomainGroup(compartmentOcid, + iotDomainGroupOcid, displayName); return domainSummaries.stream().map(ds -> getIotDomain(ds)).toList(); } /** - * get the iotdomain (i.e. with full details) from the specified summary + * gets the **FIRST** active IotDomainSummary in the domain group with a + * matching displayName. if displayName is null then any name will match * - * @param iotDomainSummary + * @param iotDomainGroup + * @param displayName * @return */ - public IotDomain getIotDomain(@NonNull IotDomainSummary iotDomainSummary) { - GetIotDomainResponse resp = iotClient - .getIotDomain(GetIotDomainRequest.builder().iotDomainId(iotDomainSummary.getId()).build()); - return resp.getIotDomain(); + public IotDomainSummary getIotDomainSummaryInDomainGroup(@NonNull IotDomainGroup iotDomainGroup, + String displayName) { + return getIotDomainSummaryInDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId(), displayName); } /** - * get a list of all IotDomains in the specified IoTDomainGroup, if displayName - * is not null limits on only domains with a matching name + * gets the **FIRST** active IotDomainSummary in the domain group with a + * matching displayName. if displayName is null then any name will match * - * @param iotDomainGroup - * @Param displayName + * @param iotDomainGroupSummary + * @param displayName * @return */ - public IotDomain getIotDomain(@NonNull IotDomainGroup iotDomainGroup, @NonNull String displayName) { - return getIotDomain(iotDomainGroup.getId(), displayName); + public IotDomainSummary getIotDomainSummaryInDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary, + String displayName) { + return getIotDomainSummaryInDomainGroup(iotDomainGroupSummary.getCompartmentId(), iotDomainGroupSummary.getId(), + displayName); } /** - * get a list of all IotDomains in the specified IoTDomainGroup, if displayName - * is not null limits on only domains with a matching name + * gets the **FIRST** active IotDomainSummary in the domain group with a + * matching displayName. if displayName is null then any name will match * - * @param iotDomainGroup - * @Param displayName + * @param iotDomainGroupOcid + * @param displayName * @return */ - public IotDomain getIotDomain(@NonNull IotDomainGroupSummary iotDomainGroupSummary, @NonNull String displayName) { - return getIotDomain(iotDomainGroupSummary.getId(), displayName); + public IotDomainSummary getIotDomainSummaryInDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid, String displayName) { + return getIotDomainSummaryInDomainGroup(compartmentOcid, iotDomainGroupOcid, displayName, + IotDomain.LifecycleState.Active); } /** - * get a list of all IotDomains in the specified IoTDomainGroup, if displayName - * is not null limits on only domains with a matching name + * gets the **FIRST** IotDomainSummary in the domain group with a matching name + * and lifecycle state if displayName is null then any name will match, if + * lifecycleStates is null or empty then all states will match * * @param iotDomainGroupOcid - * @Param displayName + * @param displayName + * @param lifecycleStates + * @return + */ + public IotDomainSummary getIotDomainSummaryInDomainGroup(@NonNull String compartmentOcid, + @NonNull String iotDomainGroupOcid, String displayName, IotDomain.LifecycleState lifecycleState) { + List iotDomainSummaries = listIotDomainSummariesInIotDomainGroup(compartmentOcid, + iotDomainGroupOcid, displayName, lifecycleState); + if (iotDomainSummaries.isEmpty()) { + return null; + } + return iotDomainSummaries.getFirst(); + + } + + /** + * gets the **FIRST** active IotDomain in the domain group with a matching + * displayName. if displayName is null then any name will match + * + * @param iotDomainGroup + * @param displayName + * @return + */ + public IotDomain getIotDomainInDomainGroup(@NonNull IotDomainGroup iotDomainGroup, String displayName) { + return getIotDomainInDomainGroup(iotDomainGroup.getCompartmentId(), iotDomainGroup.getId(), displayName); + } + + /** + * gets the **FIRST** active IotDomain in the domain group with a matching + * displayName. if displayName is null then any name will match + * + * @param iotDomainGroupSummary + * @param displayName * @return */ - public IotDomain getIotDomain(@NonNull String iotDomainGroupOcid, @NonNull String displayName) { - List iotDomainSummaries = listIotDomainSummariesInIotDomainGroup(iotDomainGroupOcid, + public IotDomain getIotDomainInDomainGroup(@NonNull IotDomainGroupSummary iotDomainGroupSummary, + String displayName) { + return getIotDomainInDomainGroup(iotDomainGroupSummary.getCompartmentId(), iotDomainGroupSummary.getId(), displayName); + } + + /** + * gets the **FIRST** active IotDomain in the domain group with a matching + * displayName. if displayName is null then any name will match + * + * @param iotDomainGroupOcid + * @param displayName + * @return + */ + public IotDomain getIotDomainInDomainGroup(@NonNull String compartmentOcid, @NonNull String iotDomainGroupOcid, + String displayName) { + return getIotDomainInDomainGroup(compartmentOcid, iotDomainGroupOcid, displayName, + IotDomain.LifecycleState.Active); + } + + /** + * gets the **FIRST** IotDomain in the domain group with a matching name and + * lifecycle state if displayName is null then any name will match, if + * lifecycleStates is null or empty then all states will match + * + * @param iotDomainGroupOcid + * @param displayName + * @param lifecycleState + * @return + */ + public IotDomain getIotDomainInDomainGroup(@NonNull String compartmentOcid, @NonNull String iotDomainGroupOcid, + String displayName, IotDomain.LifecycleState lifecycleState) { + List iotDomainSummaries = listIotDomainSummariesInIotDomainGroup(compartmentOcid, + iotDomainGroupOcid, displayName, lifecycleState); if (iotDomainSummaries.isEmpty()) { return null; } return getIotDomain(iotDomainSummaries.getFirst()); + } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomainSummary + * get the iotdomain (i.e. with full details) from the specified summary + * + * @param iotDomainSummary + * @return + */ + public IotDomain getIotDomain(@NonNull IotDomainSummary iotDomainSummary) { + return getIotDomain(iotDomainSummary.getId()); + } + + /** + * get the iotdomain (i.e. with full details) from the specified summary + * + * @param iotDomainSummary + * @return + */ + public IotDomain getIotDomain(@NonNull String iotDomainSummaryOcid) { + GetIotDomainResponse resp = iotClient + .getIotDomain(GetIotDomainRequest.builder().iotDomainId(iotDomainSummaryOcid).build()); + return resp.getIotDomain(); + } + + /** + * get a list of all active DigitalTwinModelSummary in the specified + * IoTDomainSummary * * @param iotDomainSummary * @return @@ -494,7 +730,7 @@ public List listDigitalTwinModelSummaries(@NonNull IotD } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomain + * get a list of all active DigitalTwinModelSummary in the specified IoTDomain * * @param iotDomain * @return @@ -505,7 +741,7 @@ public List listDigitalTwinModelSummaries(@NonNull IotD } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomain + * get a list of all active DigitalTwinModelSummary in the specified IoTDomain * * @param iotDomainOcid * @return @@ -516,8 +752,9 @@ public List listDigitalTwinModelSummaries(@NonNull Stri } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomainSummary, - * if displayName is not null limits on only domains with a matching name + * get a list of all active DigitalTwinModelSummary in the specified + * IoTDomainSummary, if displayName is not null limits on only domains with a + * matching name * * @param iotDomainSummary * @Param displayName @@ -529,8 +766,8 @@ public List listDigitalTwinModelSummaries(@NonNull IotD } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomain, if - * displayName is not null limits on only domains with a matching name + * get a list of all active DigitalTwinModelSummary in the specified IoTDomain, + * if displayName is not null limits on only domains with a matching name * * @param iotDomain * @Param displayName @@ -543,8 +780,8 @@ public List listDigitalTwinModelSummaries(@NonNull IotD } /** - * get a list of all DigitalTwinModelSummary in the specified IoTDomain, if - * displayName is not null limits on only domains with a matching name + * get a list of all active DigitalTwinModelSummary in the specified IoTDomain, + * if displayName is not null limits on only domains with a matching name * * @param iotDomainOcid * @Param displayName @@ -552,8 +789,27 @@ public List listDigitalTwinModelSummaries(@NonNull IotD */ public List listDigitalTwinModelSummaries(@NonNull String iotDomainOcid, String displayName) { + return listDigitalTwinModelSummaries(iotDomainOcid, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinModelSummary in the specified lifecycle state + * and IoTDomain, if displayName is not null limits on only domains with a + * matching name. If lifecycle states is null or empty defaults to all allowed + * states + * + * @param iotDomainOcid + * @Param displayName + * @return + */ + public List listDigitalTwinModelSummaries(@NonNull String iotDomainOcid, + String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { ListDigitalTwinModelsRequest.Builder requestBuilder = ListDigitalTwinModelsRequest.builder() - .iotDomainId(iotDomainOcid); + .iotDomainId(iotDomainOcid).sortBy(SortBy.DisplayName).sortOrder(SortOrder.Asc); + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } if (displayName != null) { requestBuilder.displayName(displayName); } @@ -563,7 +819,7 @@ public List listDigitalTwinModelSummaries(@NonNull Stri } /** - * get a list of all DigitalTwinModel in the specified IoTDomainSummary + * get a list of all active DigitalTwinModel in the specified IoTDomainSummary * * @param iotDomainSummary * @return @@ -573,7 +829,7 @@ public List listDigitalTwinModels(@NonNull IotDomainSummary io } /** - * get a list of all DigitalTwinModel in the specified IoTDomain + * get a list of all active DigitalTwinModel in the specified IoTDomain * * @param iotDomain * @return @@ -584,7 +840,7 @@ public List listDigitalTwinModels(@NonNull IotDomain iotDomain } /** - * get a list of all DigitalTwinModel in the specified IoTDomain + * get a list of all active DigitalTwinModel in the specified IoTDomain * * @param iotDomainOcid * @return @@ -595,8 +851,8 @@ public List listDigitalTwinModels(@NonNull String iotDomainOci } /** - * get a list of all DigitalTwinModel in the specified IoTDomainSummary, if - * displayName is not null it's used to limit the results + * get a list of all active DigitalTwinModel in the specified IoTDomainSummary, + * if displayName is not null it's used to limit the results * * @param iotDomainSummary * @param displayName @@ -608,8 +864,8 @@ public List listDigitalTwinModels(@NonNull IotDomainSummary io } /** - * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName - * is not null it's used to limit the results + * get a list of all active DigitalTwinModel in the specified IoTDomain, if + * displayName is not null it's used to limit the results * * @param iotDomain * @param displayName @@ -629,13 +885,28 @@ public List listDigitalTwinModels(@NonNull IotDomain iotDomain * @return */ public List listDigitalTwinModels(@NonNull String iotDomainOcid, String displayName) { - List modelSummaries = listDigitalTwinModelSummaries(iotDomainOcid, displayName); + return listDigitalTwinModels(iotDomainOcid, displayName, com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all active DigitalTwinModel in the specified state and + * IoTDomain, if displayName is not null it's used to limit the results. if + * lifecycleStates is null then all states are allowed + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinModels(@NonNull String iotDomainOcid, String displayName, + com.oracle.bmc.iot.model.LifecycleState lifecycleState) { + List modelSummaries = listDigitalTwinModelSummaries(iotDomainOcid, displayName, + lifecycleState); return modelSummaries.stream().map(ms -> getDigitalTwinModel(ms)).toList(); } /** - * get gets DigitalTwinModel in the specified IoTDomainSummary, with the - * specified displayName, if there are no matches returns null + * get the **FIRST** active DigitalTwinModel in the specified IoTDomainSummary, + * with the specified displayName, if there are no matches returns null * * @param iotDomainSummary * @param displayName @@ -647,8 +918,8 @@ public DigitalTwinModel getDigitalTwinModel(@NonNull IotDomainSummary iotDomainS } /** - * get gets DigitalTwinModel in the specified IoTDomain, with the specified - * displayName, if there are no matches returns null + * get the **FIRST** active DigitalTwinModel in the specified IoTDomain, with + * the specified displayName, if there are no matches returns null * * @param iotDomain * @param displayName @@ -660,16 +931,30 @@ public DigitalTwinModel getDigitalTwinModel(@NonNull IotDomain iotDomain, @NonNu } /** - * get gets DigitalTwinModel in the specified IoTDomain, with the specified - * displayName, if there are no matches returns null + * get the **FIRST active DigitalTwinModel in the specified IoTDomain, with the + * specified displayName, if there are no matches returns null * * @param iotDomainOcid * @param displayName * @return */ public DigitalTwinModel getDigitalTwinModel(@NonNull String iotDomainOcid, @NonNull String displayName) { + return getDigitalTwinModel(iotDomainOcid, displayName, com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get the **FIRST DigitalTwinModel in the specified state and IoTDomain, with + * the specified displayName, if there are no matches returns null. if + * lifecycleStates is null then all states are returned + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public DigitalTwinModel getDigitalTwinModel(@NonNull String iotDomainOcid, @NonNull String displayName, + com.oracle.bmc.iot.model.LifecycleState lifecycleState) { List digitalTwinModelSummaries = listDigitalTwinModelSummaries(iotDomainOcid, - displayName); + displayName, lifecycleState); if (digitalTwinModelSummaries.isEmpty()) { return null; } @@ -677,7 +962,7 @@ public DigitalTwinModel getDigitalTwinModel(@NonNull String iotDomainOcid, @NonN } /** - * get gets DigitalTwinModel from the specified DigitalTwinModelSummary + * get gets DigitalTwinModel from the specified DigitalTwinModelSummary. * * @param digitalTwinModelSummary * @return @@ -689,7 +974,7 @@ public DigitalTwinModel getDigitalTwinModel(@NonNull DigitalTwinModelSummary dig } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain + * get all active DigitalTwinAdapterSummary in the specified IotDomain * * @param iotDomainSummary * @return @@ -699,7 +984,7 @@ public List listDigitalTwinAdapterSummaries(@NonNull } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain + * get all active DigitalTwinAdapterSummary in the specified IotDomain * * @param iotDomain * @return @@ -710,7 +995,7 @@ public List listDigitalTwinAdapterSummaries(@NonNull } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain + * get all active DigitalTwinAdapterSummary in the specified IotDomain * * @param iotDomainOcid * @return @@ -721,8 +1006,8 @@ public List listDigitalTwinAdapterSummaries(@NonNull } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinAdapterSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomainSummary * @return @@ -733,8 +1018,8 @@ public List listDigitalTwinAdapterSummaries(@NonNull } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinAdapterSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomain * @return @@ -746,26 +1031,44 @@ public List listDigitalTwinAdapterSummaries(@NonNull } /** - * get all DigitalTwinAdapterSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinAdapterSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomainOcid * @return */ public List listDigitalTwinAdapterSummaries(@NonNull String iotDomainOcid, String displayName) { + return listDigitalTwinAdapterSummaries(iotDomainOcid, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all DigitalTwinAdapterSummary in the specified state and IotDomain, if + * displayName is non null limits to only results with that displayName. If + * lifecycleStates is null then all states are allowed + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinAdapterSummaries(@NonNull String iotDomainOcid, + String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { ListDigitalTwinAdaptersRequest.Builder requestBuilder = ListDigitalTwinAdaptersRequest.builder() - .iotDomainId(iotDomainOcid); + .iotDomainId(iotDomainOcid).sortBy(ListDigitalTwinAdaptersRequest.SortBy.DisplayName) + .sortOrder(ListDigitalTwinAdaptersRequest.SortOrder.Asc); if (displayName != null) { requestBuilder.displayName(displayName); } + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } Iterable digitalTwinAdapterSummaries = iotClient.getPaginators() .listDigitalTwinAdaptersRecordIterator(requestBuilder.build()); return StreamSupport.stream(digitalTwinAdapterSummaries.spliterator(), false).toList(); } /** - * get a list of all DigitalTwinAdapter in the specified IoTDomainSummary + * get a list of all active DigitalTwinAdapter in the specified IoTDomainSummary * * @param iotDomainSummary * @return @@ -775,7 +1078,7 @@ public List listDigitalTwinAdapters(@NonNull IotDomainSummar } /** - * get a list of all DigitalTwinAdapter in the specified IoTDomain + * get a list of all active DigitalTwinAdapter in the specified IoTDomain * * @param iotDomain * @return @@ -786,7 +1089,7 @@ public List listDigitalTwinAdapters(@NonNull IotDomain iotDo } /** - * get a list of all DigitalTwinAdapter in the specified IoTDomain + * get a list of all active DigitalTwinAdapter in the specified IoTDomain * * @param iotDomainOcid * @return @@ -797,8 +1100,8 @@ public List listDigitalTwinAdapters(@NonNull String iotDomai } /** - * get a list of all DigitalTwinAdapter in the specified IoTDomainSummary, if - * displayName is not null it's used to limit the results + * get a list of all active DigitalTwinAdapter in the specified + * IoTDomainSummary, if displayName is not null it's used to limit the results * * @param iotDomainSummary * @param displayName @@ -810,8 +1113,8 @@ public List listDigitalTwinAdapters(@NonNull IotDomainSummar } /** - * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName - * is not null it's used to limit the results + * get a list of all active DigitalTwinModel in the specified IoTDomain, if + * displayName is not null it's used to limit the results * * @param iotDomain * @param displayName @@ -823,21 +1126,36 @@ public List listDigitalTwinAdapters(@NonNull IotDomain iotDo } /** - * get a list of all DigitalTwinModel in the specified IoTDomain, if displayName - * is not null it's used to limit the results + * get a list of all active DigitalTwinModel in the specified IoTDomain, if + * displayName is not null it's used to limit the results * * @param iotDomainOcid * @param displayName * @return */ public List listDigitalTwinAdapters(@NonNull String iotDomainOcid, String displayName) { - List modelSummaries = listDigitalTwinAdapterSummaries(iotDomainOcid, displayName); + return listDigitalTwinAdapters(iotDomainOcid, displayName, com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinModel in the specified state and IoTDomain, if + * displayName is not null it's used to limit the results. If lifecycleStates is + * null then all states match + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinAdapters(@NonNull String iotDomainOcid, String displayName, + com.oracle.bmc.iot.model.LifecycleState lifecycleState) { + List modelSummaries = listDigitalTwinAdapterSummaries(iotDomainOcid, displayName, + lifecycleState); return modelSummaries.stream().map(ms -> getDigitalTwinAdapter(ms)).toList(); } /** - * get the DigitalTwinAdapter in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinAdapter in the specified IotDomain with + * the displayName, returns null if there are no matches * * @param iotDomainSummary * @param displayName @@ -849,8 +1167,8 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull IotDomainSummary iotDom } /** - * get the DigitalTwinAdapter in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinAdapter in the specified IotDomain with + * the displayName, returns null if there are no matches * * @param iotDomain * @param displayName @@ -862,16 +1180,30 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull IotDomain iotDomain, @N } /** - * get the DigitalTwinAdapter in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinAdapter in the specified IotDomain with + * the displayName, returns null if there are no matches * * @param iotDomainOcid * @param displayName * @return */ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull String iotDomainOcid, @NonNull String displayName) { + return getDigitalTwinAdapter(iotDomainOcid, displayName, com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get the **FIRST** active DigitalTwinAdapter in the specified state and + * IotDomain with the displayName, returns null if there are no matches. if + * lifecycleState is null then all states match + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull String iotDomainOcid, @NonNull String displayName, + com.oracle.bmc.iot.model.LifecycleState lifecycleState) { List digitalTwinAdapterSummaries = listDigitalTwinAdapterSummaries(iotDomainOcid, - displayName); + displayName, lifecycleState); if (digitalTwinAdapterSummaries.isEmpty()) { return null; } @@ -879,7 +1211,7 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull String iotDomainOcid, @ } /** - * get the DigitalTwinAdapter from the specified summary + * get the DigitalTwinAdapter from the specified summary. * * @param digitalTwinAdapterSummary * @return @@ -891,7 +1223,7 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull DigitalTwinAdapterSumma } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain + * get all active DigitalTwinInstanceSummary in the specified IotDomain * * @param iotDomainSummary * @return @@ -902,7 +1234,7 @@ public List listDigitalTwinInstanceSummaries( } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain + * get all active DigitalTwinInstanceSummary in the specified IotDomain * * @param iotDomain * @return @@ -913,7 +1245,7 @@ public List listDigitalTwinInstanceSummaries(@NonNul } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain + * get all active DigitalTwinInstanceSummary in the specified IotDomain * * @param iotDomainOcid * @return @@ -924,8 +1256,8 @@ public List listDigitalTwinInstanceSummaries(@NonNul } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomainSummary * @return @@ -936,8 +1268,8 @@ public List listDigitalTwinInstanceSummaries(@NonNul } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomain * @return @@ -949,26 +1281,46 @@ public List listDigitalTwinInstanceSummaries(@NonNul } /** - * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName - * is non null limits to only results with that displayName + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName * * @param iotDomainOcid * @return */ public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, String displayName) { + return listDigitalTwinInstanceSummaries(iotDomainOcid, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all active DigitalTwinInstanceSummary in the specified state and + * IotDomain, if displayName is non null limits to only results with that + * displayName if the lifecycle state is null then all states match + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { ListDigitalTwinInstancesRequest.Builder requestBuilder = ListDigitalTwinInstancesRequest.builder() - .iotDomainId(iotDomainOcid); + .iotDomainId(iotDomainOcid).sortBy(ListDigitalTwinInstancesRequest.SortBy.DisplayName) + .sortOrder(ListDigitalTwinInstancesRequest.SortOrder.Asc); if (displayName != null) { requestBuilder.displayName(displayName); } + if (lifecycleState != null) { + requestBuilder.lifecycleState(lifecycleState); + } + Iterable digitalTwinInstanceSummaries = iotClient.getPaginators() .listDigitalTwinInstancesRecordIterator(requestBuilder.build()); return StreamSupport.stream(digitalTwinInstanceSummaries.spliterator(), false).toList(); } /** - * get a list of all DigitalTwinInstance in the specified IoTDomainSummary + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary * * @param iotDomainSummary * @return @@ -978,7 +1330,7 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm } /** - * get a list of all DigitalTwinInstance in the specified IoTDomain + * get a list of all active DigitalTwinInstance in the specified IoTDomain * * @param iotDomain * @return @@ -989,7 +1341,7 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot } /** - * get a list of all DigitalTwinInstance in the specified IoTDomain + * get a list of all active DigitalTwinInstance in the specified IoTDomain * * @param iotDomainOcid * @return @@ -1000,8 +1352,8 @@ public List listDigitalTwinInstances(@NonNull String iotDom } /** - * get a list of all DigitalTwinInstance in the specified IoTDomainSummary, if - * displayName is not null it's used to limit the results + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary, if displayName is not null it's used to limit the results * * @param iotDomainSummary * @param displayName @@ -1013,7 +1365,7 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm } /** - * get a list of all DigitalTwinInstance in the specified IoTDomain, if + * get a list of all active DigitalTwinInstance in the specified IoTDomain, if * displayName is not null it's used to limit the results * * @param iotDomain @@ -1026,8 +1378,8 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot } /** - * get a list of all DigitalTwinInstanceSummary in the specified IoTDomain, if - * displayName is not null it's used to limit the results + * get a list of all active DigitalTwinInstanceSummary in the specified + * IoTDomain, if displayName is not null it's used to limit the results * * @param iotDomainOcid * @param displayName @@ -1039,8 +1391,8 @@ public List listDigitalTwinInstances(@NonNull String iotDom } /** - * get the DigitalTwinInstance in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinInstance in the specified IotDomain with + * the displayName, returns null of there are no matches * * @param iotDomainSummary * @param displayName @@ -1052,8 +1404,8 @@ public DigitalTwinInstance getDigitalTwinInstance(@NonNull IotDomainSummary iotD } /** - * get the DigitalTwinInstance in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinInstance in the specified IotDomain with + * the displayName, returns null of there are no matches * * @param iotDomain * @param displayName @@ -1065,8 +1417,8 @@ public DigitalTwinInstance getDigitalTwinInstance(@NonNull IotDomain iotDomain, } /** - * get the DigitalTwinAdapter in the specified IotDomain with the displayName, - * returns null of there are no matches + * get the **FIRST** active DigitalTwinAdapter in the specified IotDomain with + * the displayName, returns null of there are no matches * * @param iotDomainOcid * @param displayName From 142b8245bc91969e89527d529c77d5e82cfe6bc6 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:21:00 +0000 Subject: [PATCH 07/10] added support for additional method to get entries by name, needed for the sample gateway functionality --- oci-java-sdk-simple-wrappers-testing/pom.xml | 2 +- oci-java-sdk-simple-wrappers/pom.xml | 2 +- .../com/oracle/timg/oci/iot/IoTProcessor.java | 222 +++++++++++++++++- .../oracle/timg/oci/vault/VaultProcessor.java | 110 ++++++++- 4 files changed, 319 insertions(+), 17 deletions(-) diff --git a/oci-java-sdk-simple-wrappers-testing/pom.xml b/oci-java-sdk-simple-wrappers-testing/pom.xml index a0fc0d6..daaaa64 100644 --- a/oci-java-sdk-simple-wrappers-testing/pom.xml +++ b/oci-java-sdk-simple-wrappers-testing/pom.xml @@ -8,7 +8,7 @@ OciTesting UTF-8 - 1.2.0 + 1.2.1 1.0.13 21 ${maven.compiler.source} diff --git a/oci-java-sdk-simple-wrappers/pom.xml b/oci-java-sdk-simple-wrappers/pom.xml index 967f421..5b8b025 100644 --- a/oci-java-sdk-simple-wrappers/pom.xml +++ b/oci-java-sdk-simple-wrappers/pom.xml @@ -41,7 +41,7 @@ SOFTWARE. --> com.oracle.timg.demo oci-java-sdk-simple-wrappers ocicore - 1.2.0 + 1.2.1 jar 21 diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java index 7ca3426..116b246 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java @@ -1230,7 +1230,19 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull DigitalTwinAdapterSumma */ public List listDigitalTwinInstanceSummaries( @NonNull IotDomainSummary iotDomainSummary) { - return listDigitalTwinInstanceSummaries(iotDomainSummary.getId()); + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), null, null, null); + } + + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, null); } /** @@ -1240,7 +1252,33 @@ public List listDigitalTwinInstanceSummaries( * @return */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain) { - return listDigitalTwinInstanceSummaries(iotDomain.getId()); + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), null, null, null); + + } + + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, null); + + } + + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, null); } @@ -1251,10 +1289,23 @@ public List listDigitalTwinInstanceSummaries(@NonNul * @return */ public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid) { - return listDigitalTwinInstanceSummaries(iotDomainOcid, null); + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, null, null, null); } + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, null); + } + /** * get all active DigitalTwinInstanceSummary in the specified IotDomain, if * displayName is non null limits to only results with that displayName @@ -1264,7 +1315,21 @@ public List listDigitalTwinInstanceSummaries(@NonNul */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, String displayName) { - return listDigitalTwinInstanceSummaries(iotDomainSummary.getId(), displayName); + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), null, displayName, null); + } + + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, null); + } /** @@ -1276,7 +1341,7 @@ public List listDigitalTwinInstanceSummaries(@NonNul */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, String displayName) { - return listDigitalTwinInstanceSummaries(iotDomain.getId(), displayName); + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), null, displayName, null); } @@ -1289,23 +1354,78 @@ public List listDigitalTwinInstanceSummaries(@NonNul */ public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, String displayName) { - return listDigitalTwinInstanceSummaries(iotDomainOcid, displayName, + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, null, displayName, null); + } + + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain, if + * displayName is non null limits to only results with that displayName + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, displayName, null, com.oracle.bmc.iot.model.LifecycleState.Active); } /** + * * get all active DigitalTwinInstanceSummary in the specified state and * IotDomain, if displayName is non null limits to only results with that * displayName if the lifecycle state is null then all states match * * @param iotDomainOcid + * @param displayName + * @param lifecycleState * @return */ public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, null, displayName, lifecycleState); + } + + /** + * + * get all active DigitalTwinInstanceSummary in the specified state and + * IotDomain, if displayName is non null limits to only results with that + * displayName if the lifecycle state is null then all states match, if + * digitalTwinModelOcid is null then matches all models + * + * @param iotDomainOcid + * @param digitalTwinModelOcid + * @param displayName + * @param lifecycleState + * @return + */ + public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, digitalTwinModelOcid, displayName, lifecycleState); + } + + /** + * + * get all active DigitalTwinInstanceSummary in the specified state and + * IotDomain, if displayName is non null limits to only results with that + * displayName if the lifecycle state is null then all states match, if + * digitalTwinModelOcid is null then matches all models + * + * @param iotDomainOcid + * @param digitalTwinModelOcid + * @param displayName + * @param lifecycleState + * @return + */ + private List listDigitalTwinInstanceSummariesReal(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { ListDigitalTwinInstancesRequest.Builder requestBuilder = ListDigitalTwinInstancesRequest.builder() .iotDomainId(iotDomainOcid).sortBy(ListDigitalTwinInstancesRequest.SortBy.DisplayName) .sortOrder(ListDigitalTwinInstancesRequest.SortOrder.Asc); + if (digitalTwinModelOcid != null) { + requestBuilder.digitalTwinModelId(digitalTwinModelOcid); + } + if (displayName != null) { requestBuilder.displayName(displayName); } @@ -1329,6 +1449,19 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm return listDigitalTwinInstances(iotDomainSummary.getId()); } + /** + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null); + } + /** * get a list of all active DigitalTwinInstance in the specified IoTDomain * @@ -1340,6 +1473,19 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot } + /** + * get a list of all active DigitalTwinInstance in the specified IoTDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstancesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null); + + } + /** * get a list of all active DigitalTwinInstance in the specified IoTDomain * @@ -1347,7 +1493,7 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot * @return */ public List listDigitalTwinInstances(@NonNull String iotDomainOcid) { - return listDigitalTwinInstances(iotDomainOcid, null); + return listDigitalTwinInstancesReal(iotDomainOcid, null, null); } @@ -1361,7 +1507,21 @@ public List listDigitalTwinInstances(@NonNull String iotDom */ public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, String displayName) { - return listDigitalTwinInstances(iotDomainSummary.getId(), displayName); + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, displayName); + } + + /** + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary, if displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName); } /** @@ -1373,7 +1533,22 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm * @return */ public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, String displayName) { - return listDigitalTwinInstances(iotDomain.getId(), displayName); + return listDigitalTwinInstancesReal(iotDomain.getId(), null, displayName); + + } + + /** + * get a list of all active DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstancesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName); } @@ -1386,7 +1561,34 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot * @return */ public List listDigitalTwinInstances(@NonNull String iotDomainOcid, String displayName) { - List modelSummaries = listDigitalTwinInstanceSummaries(iotDomainOcid, displayName); + return listDigitalTwinInstancesReal(iotDomainOcid, null, displayName); + } + + /** + * get a list of all active DigitalTwinInstanceSummary in the specified + * IoTDomain, if displayName is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + public List listDigitalTwinInstances(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName) { + return listDigitalTwinInstancesReal(iotDomainOcid, digitalTwinModelOcid, displayName); + } + + /** + * get a list of all active DigitalTwinInstanceSummary in the specified + * IoTDomain, if displayName is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + private List listDigitalTwinInstancesReal(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName) { + List modelSummaries = listDigitalTwinInstanceSummariesReal(iotDomainOcid, + digitalTwinModelOcid, displayName, null); return modelSummaries.stream().map(ms -> getDigitalTwinInstance(ms)).toList(); } diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java index 45af66f..9aa6800 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java @@ -324,6 +324,60 @@ public List listVaults(@NonNull String parentCompartmentOcid, String disp return vaultSummaries.stream().map(vs -> getVaultFromVaultSummary(vs)).toList(); } + /** + * gets the first matching vault with displayname in the compartment in active + * state, returns null if not found + * + * @param compartment + * @param displayName + * @return + */ + public Vault getVaultByName(@NonNull Compartment compartment, @NonNull String displayName) { + return getVaultByName(compartment, displayName, Vault.LifecycleState.Active); + } + + /** + * gets the first matching vault with displayname in the compartment in active + * state, returns null if not found + * + * @param parentCompartmentOcid + * @param displayName + * @return + */ + public Vault getVaultByName(@NonNull String parentCompartmentOcid, @NonNull String displayName) { + return getVaultByName(parentCompartmentOcid, displayName, Vault.LifecycleState.Active); + } + + /** + * gets the first matching vault with displayname in the compartment in the + * specified state (null matches all states), returns null if not found + * + * @param compartment + * @param displayName + * @return + */ + public Vault getVaultByName(@NonNull Compartment compartment, @NonNull String displayName, + Vault.LifecycleState lifecycleState) { + return getVaultByName(compartment.getId(), displayName, lifecycleState); + } + + /** + * gets the first matching vault with displayname in the compartment in the + * specified state (null matches all states), returns null if not found + * + * @param parentCompartmentOcid + * @param displayName + * @return + */ + public Vault getVaultByName(@NonNull String parentCompartmentOcid, @NonNull String displayName, + Vault.LifecycleState lifecycleState) { + List vaults = listVaults(parentCompartmentOcid, displayName, lifecycleState); + if (vaults.isEmpty()) { + return null; + } + return vaults.getFirst(); + } + public Vault getVaultFromVaultSummary(@NonNull VaultSummary vaultSummary) { return getVaultFromVaultSummary(vaultSummary.getId()); } @@ -444,6 +498,11 @@ public Key getKey(@NonNull VaultSummary vaultSummary, @NonNull String keyOcid) { return getKey(vaultSummary.getId(), vaultSummary.getManagementEndpoint(), keyOcid); } + public Key getKeyByName(@NonNull VaultSummary vaultSummary, @NonNull String keyName) { + KmsManagementClient kmsManagementClient = getKmsManagementClientForVault(vaultSummary); + return getKeyByName(kmsManagementClient, vaultSummary.getCompartmentId(), keyName); + } + public Key getKey(@NonNull Vault vault, @NonNull KeySummary keySummary) { return getKey(vault.getId(), vault.getManagementEndpoint(), keySummary.getId()); } @@ -452,6 +511,27 @@ public Key getKey(@NonNull Vault vault, @NonNull String keyOcid) { return getKey(vault.getId(), vault.getManagementEndpoint(), keyOcid); } + public Key getKeyByName(@NonNull Vault vault, @NonNull String keyName) { + KmsManagementClient kmsManagementClient = getKmsManagementClientForVault(vault); + return getKeyByName(kmsManagementClient, vault.getCompartmentId(), keyName); + } + + public Key getKeyByName(@NonNull KmsManagementClient kmsManagementClient, @NonNull String parentCompartmentOcid, + @NonNull String keyName) { + return getKeyByName(kmsManagementClient, parentCompartmentOcid, keyName, KeySummary.LifecycleState.Enabled); + } + + public Key getKeyByName(@NonNull KmsManagementClient kmsManagementClient, @NonNull String parentCompartmentOcid, + @NonNull String keyName, KeySummary.LifecycleState lifecycleState) { + List summaries = listKeySummaries(kmsManagementClient, parentCompartmentOcid, keyName, + lifecycleState); + if (summaries.isEmpty()) { + return null; + } + KeySummary first = summaries.getFirst(); + return getKey(first.getVaultId(), kmsManagementClient.getEndpoint(), first.getId()); + } + public Key getKey(@NonNull String vaultOcid, @NonNull String vaultEndpoint, @NonNull String keyOcid) { GetKeyRequest request = GetKeyRequest.builder().keyId(keyOcid).build(); KmsManagementClient kmvManagementClient = getKmsManagementClientForVault(vaultOcid, vaultEndpoint); @@ -898,8 +978,8 @@ public List listSecrets(@NonNull String compartmentOcid, String vaultOci * @param name * @return */ - public Secret getSecret(@NonNull VaultSummary vaultSummary, @NonNull String name) { - return getSecret(vaultSummary.getCompartmentId(), vaultSummary.getId(), name); + public Secret getSecretByName(@NonNull VaultSummary vaultSummary, @NonNull String name) { + return getSecretByName(vaultSummary.getCompartmentId(), vaultSummary.getId(), name); } /** @@ -910,8 +990,8 @@ public Secret getSecret(@NonNull VaultSummary vaultSummary, @NonNull String name * @param name * @return */ - public Secret getSecret(@NonNull Vault vault, @NonNull String name) { - return getSecret(vault.getCompartmentId(), vault.getId(), name); + public Secret getSecretByName(@NonNull Vault vault, @NonNull String name) { + return getSecretByName(vault.getCompartmentId(), vault.getId(), name); } /** @@ -923,7 +1003,7 @@ public Secret getSecret(@NonNull Vault vault, @NonNull String name) { * @param name * @return */ - public Secret getSecret(@NonNull String compartmentOcid, String vaultOcid, @NonNull String name) { + public Secret getSecretByName(@NonNull String compartmentOcid, String vaultOcid, @NonNull String name) { List secretSummaries = listSecretSummaries(compartmentOcid, vaultOcid, name, SecretSummary.LifecycleState.Active); if (secretSummaries.isEmpty()) { @@ -1531,6 +1611,26 @@ public SecretVersion getSecretVersion(@NonNull String secretOcid, @NonNull Long return response.getSecretVersion(); } + /** + * gets the contents of the CURRENT version of the secret + * + * @param secret + * @return + */ + public String getSecretContents(@NonNull Secret secret) { + return getSecretContentsReal(secret.getId(), null, null, null); + } + + /** + * gets the contents of the CURRENT version of the secret + * + * @param secretSummary + * @return + */ + public String getSecretContents(@NonNull SecretSummary secretSummary) { + return getSecretContentsReal(secretSummary.getId(), null, null, null); + } + /** * gets the contents of the CURRENT version of the secret * From d4159adbcc0f6e65971d172981923a258c258c31 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Thu, 26 Feb 2026 19:08:07 +0000 Subject: [PATCH 08/10] add instance retrieval methods which can filter for active instances only --- .../.classpath | 6 + .../.factorypath | 1 + oci-java-sdk-simple-wrappers-testing/pom.xml | 4 +- .../timg/demo/examples/iot/TestIoT.java | 22 +- oci-java-sdk-simple-wrappers/pom.xml | 2 +- .../com/oracle/timg/oci/iot/IoTProcessor.java | 346 ++++++++++++++++-- 6 files changed, 355 insertions(+), 26 deletions(-) diff --git a/oci-java-sdk-simple-wrappers-testing/.classpath b/oci-java-sdk-simple-wrappers-testing/.classpath index 28d610f..f53e74a 100644 --- a/oci-java-sdk-simple-wrappers-testing/.classpath +++ b/oci-java-sdk-simple-wrappers-testing/.classpath @@ -39,11 +39,17 @@ + + + + + + diff --git a/oci-java-sdk-simple-wrappers-testing/.factorypath b/oci-java-sdk-simple-wrappers-testing/.factorypath index e5823d2..29c5fd0 100644 --- a/oci-java-sdk-simple-wrappers-testing/.factorypath +++ b/oci-java-sdk-simple-wrappers-testing/.factorypath @@ -1,4 +1,5 @@ + diff --git a/oci-java-sdk-simple-wrappers-testing/pom.xml b/oci-java-sdk-simple-wrappers-testing/pom.xml index daaaa64..7f10ab4 100644 --- a/oci-java-sdk-simple-wrappers-testing/pom.xml +++ b/oci-java-sdk-simple-wrappers-testing/pom.xml @@ -8,7 +8,7 @@ OciTesting UTF-8 - 1.2.1 + 1.2.2 1.0.13 21 ${maven.compiler.source} @@ -17,7 +17,7 @@ com.oracle.timg.demo oci-java-sdk-simple-wrappers - ${version.ocicore} + ${version.ociwrappers} com.google.guava diff --git a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java index 33d8f34..afebe4d 100644 --- a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java +++ b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java @@ -140,7 +140,7 @@ public static void main(String[] args) throws Exception { digitalTwinInstances.stream() .map(dti -> new ChoiceDescription(dti.getDisplayName(), dti)) .toList()); - digitalTwinInstance = TextIOUtils.getParamChoice("Please chose the IoT domain group", + digitalTwinInstance = TextIOUtils.getParamChoice("Please chose the IoT instance form all instances", digitalTwinInstancesCdd); TextIOUtils.doOutput("You chose Digital Twin Instance " + digitalTwinInstance.getDisplayName()); } @@ -148,6 +148,26 @@ public static void main(String[] args) throws Exception { if (digitalTwinInstance != null) { getAndPrintLatestInstanceData(digitalTwinInstance); } + + List digitalTwinInstancesActive = iotProcessor.listDigitalTwinInstancesActive(iotDomain); + DigitalTwinInstance digitalTwinInstanceActive = null; + if (digitalTwinInstancesActive.isEmpty()) { + TextIOUtils.doOutput("No active Digital Twin Instances found in IotDomain " + iotDomain.getDisplayName()); + } else { + ChoiceDescriptionData digitalTwinInstancesActiveCdd = new ChoiceDescriptionData<>( + digitalTwinInstancesActive.stream() + .map(dti -> new ChoiceDescription(dti.getDisplayName(), dti)) + .toList()); + digitalTwinInstanceActive = TextIOUtils.getParamChoice( + "Please chose the active IoT instance form all instances", digitalTwinInstancesActiveCdd); + TextIOUtils + .doOutput("You chose active Digital Twin Instance " + digitalTwinInstanceActive.getDisplayName()); + } + + if (digitalTwinInstanceActive != null) { + getAndPrintLatestInstanceData(digitalTwinInstanceActive); + } + DigitalTwinInstance newDigitalTwinInstance = null; if ((digitalTwinInstance != null) && (digitalTwinAdapter != null) && (digitalTwinModel != null)) { if (TextIOUtils.getYN( diff --git a/oci-java-sdk-simple-wrappers/pom.xml b/oci-java-sdk-simple-wrappers/pom.xml index 5b8b025..c60ca76 100644 --- a/oci-java-sdk-simple-wrappers/pom.xml +++ b/oci-java-sdk-simple-wrappers/pom.xml @@ -41,7 +41,7 @@ SOFTWARE. --> com.oracle.timg.demo oci-java-sdk-simple-wrappers ocicore - 1.2.1 + 1.2.2 jar 21 diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java index 116b246..51744ed 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java @@ -1223,7 +1223,7 @@ public DigitalTwinAdapter getDigitalTwinAdapter(@NonNull DigitalTwinAdapterSumma } /** - * get all active DigitalTwinInstanceSummary in the specified IotDomain + * get all DigitalTwinInstanceSummary in the specified IotDomain * * @param iotDomainSummary * @return @@ -1239,6 +1239,18 @@ public List listDigitalTwinInstanceSummaries( * @param iotDomainSummary * @return */ + public List listDigitalTwinInstanceActiveSummaries( + @NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainSummary + * @return + */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, DigitalTwinModel digitalTwinModel) { return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), @@ -1248,6 +1260,19 @@ public List listDigitalTwinInstanceSummaries(@NonNul /** * get all active DigitalTwinInstanceSummary in the specified IotDomain * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceActiveSummaries( + @NonNull IotDomainSummary iotDomainSummary, DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * * @param iotDomain * @return */ @@ -1262,6 +1287,18 @@ public List listDigitalTwinInstanceSummaries(@NonNul * @param iotDomain * @return */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull IotDomain iotDomain) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomain + * @return + */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, DigitalTwinModel digitalTwinModel) { return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), @@ -1269,6 +1306,20 @@ public List listDigitalTwinInstanceSummaries(@NonNul } + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + /** * get all active DigitalTwinInstanceSummary in the specified IotDomain * @@ -1282,6 +1333,20 @@ public List listDigitalTwinInstanceSummaries(@NonNul } + /** + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull String iotDomainOcid, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + /** * get all active DigitalTwinInstanceSummary in the specified IotDomain * @@ -1294,8 +1359,20 @@ public List listDigitalTwinInstanceSummaries(@NonNul } /** - * get all active DigitalTwinInstanceSummary in the specified IotDomain, if - * displayName is non null limits to only results with that displayName + * get all active DigitalTwinInstanceSummary in the specified IotDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull String iotDomainOcid) { + return listDigitalTwinInstanceSummariesReal(iotDomainOcid, null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName * * @param iotDomainSummary * @return @@ -1313,6 +1390,20 @@ public List listDigitalTwinInstanceSummaries(@NonNul * @param iotDomainSummary * @return */ + public List listDigitalTwinInstanceActiveSummaries( + @NonNull IotDomainSummary iotDomainSummary, DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomainSummary + * @return + */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomainSummary iotDomainSummary, String displayName) { return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), null, displayName, null); @@ -1322,6 +1413,19 @@ public List listDigitalTwinInstanceSummaries(@NonNul * get all active DigitalTwinInstanceSummary in the specified IotDomain, if * displayName is non null limits to only results with that displayName * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstanceActiveSummaries( + @NonNull IotDomainSummary iotDomainSummary, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomainSummary.getId(), null, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * * @param iotDomain * @return */ @@ -1339,6 +1443,21 @@ public List listDigitalTwinInstanceSummaries(@NonNul * @param iotDomain * @return */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * + * @param iotDomain + * @return + */ public List listDigitalTwinInstanceSummaries(@NonNull IotDomain iotDomain, String displayName) { return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), null, displayName, null); @@ -1349,6 +1468,20 @@ public List listDigitalTwinInstanceSummaries(@NonNul * get all active DigitalTwinInstanceSummary in the specified IotDomain, if * displayName is non null limits to only results with that displayName * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstanceActiveSummaries(@NonNull IotDomain iotDomain, + String displayName) { + return listDigitalTwinInstanceSummariesReal(iotDomain.getId(), null, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get all DigitalTwinInstanceSummary in the specified IotDomain, if displayName + * is non null limits to only results with that displayName + * * @param iotDomainOcid * @return */ @@ -1364,7 +1497,7 @@ public List listDigitalTwinInstanceSummaries(@NonNul * @param iotDomainOcid * @return */ - public List listDigitalTwinInstanceSummaries(@NonNull String iotDomainOcid, + public List listDigitalTwinInstanceActiveSummaries(@NonNull String iotDomainOcid, String digitalTwinModelOcid, String displayName) { return listDigitalTwinInstanceSummariesReal(iotDomainOcid, displayName, null, com.oracle.bmc.iot.model.LifecycleState.Active); @@ -1438,6 +1571,16 @@ private List listDigitalTwinInstanceSummariesReal(@N return StreamSupport.stream(digitalTwinInstanceSummaries.spliterator(), false).toList(); } + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, null, null); + } + /** * get a list of all active DigitalTwinInstance in the specified * IoTDomainSummary @@ -1445,8 +1588,19 @@ private List listDigitalTwinInstanceSummariesReal(@N * @param iotDomainSummary * @return */ - public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary) { - return listDigitalTwinInstances(iotDomainSummary.getId()); + public List listDigitalTwinInstancesActive(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinActiveInstances(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, null, null); } /** @@ -1456,20 +1610,45 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm * @param iotDomainSummary * @return */ + public List listDigitalTwinActiveInstancesActive(@NonNull IotDomainSummary iotDomainSummary) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, DigitalTwinModel digitalTwinModel) { return listDigitalTwinInstancesReal(iotDomainSummary.getId(), - digitalTwinModel == null ? null : digitalTwinModel.getId(), null); + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, null); } /** - * get a list of all active DigitalTwinInstance in the specified IoTDomain + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary + * + * @param iotDomainSummary + * @return + */ + public List listDigitalTwinInstancesActive(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain * * @param iotDomain * @return */ public List listDigitalTwinInstances(@NonNull IotDomain iotDomain) { - return listDigitalTwinInstances(iotDomain.getId()); + return listDigitalTwinInstancesReal(iotDomain.getId(), null, null, null); } @@ -1479,21 +1658,58 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot * @param iotDomain * @return */ + public List listDigitalTwinInstancesActive(@NonNull IotDomain iotDomain) { + return listDigitalTwinInstancesReal(iotDomain.getId(), null, null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain + * + * @param iotDomain + * @return + */ public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, DigitalTwinModel digitalTwinModel) { return listDigitalTwinInstancesReal(iotDomain.getId(), - digitalTwinModel == null ? null : digitalTwinModel.getId(), null); + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, null); } /** * get a list of all active DigitalTwinInstance in the specified IoTDomain * + * @param iotDomain + * @return + */ + public List listDigitalTwinInstancesActive(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel) { + return listDigitalTwinInstancesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), null, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain + * * @param iotDomainOcid * @return */ public List listDigitalTwinInstances(@NonNull String iotDomainOcid) { - return listDigitalTwinInstancesReal(iotDomainOcid, null, null); + return listDigitalTwinInstancesReal(iotDomainOcid, null, null, null); + + } + + /** + * get a list of all active DigitalTwinInstance in the specified IoTDomain + * + * @param iotDomainOcid + * @return + */ + public List listDigitalTwinInstancesActive(@NonNull String iotDomainOcid) { + return listDigitalTwinInstancesReal(iotDomainOcid, null, null, com.oracle.bmc.iot.model.LifecycleState.Active); } @@ -1507,7 +1723,7 @@ public List listDigitalTwinInstances(@NonNull String iotDom */ public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, String displayName) { - return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, displayName); + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, displayName, null); } /** @@ -1518,14 +1734,43 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm * @param displayName * @return */ + public List listDigitalTwinInstancesActive(@NonNull IotDomainSummary iotDomainSummary, + String displayName) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), null, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomainSummary, if + * displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ public List listDigitalTwinInstances(@NonNull IotDomainSummary iotDomainSummary, DigitalTwinModel digitalTwinModel, String displayName) { return listDigitalTwinInstancesReal(iotDomainSummary.getId(), - digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName); + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, null); } /** - * get a list of all active DigitalTwinInstance in the specified IoTDomain, if + * get a list of all active DigitalTwinInstance in the specified + * IoTDomainSummary, if displayName is not null it's used to limit the results + * + * @param iotDomainSummary + * @param displayName + * @return + */ + public List listDigitalTwinInstancesActive(@NonNull IotDomainSummary iotDomainSummary, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstancesReal(iotDomainSummary.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain, if * displayName is not null it's used to limit the results * * @param iotDomain @@ -1533,7 +1778,7 @@ public List listDigitalTwinInstances(@NonNull IotDomainSumm * @return */ public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, String displayName) { - return listDigitalTwinInstancesReal(iotDomain.getId(), null, displayName); + return listDigitalTwinInstancesReal(iotDomain.getId(), null, displayName, null); } @@ -1545,23 +1790,53 @@ public List listDigitalTwinInstances(@NonNull IotDomain iot * @param displayName * @return */ + public List listDigitalTwinInstancesActive(@NonNull IotDomain iotDomain, String displayName) { + return listDigitalTwinInstancesReal(iotDomain.getId(), null, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ public List listDigitalTwinInstances(@NonNull IotDomain iotDomain, DigitalTwinModel digitalTwinModel, String displayName) { return listDigitalTwinInstancesReal(iotDomain.getId(), - digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName); + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, null); } /** - * get a list of all active DigitalTwinInstanceSummary in the specified - * IoTDomain, if displayName is not null it's used to limit the results + * get a list of all active DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomain + * @param displayName + * @return + */ + public List listDigitalTwinInstancesActive(@NonNull IotDomain iotDomain, + DigitalTwinModel digitalTwinModel, String displayName) { + return listDigitalTwinInstancesReal(iotDomain.getId(), + digitalTwinModel == null ? null : digitalTwinModel.getId(), displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results * * @param iotDomainOcid * @param displayName * @return */ public List listDigitalTwinInstances(@NonNull String iotDomainOcid, String displayName) { - return listDigitalTwinInstancesReal(iotDomainOcid, null, displayName); + return listDigitalTwinInstancesReal(iotDomainOcid, null, displayName, null); } /** @@ -1572,9 +1847,22 @@ public List listDigitalTwinInstances(@NonNull String iotDom * @param displayName * @return */ + public List listDigitalTwinInstancesActive(@NonNull String iotDomainOcid, String displayName) { + return listDigitalTwinInstancesReal(iotDomainOcid, null, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all DigitalTwinInstance in the specified IoTDomain, if + * displayName is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ public List listDigitalTwinInstances(@NonNull String iotDomainOcid, String digitalTwinModelOcid, String displayName) { - return listDigitalTwinInstancesReal(iotDomainOcid, digitalTwinModelOcid, displayName); + return listDigitalTwinInstancesReal(iotDomainOcid, digitalTwinModelOcid, displayName, null); } /** @@ -1585,10 +1873,24 @@ public List listDigitalTwinInstances(@NonNull String iotDom * @param displayName * @return */ - private List listDigitalTwinInstancesReal(@NonNull String iotDomainOcid, + public List listDigitalTwinInstancesActive(@NonNull String iotDomainOcid, String digitalTwinModelOcid, String displayName) { + return listDigitalTwinInstancesReal(iotDomainOcid, digitalTwinModelOcid, displayName, + com.oracle.bmc.iot.model.LifecycleState.Active); + } + + /** + * get a list of all active DigitalTwinInstanceSummary in the specified + * IoTDomain, if displayName is not null it's used to limit the results + * + * @param iotDomainOcid + * @param displayName + * @return + */ + private List listDigitalTwinInstancesReal(@NonNull String iotDomainOcid, + String digitalTwinModelOcid, String displayName, com.oracle.bmc.iot.model.LifecycleState lifecycleState) { List modelSummaries = listDigitalTwinInstanceSummariesReal(iotDomainOcid, - digitalTwinModelOcid, displayName, null); + digitalTwinModelOcid, displayName, lifecycleState); return modelSummaries.stream().map(ms -> getDigitalTwinInstance(ms)).toList(); } From 89aacdb73a2dda524ca72265c1d19c90c4c13ed2 Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:39:37 +0000 Subject: [PATCH 09/10] update method and class names to use correct cammel case (IOT/IoT to Iot) --- .../.classpath | 6 --- .../.factorypath | 1 - .../iot/{TestIoT.java => TestIot.java} | 10 ++-- .../{IoTProcessor.java => IotProcessor.java} | 50 +++++++++---------- 4 files changed, 30 insertions(+), 37 deletions(-) rename oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/{TestIoT.java => TestIot.java} (98%) rename oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/{IoTProcessor.java => IotProcessor.java} (97%) diff --git a/oci-java-sdk-simple-wrappers-testing/.classpath b/oci-java-sdk-simple-wrappers-testing/.classpath index f53e74a..28d610f 100644 --- a/oci-java-sdk-simple-wrappers-testing/.classpath +++ b/oci-java-sdk-simple-wrappers-testing/.classpath @@ -39,17 +39,11 @@ - - - - - - diff --git a/oci-java-sdk-simple-wrappers-testing/.factorypath b/oci-java-sdk-simple-wrappers-testing/.factorypath index 29c5fd0..e5823d2 100644 --- a/oci-java-sdk-simple-wrappers-testing/.factorypath +++ b/oci-java-sdk-simple-wrappers-testing/.factorypath @@ -1,5 +1,4 @@ - diff --git a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIot.java similarity index 98% rename from oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java rename to oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIot.java index afebe4d..ae6c5a2 100644 --- a/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIoT.java +++ b/oci-java-sdk-simple-wrappers-testing/src/main/java/com/oracle/timg/demo/examples/iot/TestIot.java @@ -54,24 +54,24 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on import com.oracle.bmc.iot.model.IotDomainGroup; import com.oracle.timg.oci.authentication.AuthenticationProcessor; import com.oracle.timg.oci.identity.IdentityProcessor; -import com.oracle.timg.oci.iot.IoTProcessor; +import com.oracle.timg.oci.iot.IotProcessor; import com.oracle.timg.oci.vault.VaultProcessor; import timgutilities.textio.ChoiceDescription; import timgutilities.textio.ChoiceDescriptionData; import timgutilities.textio.TextIOUtils; -public class TestIoT { +public class TestIot { static AuthenticationProcessor authenticationProcessor; static IdentityProcessor identityProcessor; - static IoTProcessor iotProcessor; + static IotProcessor iotProcessor; static VaultProcessor vaultProcessor; public static void main(String[] args) throws Exception { TextIOUtils.doOutput("Configuring OCI connection"); authenticationProcessor = new AuthenticationProcessor("DEFAULT"); identityProcessor = new IdentityProcessor(authenticationProcessor); - iotProcessor = new IoTProcessor(authenticationProcessor); + iotProcessor = new IotProcessor(authenticationProcessor); vaultProcessor = new VaultProcessor(authenticationProcessor); String compartmentPath = TextIOUtils.getString("Please enter the compartment path to operate in", @@ -83,7 +83,7 @@ public static void main(String[] args) throws Exception { } TextIOUtils.doOutput("OCID of " + compartmentPath + " is " + compartment.getId()); - List iotDomainGroups = iotProcessor.listIoTDomainGroupsInCompartment(compartment); + List iotDomainGroups = iotProcessor.listIotDomainGroupsInCompartment(compartment); if (iotDomainGroups.isEmpty()) { TextIOUtils.doOutput("No Iot Domain Groups found in compartment " + compartmentPath + ", cannot continue"); return; diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IotProcessor.java similarity index 97% rename from oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java rename to oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IotProcessor.java index 51744ed..df688bc 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IoTProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/iot/IotProcessor.java @@ -90,7 +90,7 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on * easier */ @Slf4j -public class IoTProcessor { +public class IotProcessor { private final AuthenticationProcessor authProcessor; @Getter private final IotClient iotClient; @@ -101,7 +101,7 @@ public class IoTProcessor { * * @param authProcessor */ - public IoTProcessor(AuthenticationProcessor authProcessor) { + public IotProcessor(AuthenticationProcessor authProcessor) { this.authProcessor = authProcessor; iotClient = IotClient.builder().region(authProcessor.getRegionName()).build(authProcessor.getProvider()); } @@ -122,8 +122,8 @@ public void setRegion(@NonNull String regionName) { * * @return */ - public List listIoTDomainGroupSummariesInTenancy() { - return listIoTDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); + public List listIotDomainGroupSummariesInTenancy() { + return listIotDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); } /** @@ -133,9 +133,9 @@ public List listIoTDomainGroupSummariesInTenancy() { * @param parentCompartment * @return */ - public List listIoTDomainGroupSummariesInCompartment( + public List listIotDomainGroupSummariesInCompartment( @NonNull Compartment parentCompartment) { - return listIoTDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); + return listIotDomainGroupSummariesInCompartment(authProcessor.getTenancyOCID()); } /** @@ -145,8 +145,8 @@ public List listIoTDomainGroupSummariesInCompartment( * @param parentCompartmentOcid * @return */ - public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid) { - return listIoTDomainGroupSummariesInCompartment(parentCompartmentOcid, null); + public List listIotDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid) { + return listIotDomainGroupSummariesInCompartment(parentCompartmentOcid, null); } /** @@ -158,9 +158,9 @@ public List listIoTDomainGroupSummariesInCompartment(@Non * * @return */ - public List listIoTDomainGroupSummariesInCompartment(@NonNull Compartment parentCompartment, + public List listIotDomainGroupSummariesInCompartment(@NonNull Compartment parentCompartment, String displayName) { - return listIoTDomainGroupSummariesInCompartment(parentCompartment.getId(), displayName); + return listIotDomainGroupSummariesInCompartment(parentCompartment.getId(), displayName); } /** @@ -172,9 +172,9 @@ public List listIoTDomainGroupSummariesInCompartment(@Non * * @return */ - public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, + public List listIotDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, String displayName) { - return listIoTDomainGroupSummariesInCompartment(parentCompartmentOcid, displayName, + return listIotDomainGroupSummariesInCompartment(parentCompartmentOcid, displayName, IotDomainGroup.LifecycleState.Active); } @@ -188,7 +188,7 @@ public List listIoTDomainGroupSummariesInCompartment(@Non * * @return */ - public List listIoTDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, + public List listIotDomainGroupSummariesInCompartment(@NonNull String parentCompartmentOcid, String displayName, IotDomainGroup.LifecycleState lifecycleState) { ListIotDomainGroupsRequest.Builder requestBuilder = ListIotDomainGroupsRequest.builder() .compartmentId(parentCompartmentOcid).sortBy(ListIotDomainGroupsRequest.SortBy.DisplayName) @@ -209,8 +209,8 @@ public List listIoTDomainGroupSummariesInCompartment(@Non * * @return */ - public List listIoTDomainGroupsInTenancy() { - return listIoTDomainGroupsInCompartment(authProcessor.getTenancyOCID()); + public List listIotDomainGroupsInTenancy() { + return listIotDomainGroupsInCompartment(authProcessor.getTenancyOCID()); } /** @@ -220,8 +220,8 @@ public List listIoTDomainGroupsInTenancy() { * @param parentCompartmentOcid * @return */ - public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid) { - return listIoTDomainGroupsInCompartment(parentCompartmentOcid, null); + public List listIotDomainGroupsInCompartment(@NonNull String parentCompartmentOcid) { + return listIotDomainGroupsInCompartment(parentCompartmentOcid, null); } /** @@ -231,8 +231,8 @@ public List listIoTDomainGroupsInCompartment(@NonNull String par * @param parentCompartmentOcid * @return */ - public List listIoTDomainGroupsInCompartment(@NonNull Compartment parentCompartment) { - return listIoTDomainGroupsInCompartment(parentCompartment.getId(), null); + public List listIotDomainGroupsInCompartment(@NonNull Compartment parentCompartment) { + return listIotDomainGroupsInCompartment(parentCompartment.getId(), null); } /** @@ -245,9 +245,9 @@ public List listIoTDomainGroupsInCompartment(@NonNull Compartmen * * @return */ - public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, + public List listIotDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, String displayName) { - return listIoTDomainGroupsInCompartment(parentCompartmentOcid, displayName, + return listIotDomainGroupsInCompartment(parentCompartmentOcid, displayName, IotDomainGroup.LifecycleState.Active); } @@ -261,9 +261,9 @@ public List listIoTDomainGroupsInCompartment(@NonNull String par * * @return */ - public List listIoTDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, + public List listIotDomainGroupsInCompartment(@NonNull String parentCompartmentOcid, String displayName, IotDomainGroup.LifecycleState lifecycleState) { - List domainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + List domainGroupSummaries = listIotDomainGroupSummariesInCompartment( parentCompartmentOcid, displayName, lifecycleState); return domainGroupSummaries.stream().map(dsg -> getIotDomainGroup(dsg)).toList(); } @@ -295,7 +295,7 @@ public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentComp */ public IotDomainGroupSummary getIotDomainGroupSummary(@NonNull String parentCompartmentOcid, @NonNull String displayName, IotDomainGroup.LifecycleState lifecycleState) { - List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + List iotDomainGroupSummaries = listIotDomainGroupSummariesInCompartment( parentCompartmentOcid, displayName, lifecycleState); if (iotDomainGroupSummaries.isEmpty()) { return null; @@ -330,7 +330,7 @@ public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @ */ public IotDomainGroup getIotDomainGroup(@NonNull String parentCompartmentOcid, @NonNull String displayName, IotDomainGroup.LifecycleState lifecycleState) { - List iotDomainGroupSummaries = listIoTDomainGroupSummariesInCompartment( + List iotDomainGroupSummaries = listIotDomainGroupSummariesInCompartment( parentCompartmentOcid, displayName, lifecycleState); if (iotDomainGroupSummaries.isEmpty()) { return null; From 0a1d55b6d3cc20a312a2e8823c91b4e0fc28d0bc Mon Sep 17 00:00:00 2001 From: tim_graves <28924492+atimgraves@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:56:24 +0000 Subject: [PATCH 10/10] when checking for secrete creation check for seconds, not milliseconds --- .../main/java/com/oracle/timg/oci/vault/VaultProcessor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java index 9aa6800..b6b6394 100644 --- a/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java +++ b/oci-java-sdk-simple-wrappers/src/main/java/com/oracle/timg/oci/vault/VaultProcessor.java @@ -37,6 +37,7 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on package com.oracle.timg.oci.vault; import java.io.IOException; +import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -1184,7 +1185,7 @@ public Boolean waitForSecretToBecomeActive(@NonNull Secret secret, int secondsBe while ((remainingSeconds > 0) && (!secretToTest.getLifecycleState().equals(Secret.LifecycleState.Active))) { remainingSeconds -= secondsBetweenChecks; try { - Thread.sleep(secondsBetweenChecks); + Thread.sleep(Duration.ofSeconds(secondsBetweenChecks)); } catch (InterruptedException e) { return null; }