-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agent): enable Agent HTTP communications (#342)
- Loading branch information
1 parent
1071e70
commit 05060e5
Showing
31 changed files
with
1,341 additions
and
591 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
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
Binary file not shown.
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
82 changes: 82 additions & 0 deletions
82
src/main/java/io/cryostat/credentials/CredentialsFinder.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,82 @@ | ||
/* | ||
* Copyright The Cryostat Authors. | ||
* | ||
* 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 io.cryostat.credentials; | ||
|
||
import java.net.URI; | ||
import java.util.Optional; | ||
|
||
import io.cryostat.expressions.MatchExpressionEvaluator; | ||
import io.cryostat.targets.Target; | ||
import io.cryostat.targets.Target.EventKind; | ||
import io.cryostat.targets.Target.TargetDiscovery; | ||
|
||
import io.quarkus.vertx.ConsumeEvent; | ||
import io.smallrye.common.annotation.Blocking; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import org.apache.commons.collections4.BidiMap; | ||
import org.apache.commons.collections4.bidimap.DualHashBidiMap; | ||
import org.jboss.logging.Logger; | ||
import org.projectnessie.cel.tools.ScriptException; | ||
|
||
@ApplicationScoped | ||
public class CredentialsFinder { | ||
|
||
@Inject MatchExpressionEvaluator expressionEvaluator; | ||
@Inject Logger logger; | ||
|
||
private final BidiMap<Target, Credential> cache = new DualHashBidiMap<>(); | ||
|
||
@ConsumeEvent(Credential.CREDENTIALS_DELETED) | ||
void onCredentialsDeleted(Credential credential) { | ||
cache.removeValue(credential); | ||
} | ||
|
||
@ConsumeEvent(Target.TARGET_JVM_DISCOVERY) | ||
void onMessage(TargetDiscovery event) { | ||
if (EventKind.LOST.equals(event.kind())) { | ||
cache.remove(event.serviceRef()); | ||
} | ||
} | ||
|
||
@Blocking | ||
public Optional<Credential> getCredentialsForTarget(Target target) { | ||
return Optional.ofNullable( | ||
cache.computeIfAbsent( | ||
target, | ||
t -> | ||
Credential.<Credential>listAll().stream() | ||
.filter( | ||
c -> { | ||
try { | ||
return expressionEvaluator.applies( | ||
c.matchExpression, t); | ||
} catch (ScriptException e) { | ||
logger.error(e); | ||
return false; | ||
} | ||
}) | ||
.findFirst() | ||
.orElse(null))); | ||
} | ||
|
||
@Blocking | ||
public Optional<Credential> getCredentialsForConnectUrl(URI connectUrl) { | ||
return Target.find("connectUrl", connectUrl) | ||
.<Target>singleResultOptional() | ||
.flatMap(this::getCredentialsForTarget); | ||
} | ||
} |
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
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
Oops, something went wrong.