mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-03 17:39:15 +00:00
Replace LicenseExpiredException with ElasticsearchException.WithRestHeadersException
Original commit: elastic/x-pack-elasticsearch@36aaccc0b9
This commit is contained in:
parent
e5cd37a9af
commit
e0e4f07348
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
/**
|
||||
* Exception to be thrown when a feature action requires a valid license
|
||||
*/
|
||||
public class LicenseExpiredException extends ElasticsearchException {
|
||||
|
||||
private final String feature;
|
||||
|
||||
public LicenseExpiredException(String feature) {
|
||||
super("license expired for feature [" + feature + "]");
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestStatus status() {
|
||||
return RestStatus.UNAUTHORIZED;
|
||||
}
|
||||
|
||||
public String feature() {
|
||||
return feature;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
|
||||
public class LicenseUtils {
|
||||
|
||||
public final static String EXPIRED_FEATURE_HEADER = "es.license.expired.feature";
|
||||
|
||||
/**
|
||||
* Exception to be thrown when a feature action requires a valid license, but license
|
||||
* has expired
|
||||
*
|
||||
* <code>feature</code> accessible through {@link #EXPIRED_FEATURE_HEADER} in the
|
||||
* exception's rest header
|
||||
*/
|
||||
public static ElasticsearchException newExpirationException(String feature) {
|
||||
// TODO: after https://github.com/elastic/elasticsearch/pull/12006 use ElasicsearchException with addHeader(EXPIRED_FEATURE_HEADER, feature)
|
||||
return new ElasticsearchException.WithRestHeadersException("license expired for feature [" + feature + "]",
|
||||
Tuple.tuple(EXPIRED_FEATURE_HEADER, new String[] {feature}));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user