Skip to content

Commit

Permalink
chore(cleanup): Doing refactoring of Kayenta to cleanup codebase (#926)
Browse files Browse the repository at this point in the history
* chore(refactor): Refactor account credentials to be an abstract class.  Refactor Prometheus code to not duplicate account code

* fix(security): do not return the password in json

* fix(security): do not return the bearer token  in json
  • Loading branch information
jasonmcintosh authored Feb 1, 2023
1 parent 7925c89 commit 4834853
Show file tree
Hide file tree
Showing 24 changed files with 179 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
import java.util.Collections;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class AtlasNamedAccountCredentials implements AccountCredentials<AtlasCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Setter
@Getter
public class AtlasNamedAccountCredentials extends AccountCredentials<AtlasCredentials> {

@Override
public String getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@
import com.amazonaws.services.s3.AmazonS3;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class AwsNamedAccountCredentials implements AccountCredentials<AwsCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Setter
@Getter
public class AwsNamedAccountCredentials extends AccountCredentials<AwsCredentials> {

@NotNull private AwsCredentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
package com.netflix.kayenta.azure.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.azure.storage.blob.*;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class AzureNamedAccountCredentials implements AccountCredentials<AzureCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Getter
@Setter
@NoArgsConstructor
public class AzureNamedAccountCredentials extends AccountCredentials<AzureCredentials> {

@NotNull private AzureCredentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,44 @@
package com.netflix.kayenta.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.*;
import lombok.experimental.SuperBuilder;

public interface AccountCredentials<T> {
String getName();
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = "name")
public abstract class AccountCredentials<T> {
private String name;
@Builder.Default private List<Type> supportedTypes = new ArrayList<>();

String getType();

List<Type> getSupportedTypes();
public abstract String getType();

/*
* If this account provides a metrics service, return a list of valid "location" values for the metric
* scope. This is used as a UI hint. If the service cannot enumerate the locations, it should return
* an empty list, and the UI may provide an input field rather than a selection.
*/
default List<String> getLocations() {
return Collections.emptyList();
}

@Builder.Default private List<String> locations = Collections.emptyList();

/*
* If this account provides a recommended list of locations, this can also be used by the UI to limit
* the initially presented list to something shorter than "everything." Note that this list may be
* present even if locations() returns an empty list; this would imply that there are commonly
* used locations, but the full list is unknown by the metrics service.
*/
default List<String> getRecommendedLocations() {
return Collections.emptyList();
}
@Builder.Default private List<String> recommendedLocations = Collections.emptyList();

@JsonIgnore
T getCredentials();
public abstract T getCredentials();

enum Type {
public enum Type {
METRICS_STORE,
OBJECT_STORE,
CONFIGURATION_STORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ package com.netflix.kayenta.index

import com.netflix.kayenta.security.AccountCredentials

class TestNamedAccountCredentials implements AccountCredentials<TestCredentials> {
class TestNamedAccountCredentials extends AccountCredentials<TestCredentials> {

String name = "some-account"
String type = "some-platform"
String getName() {
return "some-account";
}

String getType() {
return "some-platform";
}

@Override
List<AccountCredentials.Type> getSupportedTypes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
import com.netflix.kayenta.datadog.service.DatadogRemoteService;
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class DatadogNamedAccountCredentials implements AccountCredentials<DatadogCredentials> {
@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Getter
@Setter
@NoArgsConstructor
public class DatadogNamedAccountCredentials extends AccountCredentials<DatadogCredentials> {

@NotNull private DatadogCredentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
import com.google.api.services.monitoring.v3.Monitoring;
import com.google.api.services.storage.Storage;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;
import lombok.*;
import lombok.experimental.SuperBuilder;

@Builder
@Data
public class GoogleNamedAccountCredentials implements AccountCredentials<GoogleClientFactory> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
public class GoogleNamedAccountCredentials extends AccountCredentials<GoogleClientFactory> {

@NotNull private GoogleClientFactory credentials;

Expand All @@ -48,7 +44,7 @@ public String getType() {
}

public String getMetricsStoreType() {
return supportedTypes.contains(Type.METRICS_STORE) ? "stackdriver" : null;
return getSupportedTypes().contains(Type.METRICS_STORE) ? "stackdriver" : null;
}

@JsonIgnore private Monitoring monitoring;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@
import com.netflix.kayenta.graphite.service.GraphiteRemoteService;
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class GraphiteNamedAccountCredentials implements AccountCredentials<GraphiteCredentials> {
@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;

import lombok.*;
import lombok.experimental.SuperBuilder;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
public class GraphiteNamedAccountCredentials extends AccountCredentials<GraphiteCredentials> {
@NotNull private GraphiteCredentials credentials;

@NotNull private RemoteService endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@
import com.netflix.kayenta.influxdb.service.InfluxDbRemoteService;
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class InfluxDbNamedAccountCredentials implements AccountCredentials<InfluxdbCredentials> {
@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;

import lombok.*;
import lombok.experimental.SuperBuilder;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
public class InfluxDbNamedAccountCredentials extends AccountCredentials<InfluxdbCredentials> {
@NotNull private InfluxdbCredentials credentials;

@NotNull private RemoteService endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
import com.netflix.kayenta.newrelic.service.NewRelicRemoteService;
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class NewRelicNamedAccountCredentials implements AccountCredentials<NewRelicCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.*;
import lombok.experimental.SuperBuilder;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
public class NewRelicNamedAccountCredentials extends AccountCredentials<NewRelicCredentials> {

@NotNull private NewRelicCredentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
import com.netflix.kayenta.configbin.service.ConfigBinRemoteService;
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.security.AccountCredentials;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.*;

@Builder
@Data
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Getter
@Setter
@NoArgsConstructor
public class ConfigBinNamedAccountCredentials
implements AccountCredentials<ConfigBinAccountCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
extends AccountCredentials<ConfigBinAccountCredentials> {

@NotNull private ConfigBinAccountCredentials credentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@

import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.storage.ObjectType;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

@Builder
@Data
public class MemoryNamedAccountCredentials implements AccountCredentials<MemoryAccountCredentials> {

@NotNull private String name;

@NotNull @Singular private List<Type> supportedTypes;
import lombok.*;
import lombok.experimental.SuperBuilder;

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
public class MemoryNamedAccountCredentials extends AccountCredentials<MemoryAccountCredentials> {

@NotNull private MemoryAccountCredentials credentials;

Expand Down
Loading

0 comments on commit 4834853

Please sign in to comment.