-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Support enabling fiat at runtime (#233)
This PR will always register the `FiatAuthenticationFilter` in the authentication chain _but_ allow for it to be disabled at runtime depending on the dynamic config service. The `FiatAuthenticationFilter` has been modified to no-op when fiat would have previously been disabled. A metric is also emitted (`fiat.enabled` to track whether fiat is enabled on a service/instance basis).
- Loading branch information
Showing
5 changed files
with
97 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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
60 changes: 60 additions & 0 deletions
60
fiat-api/src/main/java/com/netflix/spinnaker/fiat/shared/FiatStatus.java
This file contains 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,60 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed 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 com.netflix.spinnaker.fiat.shared; | ||
|
||
import com.netflix.spectator.api.Registry; | ||
import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Component | ||
public class FiatStatus { | ||
private final Logger log = LoggerFactory.getLogger(FiatStatus.class); | ||
|
||
private final DynamicConfigService dynamicConfigService; | ||
private final AtomicBoolean enabled; | ||
|
||
@Autowired | ||
public FiatStatus(Registry registry, | ||
DynamicConfigService dynamicConfigService, | ||
FiatClientConfigurationProperties fiatClientConfigurationProperties) { | ||
this.dynamicConfigService = dynamicConfigService; | ||
this.enabled = new AtomicBoolean( | ||
dynamicConfigService.isEnabled("fiat", fiatClientConfigurationProperties.isEnabled()) | ||
); | ||
|
||
registry.gauge("fiat.enabled", enabled, value -> enabled.get() ? 1 : 0); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled.get(); | ||
} | ||
|
||
@Scheduled(fixedDelay = 30000L) | ||
void refreshStatus() { | ||
try { | ||
enabled.set(dynamicConfigService.isEnabled("fiat", enabled.get())); | ||
} catch (Exception e) { | ||
log.warn("Unable to refresh fiat status, reason: {}", e.getMessage()); | ||
} | ||
} | ||
} |
This file contains 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