@@ -46,6 +46,38 @@ export async function listAdbDatabases(compartmentId) {
46
46
}
47
47
}
48
48
49
+ export async function listAdbDatabasesbyname ( adbName , compartmentId ) {
50
+ try {
51
+ const { stdout, exitCode, stderr } = await $ `oci db autonomous-database list --all --compartment-id ${ compartmentId } --display-name ${ adbName } ` ;
52
+ if ( exitCode !== 0 ) {
53
+ console . error ( "Error:" , stderr ) ;
54
+ return ;
55
+ }
56
+
57
+ const response = JSON . parse ( stdout . trim ( ) ) ;
58
+ // console.log("Full API Response:", response);
59
+
60
+ const connectionStrings = response . data [ 0 ] [ 'connection-strings' ] ;
61
+
62
+ if ( typeof connectionStrings === 'object' && connectionStrings !== null ) {
63
+
64
+ // Finding the 'HIGH' consumer group in profiles array
65
+ const highConsumerGroupDisplayName = connectionStrings . profiles . find ( profile => profile [ 'consumer-group' ] === "HIGH" ) ;
66
+ if ( highConsumerGroupDisplayName ) {
67
+ const adbDisplayName = highConsumerGroupDisplayName [ 'display-name' ] ;
68
+ // console.log("adbDisplayName:", adbDisplayName);
69
+ return adbDisplayName ;
70
+ } else {
71
+ console . error ( "Error: No 'HIGH' consumer group found in the response." ) ;
72
+ }
73
+ } else {
74
+ console . error ( "Error: 'connection-strings' is not an object in the response." ) ;
75
+ }
76
+ } catch ( error ) {
77
+ console . error ( "Error:" , error ) ;
78
+ }
79
+ }
80
+
49
81
export async function downloadAdbWallet ( adbId , walletFilePath , walletPassword ) {
50
82
try {
51
83
const { stdout, exitCode, stderr } =
@@ -124,6 +156,27 @@ export async function searchCompartmentIdByName(compartmentName) {
124
156
}
125
157
}
126
158
159
+ export async function searchAdbIdByName ( adbName , compartmentId ) {
160
+ if ( ! adbName ) {
161
+ exitWithError ( "ADB name required" ) ;
162
+ }
163
+ try {
164
+ const { stdout, exitCode, stderr } =
165
+ await $ `oci db autonomous-database list --compartment-id ${ compartmentId } --query "data[?\"display-name\"=='${ adbName } '].id"` ;
166
+ if ( exitCode !== 0 ) {
167
+ exitWithError ( stderr ) ;
168
+ }
169
+ const adbIds = JSON . parse ( stdout . trim ( ) ) ;
170
+ if ( adbIds . length === 0 ) {
171
+ exitWithError ( "ADB name not found" ) ;
172
+ }
173
+ const adbId = adbIds [ 0 ] ;
174
+ return adbId ;
175
+ } catch ( error ) {
176
+ exitWithError ( error . stderr ) ;
177
+ }
178
+ }
179
+
127
180
export async function uploadApiKeyFile ( userId , publicKeyPath ) {
128
181
if ( ! userId ) {
129
182
exitWithError ( "User ID required" ) ;
0 commit comments