Skip to content

Commit 32f6366

Browse files
authored
[OpenRewrite] Increase full migration sample size (Azure#43987)
* Additional samples * Additional samples * Fix app-data-config samples * Fix app-security-keyvault-administration samples * Fix app-security-keyvault-certificates samples * Fix app-security-keyvault-jca samples * Fix app-security-keyvault-keys samples * Fix app-security-keyvault-secrets samples * Fix azure-storage-blob samples * Fix azure-storage-queue samples
1 parent bedbe70 commit 32f6366

File tree

281 files changed

+51902
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+51902
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
# Azure OpenRewrite Plugin library for Java
2+
3+
The Azure OpenRewrite Plugin library for Java is a collection recipes that when used in conjunction with the
4+
[OpenRewrite Plugin by Modern](https://docs.openrewrite.org/) allows the developers of the SDKs to write migration
5+
recipes that can be used to automatically update the SDKs, elimination the need for tedious manual refactoring.
6+
27
## Getting started
8+
9+
TBD
10+
311
## Key concepts
12+
13+
TBD
14+
415
## Examples
16+
17+
TBD
18+
519
## Troubleshooting
20+
21+
TBD
22+
623
## Next steps
24+
25+
TBD
26+
727
## Contributing
28+
29+
TBD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.appconfiguration;
5+
6+
import com.azure.data.appconfiguration.models.ConfigurationSetting;
7+
import com.azure.identity.DefaultAzureCredential;
8+
import com.azure.identity.DefaultAzureCredentialBuilder;
9+
10+
/**
11+
* Sample demonstrates how to use AAD token to build a configuration client.
12+
*/
13+
public class AadAuthentication {
14+
/**
15+
* Sample for how to use AAD token Authentication.
16+
*
17+
* @param args Unused. Arguments to the program.
18+
*/
19+
public static void main(String[] args) {
20+
// The endpoint can be obtained by going to your App Configuration instance in the Azure portal
21+
// and navigating to "Overview" page. Looking for the "Endpoint" keyword.
22+
String endpoint = "{endpoint_value}";
23+
24+
// Default token credential could be obtained from Identity service.
25+
// It tries to create a valid credential in the following order:
26+
// EnvironmentCredential
27+
// ManagedIdentityCredential
28+
// SharedTokenCacheCredential
29+
// Fails if none of the credentials above could be created.
30+
DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
31+
32+
final ConfigurationClient client = new ConfigurationClientBuilder()
33+
.credential(tokenCredential) // AAD authentication
34+
.endpoint(endpoint)
35+
.buildClient();
36+
37+
// Name of the key to add to the configuration service.
38+
final String key = "hello";
39+
final String value = "world";
40+
41+
System.out.println("Beginning of synchronous sample...");
42+
43+
ConfigurationSetting setting = client.setConfigurationSetting(key, null, value);
44+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
45+
46+
setting = client.getConfigurationSetting(key, null, null);
47+
System.out.printf("[GetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
48+
49+
setting = client.deleteConfigurationSetting(key, null);
50+
System.out.printf("[DeleteConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
51+
52+
System.out.println("End of synchronous sample.");
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.appconfiguration;
5+
6+
import com.azure.data.appconfiguration.models.ConfigurationSetting;
7+
import com.azure.identity.DefaultAzureCredential;
8+
import com.azure.identity.DefaultAzureCredentialBuilder;
9+
10+
/**
11+
* Sample demonstrates how to use AAD token to build a configuration client.
12+
*/
13+
public class AadAuthentication {
14+
/**
15+
* Sample for how to use AAD token Authentication.
16+
*
17+
* @param args Unused. Arguments to the program.
18+
*/
19+
public static void main(String[] args) {
20+
// The endpoint can be obtained by going to your App Configuration instance in the Azure portal
21+
// and navigating to "Overview" page. Looking for the "Endpoint" keyword.
22+
String endpoint = "{endpoint_value}";
23+
24+
// Default token credential could be obtained from Identity service.
25+
// It tries to create a valid credential in the following order:
26+
// EnvironmentCredential
27+
// ManagedIdentityCredential
28+
// SharedTokenCacheCredential
29+
// Fails if none of the credentials above could be created.
30+
DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
31+
32+
final ConfigurationClient client = new ConfigurationClientBuilder()
33+
.credential(tokenCredential) // AAD authentication
34+
.endpoint(endpoint)
35+
.buildClient();
36+
37+
// Name of the key to add to the configuration service.
38+
final String key = "hello";
39+
final String value = "world";
40+
41+
System.out.println("Beginning of synchronous sample...");
42+
43+
ConfigurationSetting setting = client.setConfigurationSetting(key, null, value);
44+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
45+
46+
setting = client.getConfigurationSetting(key, null, null);
47+
System.out.printf("[GetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
48+
49+
setting = client.deleteConfigurationSetting(key, null);
50+
System.out.printf("[DeleteConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
51+
52+
System.out.println("End of synchronous sample.");
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.appconfiguration;
5+
6+
import com.azure.data.appconfiguration.models.ConfigurationSetting;
7+
import com.azure.data.appconfiguration.models.ConfigurationSettingsFilter;
8+
import com.azure.data.appconfiguration.models.ConfigurationSnapshot;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.concurrent.TimeUnit;
13+
14+
/**
15+
* Sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and list settings
16+
* by snapshot name asynchronously.
17+
*/
18+
public class CreateSnapshotAsync {
19+
/**
20+
* Runs the sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and
21+
* list settings by snapshot name asynchronously.
22+
*
23+
* @param args Unused. Arguments to the program.
24+
* @throws InterruptedException when a thread is waiting, sleeping, or otherwise occupied,
25+
* and the thread is interrupted, either before or during the activity.
26+
*/
27+
public static void main(String[] args) throws InterruptedException {
28+
// The connection string value can be obtained by going to your App Configuration instance in the Azure portal
29+
// and navigating to "Access Keys" page under the "Settings" section.
30+
String connectionString = "endpoint={endpoint_value};id={id_value};secret={secret_value}";
31+
32+
// Asynchronous sample
33+
// Instantiate a client that will be used to call the service.
34+
final ConfigurationAsyncClient client = new ConfigurationClientBuilder()
35+
.connectionString(connectionString)
36+
.buildAsyncClient();
37+
// Prepare first setting.
38+
client.setConfigurationSetting("TestKey1", null, "v1").subscribe(
39+
result -> {
40+
final ConfigurationSetting setting = result;
41+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
42+
},
43+
error -> System.err.println("There was an error adding the setting: " + error),
44+
() -> System.out.printf("Set setting with key=%s and value=%s added or updated.%n", "key1", "v1"));
45+
46+
// Prepare second setting.
47+
client.setConfigurationSetting("TestKey2", null, "v2").subscribe(
48+
result -> {
49+
final ConfigurationSetting setting = result;
50+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s.%n", setting.getKey(), setting.getValue());
51+
},
52+
error -> System.err.println("There was an error adding the setting: " + error),
53+
() -> System.out.printf("Set setting with key=%s and value=%s added or updated.%n", "key2", "v2"));
54+
55+
TimeUnit.MILLISECONDS.sleep(1000);
56+
57+
// Prepare the snapshot filters
58+
List<ConfigurationSettingsFilter> filters = new ArrayList<>();
59+
// Key Name also supports RegExp but only support prefix end with "*", such as "k*" and is case-sensitive.
60+
filters.add(new ConfigurationSettingsFilter("Test*"));
61+
String snapshotName = "{snapshotName}";
62+
63+
client.beginCreateSnapshot(snapshotName, new ConfigurationSnapshot(filters))
64+
.flatMap(result -> result.getFinalResult())
65+
.subscribe(
66+
snapshot -> {
67+
System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
68+
snapshot.getName(), snapshot.getCreatedAt(), snapshot.getStatus());
69+
},
70+
ex -> System.out.printf("Error on creating a snapshot=%s, with error=%s.%n", snapshotName, ex.getMessage()),
71+
() -> System.out.println("Successfully created a snapshot."));
72+
73+
// Get the snapshot status
74+
client.getSnapshot(snapshotName).subscribe(
75+
getSnapshot -> {
76+
System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
77+
getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus());
78+
}
79+
);
80+
81+
TimeUnit.MILLISECONDS.sleep(1000);
82+
83+
// Archive a READY snapshot
84+
client.archiveSnapshot(snapshotName).subscribe(
85+
archivedSnapshot -> {
86+
System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n",
87+
archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());
88+
}
89+
);
90+
91+
TimeUnit.MILLISECONDS.sleep(1000);
92+
93+
// Recover the Archived snapshot
94+
client.recoverSnapshot(snapshotName).subscribe(
95+
recoveredSnapshot -> {
96+
System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n",
97+
recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());
98+
}
99+
);
100+
101+
TimeUnit.MILLISECONDS.sleep(1000);
102+
103+
// List the configuration settings in the snapshot
104+
client.listConfigurationSettingsForSnapshot(snapshotName).subscribe(
105+
settingInSnapshot -> {
106+
System.out.printf("[ConfigurationSetting in snapshot] Key: %s, Value: %s.%n",
107+
settingInSnapshot.getKey(), settingInSnapshot.getValue());
108+
}
109+
);
110+
111+
TimeUnit.MILLISECONDS.sleep(1000);
112+
113+
// The .subscribe() creation and assignment is not a blocking call. For the purpose of this example, we sleep
114+
// the thread so the program does not end before the send operation is complete. Using .block() instead of
115+
// .subscribe() will turn this into a synchronous call.
116+
try {
117+
TimeUnit.MINUTES.sleep(5);
118+
} catch (InterruptedException e) {
119+
e.printStackTrace();
120+
}
121+
}
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.data.appconfiguration;
5+
6+
import com.azure.data.appconfiguration.models.ConfigurationSetting;
7+
import com.azure.data.appconfiguration.models.ConfigurationSettingsFilter;
8+
import com.azure.data.appconfiguration.models.ConfigurationSnapshot;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.concurrent.TimeUnit;
13+
14+
/**
15+
* Sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and list settings
16+
* by snapshot name asynchronously.
17+
*/
18+
public class CreateSnapshotAsync {
19+
/**
20+
* Runs the sample demonstrates how to create, retrieve, archive, recover a configuration setting snapshot, and
21+
* list settings by snapshot name asynchronously.
22+
*
23+
* @param args Unused. Arguments to the program.
24+
* @throws InterruptedException when a thread is waiting, sleeping, or otherwise occupied,
25+
* and the thread is interrupted, either before or during the activity.
26+
*/
27+
public static void main(String[] args) throws InterruptedException {
28+
// The connection string value can be obtained by going to your App Configuration instance in the Azure portal
29+
// and navigating to "Access Keys" page under the "Settings" section.
30+
String connectionString = "endpoint={endpoint_value};id={id_value};secret={secret_value}";
31+
32+
// Asynchronous sample
33+
// Instantiate a client that will be used to call the service.
34+
final ConfigurationAsyncClient client = new ConfigurationClientBuilder()
35+
.connectionString(connectionString)
36+
.buildAsyncClient();
37+
// Prepare first setting.
38+
client.setConfigurationSetting("TestKey1", null, "v1").subscribe(
39+
result -> {
40+
final ConfigurationSetting setting = result;
41+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s", setting.getKey(), setting.getValue());
42+
},
43+
error -> System.err.println("There was an error adding the setting: " + error),
44+
() -> System.out.printf("Set setting with key=%s and value=%s added or updated.%n", "key1", "v1"));
45+
46+
// Prepare second setting.
47+
client.setConfigurationSetting("TestKey2", null, "v2").subscribe(
48+
result -> {
49+
final ConfigurationSetting setting = result;
50+
System.out.printf("[SetConfigurationSetting] Key: %s, Value: %s.%n", setting.getKey(), setting.getValue());
51+
},
52+
error -> System.err.println("There was an error adding the setting: " + error),
53+
() -> System.out.printf("Set setting with key=%s and value=%s added or updated.%n", "key2", "v2"));
54+
55+
TimeUnit.MILLISECONDS.sleep(1000);
56+
57+
// Prepare the snapshot filters
58+
List<ConfigurationSettingsFilter> filters = new ArrayList<>();
59+
// Key Name also supports RegExp but only support prefix end with "*", such as "k*" and is case-sensitive.
60+
filters.add(new ConfigurationSettingsFilter("Test*"));
61+
String snapshotName = "{snapshotName}";
62+
63+
client.beginCreateSnapshot(snapshotName, new ConfigurationSnapshot(filters))
64+
.flatMap(result -> result.getFinalResult())
65+
.subscribe(
66+
snapshot -> {
67+
System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
68+
snapshot.getName(), snapshot.getCreatedAt(), snapshot.getStatus());
69+
},
70+
ex -> System.out.printf("Error on creating a snapshot=%s, with error=%s.%n", snapshotName, ex.getMessage()),
71+
() -> System.out.println("Successfully created a snapshot."));
72+
73+
// Get the snapshot status
74+
client.getSnapshot(snapshotName).subscribe(
75+
getSnapshot -> {
76+
System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
77+
getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus());
78+
}
79+
);
80+
81+
TimeUnit.MILLISECONDS.sleep(1000);
82+
83+
// Archive a READY snapshot
84+
client.archiveSnapshot(snapshotName).subscribe(
85+
archivedSnapshot -> {
86+
System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n",
87+
archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());
88+
}
89+
);
90+
91+
TimeUnit.MILLISECONDS.sleep(1000);
92+
93+
// Recover the Archived snapshot
94+
client.recoverSnapshot(snapshotName).subscribe(
95+
recoveredSnapshot -> {
96+
System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n",
97+
recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());
98+
}
99+
);
100+
101+
TimeUnit.MILLISECONDS.sleep(1000);
102+
103+
// List the configuration settings in the snapshot
104+
client.listConfigurationSettingsForSnapshot(snapshotName).subscribe(
105+
settingInSnapshot -> {
106+
System.out.printf("[ConfigurationSetting in snapshot] Key: %s, Value: %s.%n",
107+
settingInSnapshot.getKey(), settingInSnapshot.getValue());
108+
}
109+
);
110+
111+
TimeUnit.MILLISECONDS.sleep(1000);
112+
113+
// The .subscribe() creation and assignment is not a blocking call. For the purpose of this example, we sleep
114+
// the thread so the program does not end before the send operation is complete. Using .block() instead of
115+
// .subscribe() will turn this into a synchronous call.
116+
try {
117+
TimeUnit.MINUTES.sleep(5);
118+
} catch (InterruptedException e) {
119+
e.printStackTrace();
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)