Skip to content

Commit

Permalink
Add login and hide non-public pages (#9)
Browse files Browse the repository at this point in the history
* remove module, embrace components

* current user request

* fix ui image

* login form

* optimization

* eslint

* create env for admin password

* fix tests
  • Loading branch information
gaetancollaud authored Feb 22, 2024
1 parent 62e8854 commit 3f844de
Show file tree
Hide file tree
Showing 52 changed files with 3,125 additions and 590 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
working-directory: frontend/
run: npm run build

- name: Lint
working-directory: frontend/
run: npm run lint

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
@ConfigMapping(prefix = "cc")
public interface CostControlConfigProperties {

@WithName("admin-password")
@NotNull
String adminPassword();

@WithName("topics.raw-data")
@NotNull
List<String> rawTopics();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.spoud.kcc.aggregator.graphql;

import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import lombok.RequiredArgsConstructor;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.NonNull;
import org.eclipse.microprofile.graphql.Query;

@GraphQLApi
@RequiredArgsConstructor
@Authenticated
@RequestScoped
public class UserResource {

@Inject
SecurityIdentity securityIdentity;


@Query("currentUser")
public @NonNull String currentUser() {
return securityIdentity.getPrincipal().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

@RegisterForReflection
public record ContextDataSaveRequest(
String id, Instant validFrom, Instant validUntil, @NonNull EntityType entityType, @NonNull String regex, @NonNull Map<@NonNull String, @NonNull String> context) {
String id,
Instant validFrom,
Instant validUntil,
@NonNull EntityType entityType,
@NonNull String regex,
@NonNull Map<@NonNull String, @NonNull String> context) {
public ContextData toAvro() {
return new ContextData(Instant.now(), validFrom, validUntil, entityType, regex, context);
}
Expand Down
3 changes: 2 additions & 1 deletion aggregator/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ kafka:
url: http://localhost:8081

cc:
admin-password: admin
topics:
pricing-rules: pricing-rules
context-data: context-data
Expand Down Expand Up @@ -62,7 +63,7 @@ quarkus:
enabled: true
plain-text: true
users:
admin: kpwx06KsQ2Sbi7Tp2N2l
admin: ${cc.admin-password}
roles:
admin: ADMIN
http:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Builder
public class TestConfigProperties implements CostControlConfigProperties {
private String adminPassword;
private String topicAggregatedTableFriendly;
private List<String> rawTopics;
private String applicationId;
Expand All @@ -15,6 +16,11 @@ public class TestConfigProperties implements CostControlConfigProperties {
private List<String> topicRawData;
private String topicAggregated;

@Override
public String adminPassword() {
return adminPassword;
}

@Override
public List<String> rawTopics() {
return rawTopics;
Expand Down
3 changes: 3 additions & 0 deletions deployment/kafka-cost-control/app/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ SCHEMA_REGISTRY_API_SECRET=schema-registry-api-secret

# Coma separated list of topics that contains raw metrics from telegraf
CC_TOPICS_RAW_DATA=metrics-raw-telegraf-dev

# Admin password
CC_ADMIN_PASSWORD=admin
5 changes: 5 additions & 0 deletions deployment/kafka-cost-control/base/aggregator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ spec:
value: /home/jboss/kafka-stream/data/
- name: QUARKUS_PROFILE
value: "ccloud"
- name: CC_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: kafka-cost-control-secret
key: CC_ADMIN_PASSWORD
envFrom:
- secretRef:
name: kafka-cost-control-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ spec:
spec:
containers:
- name: kafka-cost-control-ui
# TODO define final image
image: spoud/kafka-cost-control-exploration-ui:latest
image: spoud/kafka-cost-control-ui:latest
imagePullPolicy: Always
ports:
- containerPort: 80
Expand Down
54 changes: 54 additions & 0 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"root": true,
"ignorePatterns": [
"src/generated/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
]
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended",
"plugin:@angular-eslint/template/accessibility"
],
"rules": {}
}
]
}
15 changes: 14 additions & 1 deletion frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"statsJson": true,
"outputPath": "dist/kafka-cost-control-frontend",
"index": "src/index.html",
"browser": "src/main.ts",
Expand Down Expand Up @@ -99,11 +100,23 @@
],
"scripts": []
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
}
}
}
},
"cli": {
"analytics": false
"analytics": false,
"schematicCollections": [
"@angular-eslint/schematics"
]
}
}
4 changes: 3 additions & 1 deletion frontend/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ type PricingRuleEntity {
"Query root"
type Query {
contextData: [ContextDataEntity!]!
currentUser: String!
metricNames: [MetricNameEntity!]!
pricingRules: [PricingRuleEntity!]!
}

enum EntityType {
PRINCIPAL
TOPIC
UNKNOWN
}

"Scalar for BigDecimal"
Expand All @@ -72,7 +74,7 @@ input ContextDataDeleteRequestInput {
}

input ContextDataSaveRequestInput {
context: [Entry_String_StringInput]!
context: [Entry_String_StringInput!]!
entityType: EntityType!
id: String
regex: String!
Expand Down
14 changes: 14 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ http{
error_log /var/log/nginx.error.log;
root /usr/share/nginx/html;
charset utf-8;
gzip on;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml/javascript;


add_header X-Frame-Options "DENY";

Expand Down
Loading

0 comments on commit 3f844de

Please sign in to comment.