Search in sources :

Example 1 with MangoStoreClient

use of com.infiniteautomation.mango.rest.latest.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, 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);
    }
}
Also used : MangoStoreClient(com.infiniteautomation.mango.rest.latest.util.MangoStoreClient) ResponseEntity(org.springframework.http.ResponseEntity) JsonString(com.serotonin.json.type.JsonString) ICoreLicense(com.serotonin.m2m2.ICoreLicense) JsonException(com.serotonin.json.JsonException) FeatureDisabledException(com.infiniteautomation.mango.util.exception.FeatureDisabledException) HttpException(org.apache.http.HttpException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) GenericRestException(com.infiniteautomation.mango.rest.latest.exception.GenericRestException) FileNotFoundException(java.io.FileNotFoundException) ModuleRestException(com.infiniteautomation.mango.rest.latest.exception.ModuleRestException) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) ServerErrorException(com.infiniteautomation.mango.rest.latest.exception.ServerErrorException) ValidationFailedRestException(com.infiniteautomation.mango.rest.latest.exception.ValidationFailedRestException) GenericRestException(com.infiniteautomation.mango.rest.latest.exception.GenericRestException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)1 GenericRestException (com.infiniteautomation.mango.rest.latest.exception.GenericRestException)1 ModuleRestException (com.infiniteautomation.mango.rest.latest.exception.ModuleRestException)1 ServerErrorException (com.infiniteautomation.mango.rest.latest.exception.ServerErrorException)1 ValidationFailedRestException (com.infiniteautomation.mango.rest.latest.exception.ValidationFailedRestException)1 MangoStoreClient (com.infiniteautomation.mango.rest.latest.util.MangoStoreClient)1 FeatureDisabledException (com.infiniteautomation.mango.util.exception.FeatureDisabledException)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 JsonException (com.serotonin.json.JsonException)1 JsonString (com.serotonin.json.type.JsonString)1 ICoreLicense (com.serotonin.m2m2.ICoreLicense)1 ApiOperation (io.swagger.annotations.ApiOperation)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 HttpException (org.apache.http.HttpException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1