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

Implement a Service Bus Shared Access Key Credential #21227

Merged
merged 27 commits into from
Jun 14, 2021
Merged

Implement a Service Bus Shared Access Key Credential #21227

merged 27 commits into from
Jun 14, 2021

Conversation

v-hongli1
Copy link
Member

@v-hongli1 v-hongli1 commented May 7, 2021

Fix issue #16465

  1. Add and change class and test case for implement a Service Bus Shared Access Key Credential
  2. Add and change files:
    1). sdk/identity/azure-identity/src/main/java/com/azure/identity/ServiceBusSharedKeyCredential.java
    2). sdk/identity/azure-identity/src/main/java/com/azure/identity/ServiceBusSharedKeyCredentialBuilder.java
    3). sdk/identity/azure-identity/src/test/java/com/azure/identity/ServiceBusSharedKeyCredentialTest.java
    4). sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/util/ValidationUtil.java
  3. Add a new validation method validateForSharedAccessKey in the ValidationUtil class to cope with the two parameter setting methods when the Shared Access Key Credential is created.
    a. When sharedAccessSignature != null , the specified sharedAccessSignature can be directly used to create Shared Access Key Credential, so sharedAccessPolicy and shardAccessKey do not require any verification.
    b. When sharedAccessSignature == null, sharedAccessPolicy and shardAccessKey are required for verification.

@jongio, @conniey for notification.

@ghost ghost added Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization. labels May 7, 2021
@ghost
Copy link

ghost commented May 7, 2021

Thank you for your contribution hongli750210! We will review the pull request and get back to you soon.

@v-hongli1 v-hongli1 changed the title Implement an Event Hubs Shared Access Key Credential Implement a Service Bus Shared Access Key Credential May 7, 2021
v-hongli1 added 2 commits May 7, 2021 10:22
# Conflicts:
#	sdk/identity/azure-identity/src/main/java/com/azure/identity/ServiceBusSharedKeyCredential.java
@v-hongli1 v-hongli1 marked this pull request as ready for review May 10, 2021 02:57
@ramya-rao-a
Copy link
Contributor

@hongli19750210 Please see #16465 (comment) for the updated design to be followed for this task

We should re-use the classes AzureSasCredential and AzureNamedKeyCredential from azure-core.

@conniey conniey self-assigned this May 12, 2021
Copy link
Member

@conniey conniey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good aside from the CI build failures.

Copy link
Contributor

@hemanttanwar hemanttanwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add test in integration test for receiving or sending message using sas key ?

@check-enforcer
Copy link

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run java - [service] - ci

@jongio
Copy link
Member

jongio commented Jun 14, 2021

@conniey / @hemanttanwar - Do you need anything else on this?

@@ -235,6 +237,55 @@ public ServiceBusClientBuilder credential(String fullyQualifiedNamespace, TokenC
return this;
}

/**
* Sets the credential for the Service Bus resource.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more details to javadoc on how to obtain named key credential and sas credential for the next method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to your comment, fixed in the new version.

Comment on lines +257 to +260
if (CoreUtils.isNullOrEmpty(fullyQualifiedNamespace)) {
throw logger.logExceptionAsError(
new IllegalArgumentException("'fullyQualifiedNamespace' cannot be an empty string."));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All input validation should happen before performing any operations on the input. Here ServiceBusSharedKeyCredential should not be created until fullyQualifiedNamespace param is validated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to your comment, fixed in the new version.

"'fullyQualifiedNamespace' cannot be null.");
Objects.requireNonNull(credential, "'credential' cannot be null.");

this.credentials = new ServiceBusSharedKeyCredential(credential.getSignature());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overwrites the value set in the previous overload. So, the order of calls to credential() decides which credential is being used. Instead, we should do the validate in build method and throw exception if both are set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to your comment, fixed in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants