-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Direct download certificates additions and improvements #6104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7d6fc63
Add direct download certificates listing
nvazquez f29fc4d
Restore class to original project
nvazquez 0daae73
Small refactor
nvazquez 2c1b781
Register API
nvazquez 2904a0e
Apply suggestions from code review
nvazquez 978fa68
Refactor after review
nvazquez e969c2d
Fix checkstyle
nvazquez 596ef37
Add hosts mapping to API response
nvazquez 7401183
Improvements on revoke certificate
nvazquez 2b3851e
Refactor revoke certificate API
nvazquez cee4179
Fix condition
nvazquez 8ef8ec8
Filter only certificates not revoked for revokeCertificate API
nvazquez 1cddc39
Improve upload certificate and add provision certificate API
nvazquez 5f1a74b
Improve certificate response output
nvazquez 9c86465
Address review comments
nvazquez 803fbb1
Merge branch 'main' into directdownloadimprovements
nvazquez 20e50c4
Refactor revoke cert test
nvazquez 1e840d2
Fix marvin test
nvazquez 76c1ca3
Address review comments
nvazquez f6c5970
Fix issues
nvazquez 2713b10
Improvements
nvazquez fa872be
Refactor upload template API response
nvazquez eb9458d
Fix response
nvazquez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...oudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.admin.direct.download; | ||
|
|
||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.BaseListCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.DirectDownloadCertificateHostStatusResponse; | ||
| import org.apache.cloudstack.api.response.ListResponse; | ||
| import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse; | ||
| import org.apache.cloudstack.api.response.ZoneResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.direct.download.DirectDownloadCertificate; | ||
| import org.apache.cloudstack.direct.download.DirectDownloadCertificateHostMap; | ||
| import org.apache.cloudstack.direct.download.DirectDownloadManager; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @APICommand(name = ListTemplateDirectDownloadCertificatesCmd.APINAME, | ||
| description = "List the uploaded certificates for direct download templates", | ||
| responseObject = DirectDownloadCertificateResponse.class, | ||
| since = "4.17.0", | ||
| authorized = {RoleType.Admin}) | ||
| public class ListTemplateDirectDownloadCertificatesCmd extends BaseListCmd { | ||
|
|
||
| @Inject | ||
| DirectDownloadManager directDownloadManager; | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DirectDownloadCertificateResponse.class, | ||
| description = "list direct download certificate by ID") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, | ||
| description = "the zone where certificates are uploaded") | ||
| private Long zoneId; | ||
|
|
||
| @Parameter(name = ApiConstants.LIST_HOSTS, type = CommandType.BOOLEAN, | ||
| description = "if set to true: include the hosts where the certificate is uploaded to") | ||
| private Boolean listHosts; | ||
|
|
||
| private static final Logger LOG = Logger.getLogger(ListTemplateDirectDownloadCertificatesCmd.class); | ||
| public static final String APINAME = "listTemplateDirectDownloadCertificates"; | ||
|
|
||
| public boolean isListHosts() { | ||
| return listHosts != null && listHosts; | ||
| } | ||
|
|
||
| private void createResponse(final List<DirectDownloadCertificate> certificates) { | ||
| final ListResponse<DirectDownloadCertificateResponse> response = new ListResponse<>(); | ||
| final List<DirectDownloadCertificateResponse> responses = new ArrayList<>(); | ||
| for (final DirectDownloadCertificate certificate : certificates) { | ||
| if (certificate == null) { | ||
| continue; | ||
| } | ||
| DirectDownloadCertificateResponse certificateResponse = _responseGenerator.createDirectDownloadCertificateResponse(certificate); | ||
| if (isListHosts()) { | ||
| List<DirectDownloadCertificateHostMap> hostMappings = directDownloadManager.getCertificateHostsMapping(certificate.getId()); | ||
| List<DirectDownloadCertificateHostStatusResponse> hostMapResponses = _responseGenerator.createDirectDownloadCertificateHostMapResponse(hostMappings); | ||
| certificateResponse.setHostsMap(hostMapResponses); | ||
| } | ||
| responses.add(certificateResponse); | ||
| } | ||
| response.setResponses(responses); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, | ||
| ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| List<DirectDownloadCertificate> certificates = directDownloadManager.listDirectDownloadCertificates(id, zoneId); | ||
| createResponse(certificates); | ||
| } | ||
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getId(); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
...tack/api/command/admin/direct/download/ProvisionTemplateDirectDownloadCertificateCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // | ||
| package org.apache.cloudstack.api.command.admin.direct.download; | ||
|
|
||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.utils.Pair; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.DirectDownloadCertificateHostStatusResponse; | ||
| import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse; | ||
| import org.apache.cloudstack.api.response.HostResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.direct.download.DirectDownloadManager; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| @APICommand(name = ProvisionTemplateDirectDownloadCertificateCmd.APINAME, | ||
| description = "Provisions a host with a direct download certificate", | ||
| responseObject = DirectDownloadCertificateHostStatusResponse.class, | ||
| since = "4.17.0", | ||
| authorized = {RoleType.Admin}) | ||
| public class ProvisionTemplateDirectDownloadCertificateCmd extends BaseCmd { | ||
|
|
||
| public static final String APINAME = "provisionTemplateDirectDownloadCertificate"; | ||
|
|
||
| @Inject | ||
| DirectDownloadManager directDownloadManager; | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DirectDownloadCertificateResponse.class, | ||
|
nvazquez marked this conversation as resolved.
|
||
| description = "the id of the direct download certificate to provision", required = true) | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.HOST_ID, type = CommandType.UUID, entityType = HostResponse.class, | ||
|
nvazquez marked this conversation as resolved.
|
||
| description = "the host to provision the certificate", required = true) | ||
| private Long hostId; | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| Pair<Boolean, String> result = directDownloadManager.provisionCertificate(id, hostId); | ||
| DirectDownloadCertificateHostStatusResponse response = _responseGenerator.createDirectDownloadCertificateProvisionResponse(id, hostId, result); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getId(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.