Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Androidimport resourcemanager compute #5

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ The following libraries have known issues with Android:
- `azure-core`'s `ReflectionSerializable` class also requires an external StAX dependency.

## Dependency management

- Dependency version management should use the azure BOM
- Must use OkHttp instead of Netty for http

- Recommend `azure-core` version `1.44.0` or greater. This adds behaviour to ReflectionUtils that improves Android compatibility.
- Recommend `com.fasterxml.jackson:jackson-core`, `com.fasterxml.jackson:jackson-databind`, `com.fasterxml.jackson:jackson-dataformat-xml`, `com.fasterxml.jackson:jackson-datatype-jsr310` version `2.15.0` or greater for transitive dependencies. An example of how to do this is found in the build.gradle.kts file in the android-samples app.
- The use of Jackson also requires an external StAX dependency.


### Overriding dependencies
An example [build.gradle.kts](sdk/android/azure-samples/build.gradle.kts) is included.

Expand Down
6 changes: 5 additions & 1 deletion sdk/android/azure-samples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ dependencies {
// azure_messaging_eventhubs
implementation("com.azure:azure-messaging-eventhubs")


//azure_resourcemanager
implementation("com.azure:azure-core-management")
implementation("com.azure.resourcemanager:azure-resourcemanager-compute:2.31.0")

// android
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
Expand All @@ -87,7 +92,6 @@ dependencies {
//For testing OpenAI and issue 35719, https://github.com/Azure/azure-sdk-for-java/issues/35719
implementation("com.azure:azure-ai-openai:1.0.0-beta.5")


// SL4J provides more verbose logging
/*
implementation("org.slf4j:slf4j-api:2.0.9")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.azure.android;

import static org.junit.Assert.fail;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.azure.android.resourcemanager.compute.ReadmeSamplesResourceManagerCompute;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class ResourceManagerComputeSampleTests {


@Test
public void testAuthenticate() {
try {
ReadmeSamplesResourceManagerCompute.authenticate();
} catch (RuntimeException e) {
fail();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static void main(String endpoint, ClientSecretCredential clientSecretCred
.vaultUrl(endpoint)
.credential(clientSecretCredential)
.buildClient();

String certificateName = "certificateName" + System.currentTimeMillis();
String myCertificate = "myCertificate" + System.currentTimeMillis();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void main(String endpoint, ClientSecretCredential clientSecretCred

String certName = "certName" + System.currentTimeMillis();
String myCertificate = "myCertificate" + System.currentTimeMillis();

// Let's create a self-signed certificate valid for 1 year. If the certificate already exists in the key vault,
// then a new version of the certificate is created.
CertificatePolicy policy = new CertificatePolicy("Self", "CN=SelfSignedJavaPkcs12");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ deleted certificates to be retained for a given retention period (90 days). Duri
.setKeyType(CertificateKeyType.EC);
Map<String, String> tags = new HashMap<>();
tags.put("foo", "bar");

certificateAsyncClient.beginCreateCertificate(certificateName, policy, true, tags)
.subscribe(pollResponse -> {
System.out.println("---------------------------------------------------------------------------------");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class BackupAndRestoreOperationsKeyvaultSecrets {
* @throws InterruptedException when the thread is interrupted in sleep mode.
* @throws IOException when writing backup to file is unsuccessful.
*/

private static final String TAG = "BackupRestoreSecret";

public static void main(String endpoint, ClientSecretCredential clientSecretCredential) throws IOException, InterruptedException, IllegalArgumentException {
Expand All @@ -50,7 +51,6 @@ public static void main(String endpoint, ClientSecretCredential clientSecretCred
.vaultUrl(endpoint)
.credential(clientSecretCredential)
.buildClient();

String storageAccountPassword = "StorageAccountPassword" + System.currentTimeMillis();

// Let's create secrets holding storage account credentials valid for 1 year. If the secret already exists in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public static void main(String endpoint, ClientSecretCredential clientSecretCred
bankSecret.getProperties()
.setExpiresOn(OffsetDateTime.now().plusYears(1));
SecretProperties updatedSecret = secretClient.updateSecretProperties(bankSecret.getProperties());

Log.i(TAG, String.format("Secret's updated expiry time %s \n", updatedSecret.getExpiresOn()));

// Bank forced a password update for security purposes. Let's change the value of the secret in the key vault.
// To achieve this, we need to create a new version of the secret in the key vault. The update operation cannot
// change the value of the secret.

secretClient.setSecret(new KeyVaultSecret(bankAccountPassword, "bhjd4DDgsa")
.setProperties(new SecretProperties()
.setExpiresOn(OffsetDateTime.now().plusYears(1))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.android.keyvault.secrets;

import android.util.Log;

import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.SyncPoller;
import com.azure.identity.ClientSecretCredential;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.android.resourcemanager.compute;

import com.azure.core.credential.TokenCredential;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.compute.ComputeManager;

/**
* Code samples for the README.md
*/
public class ReadmeSamplesResourceManagerCompute {

public static void authenticate() {
// BEGIN: readme-sample-authenticate
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();
ComputeManager manager = ComputeManager
.authenticate(credential, profile);
// END: readme-sample-authenticate
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void main(String accountName, ClientSecretCredential credential) t
*/
BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
Log.i(TAG, String.format("credentials created for %s", storageClient.getAccountName()));

/*
* This example shows several common operations just to get you started.
*/
Expand All @@ -67,6 +68,7 @@ public static void main(String accountName, ClientSecretCredential credential) t
blobContainerClient.create();
Log.i(TAG, "blobContainerClient Created");


/*
* Create a client that references a to-be-created blob in your Azure Storage account's container.
* This returns a BlockBlobClient object that wraps the blob's endpoint, credential and a request pipeline
Expand Down