Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface Secret extends
HasName,
Updatable<Secret.Update> {
/**
* @return the secret value
* @return the secret value when the secret is enabled
*/
String value();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.microsoft.azure.ListOperationCallback;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.keyvault.SecretIdentifier;
import com.microsoft.azure.keyvault.models.Attributes;
import com.microsoft.azure.keyvault.models.SecretAttributes;
import com.microsoft.azure.keyvault.models.SecretBundle;
Expand Down Expand Up @@ -97,7 +96,16 @@ public Observable<Secret> typeConvertAsync(final SecretItem secretItem) {

@Override
protected ServiceFuture<SecretBundle> callAsync() {
return vault.client().getSecretAsync(secretItem.identifier().identifier(), null);
if (secretItem.attributes().enabled()) {
return vault.client().getSecretAsync(secretItem.identifier().identifier(), null);
} else {
SecretBundle secretBundle = new SecretBundle()
.withId(secretItem.id())
.withAttributes(secretItem.attributes())
.withContentType(secretItem.contentType())
.withTags(secretItem.tags());
return ServiceFuture.fromBody(Observable.just(secretBundle), null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What would be the difference if we create SecretBundle this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The property secretBundle.value() will be NULL. For the enabled secrets, value will be returned by server side.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That probably is acceptable. From our API user can know it is disabled, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I update the comments at Secret interface. Meanwhile, the status of enabled/disabled can be found via secret.attributes().enabled().

}
}

@Override
Expand All @@ -111,31 +119,40 @@ protected Secret wrapModel(SecretBundle secretBundle) {

@Override
public Observable<Secret> listVersionsAsync() {
return new KeyVaultFutures.ListCallbackObserver<SecretItem, SecretIdentifier>() {
return new KeyVaultFutures.ListCallbackObserver<SecretItem, SecretItem>() {

@Override
protected void list(ListOperationCallback<SecretItem> callback) {
vault.client().listSecretVersionsAsync(vault.vaultUri(), name(), callback);
}

@Override
protected Observable<SecretIdentifier> typeConvertAsync(SecretItem o) {
return Observable.just(o.identifier());
protected Observable<SecretItem> typeConvertAsync(SecretItem o) {
return Observable.just(o);
}
}.toObservable()
.flatMap(new Func1<SecretIdentifier, Observable<Secret>>() {
.flatMap(new Func1<SecretItem, Observable<Secret>>() {
@Override
public Observable<Secret> call(final SecretIdentifier secretIdentifier) {
public Observable<Secret> call(final SecretItem secretItem) {
return new KeyVaultFutures.ServiceFutureConverter<SecretBundle, Secret>() {

@Override
protected ServiceFuture<SecretBundle> callAsync() {
return vault.client().getSecretAsync(secretIdentifier.identifier(), null);
if (secretItem.attributes().enabled()) {
return vault.client().getSecretAsync(secretItem.identifier().identifier(), null);
} else {
SecretBundle secretBundle = new SecretBundle()
.withId(secretItem.id())
.withAttributes(secretItem.attributes())
.withContentType(secretItem.contentType())
.withTags(secretItem.tags());
return ServiceFuture.fromBody(Observable.just(secretBundle), null);
}
}

@Override
protected Secret wrapModel(SecretBundle secretBundle) {
return new SecretImpl(secretIdentifier.name(), secretBundle, vault);
return new SecretImpl(secretItem.identifier().name(), secretBundle, vault);
}
}.toObservable();
}
Expand Down