use of com.infiniteautomation.mango.rest.v2.util.MangoStoreClient in project ma-modules-public by infiniteautomation.
the class ModulesRestController method downloadLicense.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Download your license from the store", notes = "Admin Only")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/download-license")
public ResponseEntity<Void> downloadLicense(@ApiParam(value = "Connection retries", required = false, defaultValue = "0", allowMultiple = false) @RequestParam(required = false, defaultValue = "0") int retries, @ApiParam(value = "User Credentials", required = true) @RequestBody(required = true) CredentialsModel model, HttpServletRequest request) {
try {
String storeUrl = Common.envProps.getString("store.url");
// Login to the store
MangoStoreClient client = new MangoStoreClient(storeUrl);
client.login(model.getUsername(), model.getPassword(), retries);
// Send the token request
String guid = Providers.get(ICoreLicense.class).getGuid();
String distributor = Common.envProps.getString("distributor");
String token = client.getLicenseToken(guid, distributor, retries);
// With the token we can make the request to download the file
String license = client.getLicense(token, retries);
saveLicense(license);
return new ResponseEntity<Void>(HttpStatus.OK);
} catch (Exception e) {
throw new GenericRestException(HttpStatus.INTERNAL_SERVER_ERROR, e);
}
}
Aggregations