From 7e57c7895815e6c9a583edc606de4faefbd29e0f Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Thu, 11 Mar 2021 19:50:50 +0000 Subject: [PATCH 01/44] version 1 added - 20 mins , run the app, created docker --- spring/.gitignore | 2 + spring/Dockerfile | 4 + spring/pom.xml | 77 ++++++++++++++++--- .../src/main/resources/application.properties | 24 +++--- spring/src/main/tomcatconf/server.xml | 38 +++++++++ spring/src/main/tomcatconf/tomcat-users.xml | 9 +++ 6 files changed, 134 insertions(+), 20 deletions(-) create mode 100644 spring/Dockerfile create mode 100644 spring/src/main/tomcatconf/server.xml create mode 100644 spring/src/main/tomcatconf/tomcat-users.xml diff --git a/spring/.gitignore b/spring/.gitignore index 55276a330..f9c08aa47 100644 --- a/spring/.gitignore +++ b/spring/.gitignore @@ -1,3 +1,5 @@ /target/ db.* application.properties +/.idea/ +/spring.iml diff --git a/spring/Dockerfile b/spring/Dockerfile new file mode 100644 index 000000000..2519c1b87 --- /dev/null +++ b/spring/Dockerfile @@ -0,0 +1,4 @@ +# we are extending everything from tomcat:8.0 image ... +FROM openjdk:8-jdk-alpine +COPY target/notejam-0.0.1-SNAPSHOT.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/spring/pom.xml b/spring/pom.xml index 8c64669bf..fdb6de015 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -6,17 +6,15 @@ spring-boot-starter-parent 1.3.0.RELEASE - net.notejam - spring + notejam + jar 0.0.1-SNAPSHOT - Notejam: Spring - Implements Notejam with Spring - + notejam + Implements notejam with Spring 1.8 - org.springframework.boot @@ -73,14 +71,12 @@ test - org.springframework.boot spring-boot-maven-plugin - org.codehaus.mojo aspectj-maven-plugin @@ -121,7 +117,70 @@ + + io.fabric8 + docker-maven-plugin + 0.34.1 + + + + notejam:0.0.1.0 + dockerfile + + + ${project.basedir} + + rootWar + + + + + development + ${project.version} + + + 8080:8080 + + + seccomp=unconfined + + + DEMO + ISO8601 + blue + + + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.1 + + / + ${project.build.directory}/${project.build.finalName} + + + + tomcat-run + + exec-war-only + + package + + / + + src/main/tomcatconf/server.xml + + + + + + - \ No newline at end of file diff --git a/spring/src/main/resources/application.properties b/spring/src/main/resources/application.properties index 458a12e23..b28ecffca 100644 --- a/spring/src/main/resources/application.properties +++ b/spring/src/main/resources/application.properties @@ -1,18 +1,20 @@ -email.sender: Markus Malkusch +#email.sender: Markus Malkusch + +#; If you want to have mail transport, configure at least the property spring.mail.host, +#; otherwise mail transport is not available. +#; For further mail configuration see http://docs.spring.io/spring-boot/docs/current/api/index.html?org/springframework/boot/autoconfigure/mail/MailProperties.html +#; +spring.mail.host= smtp.example.net +email.sender=suresh.thomas@yahoo.com -; If you want to have mail transport, configure at least the property spring.mail.host, -; otherwise mail transport is not available. -; For further mail configuration see http://docs.spring.io/spring-boot/docs/current/api/index.html?org/springframework/boot/autoconfigure/mail/MailProperties.html -; -;spring.mail.host: smtp.example.net spring.datasource.url=jdbc:hsqldb:file:db spring.jpa.hibernate.ddl-auto=update -async.queueCapacity: 1000 +async.queueCapacity= 1000 -; ISO 8601 period until a recovery token expires. -recovery.lifetime: P1D +#; ISO 8601 period until a recovery token expires. +recovery.lifetime= P1D -; The length of the generated password. -recovery.length: 32 +#; The length of the generated password. +recovery.length= 32 diff --git a/spring/src/main/tomcatconf/server.xml b/spring/src/main/tomcatconf/server.xml new file mode 100644 index 000000000..95cf3c0b2 --- /dev/null +++ b/spring/src/main/tomcatconf/server.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring/src/main/tomcatconf/tomcat-users.xml b/spring/src/main/tomcatconf/tomcat-users.xml new file mode 100644 index 000000000..221d47ae1 --- /dev/null +++ b/spring/src/main/tomcatconf/tomcat-users.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From b8ea1adee9dded49c23ddc5b5887ea549740dd09 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 12 Mar 2021 01:33:18 +0000 Subject: [PATCH 02/44] Iac terraform scripts added --- .gitignore | 5 + terraform/modules/azure/aks/k8.tf | 71 ++++++ terraform/modules/azure/aks/main.tf | 4 + terraform/modules/azure/aks/output.tf | 27 ++ terraform/modules/azure/aks/variable.tf | 40 +++ terraform/modules/azure/aks/versions.tf | 8 + terraform/modules/azure/database/main.tf | 7 + terraform/modules/azure/database/variable.tf | 12 + terraform/modules/azure/database/versions.tf | 8 + terraform/modules/azure/db_server/main.tf | 25 ++ terraform/modules/azure/db_server/variable.tf | 53 ++++ terraform/modules/azure/db_server/versions.tf | 8 + .../fixtures.us-east-2.tfvars | 123 --------- .../terraform-aws-ecs-codepipeline/main.tf | 110 -------- .../terraform-aws-ecs-codepipeline/outputs.tf | 150 ----------- .../variables.tf | 237 ------------------ .../versions.tf | 11 - .../fixtures.us-east-2.tfvars | 96 ------- .../main.tf | 99 -------- .../outputs.tf | 105 -------- .../variables.tf | 204 --------------- .../versions.tf | 8 - terraform/notejam-tf/provider.tf | 11 + terraform/notejam-tf/resource-app-cluster.tf | 11 + terraform/notejam-tf/resource-database.tf | 7 + terraform/notejam-tf/resource-db-server.tf | 12 + terraform/notejam-tf/resource-rg.tf | 16 ++ terraform/notejam-tf/resource-vnet.tf | 0 terraform/notejam-tf/terraform.auto.tfvars | 42 ++++ terraform/notejam-tf/terraform.tfstate | 8 + terraform/notejam-tf/variables.tf | 86 +++++++ 31 files changed, 461 insertions(+), 1143 deletions(-) create mode 100644 terraform/modules/azure/aks/k8.tf create mode 100644 terraform/modules/azure/aks/main.tf create mode 100644 terraform/modules/azure/aks/output.tf create mode 100644 terraform/modules/azure/aks/variable.tf create mode 100644 terraform/modules/azure/aks/versions.tf create mode 100644 terraform/modules/azure/database/main.tf create mode 100644 terraform/modules/azure/database/variable.tf create mode 100644 terraform/modules/azure/database/versions.tf create mode 100644 terraform/modules/azure/db_server/main.tf create mode 100644 terraform/modules/azure/db_server/variable.tf create mode 100644 terraform/modules/azure/db_server/versions.tf delete mode 100644 terraform/modules/terraform-aws-ecs-codepipeline/fixtures.us-east-2.tfvars delete mode 100644 terraform/modules/terraform-aws-ecs-codepipeline/main.tf delete mode 100644 terraform/modules/terraform-aws-ecs-codepipeline/outputs.tf delete mode 100644 terraform/modules/terraform-aws-ecs-codepipeline/variables.tf delete mode 100644 terraform/modules/terraform-aws-ecs-codepipeline/versions.tf delete mode 100644 terraform/modules/terraform-aws-elastic-beanstalk-environment/fixtures.us-east-2.tfvars delete mode 100644 terraform/modules/terraform-aws-elastic-beanstalk-environment/main.tf delete mode 100644 terraform/modules/terraform-aws-elastic-beanstalk-environment/outputs.tf delete mode 100644 terraform/modules/terraform-aws-elastic-beanstalk-environment/variables.tf delete mode 100644 terraform/modules/terraform-aws-elastic-beanstalk-environment/versions.tf create mode 100644 terraform/notejam-tf/provider.tf create mode 100644 terraform/notejam-tf/resource-app-cluster.tf create mode 100644 terraform/notejam-tf/resource-database.tf create mode 100644 terraform/notejam-tf/resource-db-server.tf create mode 100644 terraform/notejam-tf/resource-rg.tf create mode 100644 terraform/notejam-tf/resource-vnet.tf create mode 100644 terraform/notejam-tf/terraform.auto.tfvars create mode 100644 terraform/notejam-tf/terraform.tfstate create mode 100644 terraform/notejam-tf/variables.tf diff --git a/.gitignore b/.gitignore index aba103733..5db494851 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,8 @@ bower_components .bak +terraform/notejam-tf/Readme.txt +.terraform/** +*.backup +*.exte +.terraform \ No newline at end of file diff --git a/terraform/modules/azure/aks/k8.tf b/terraform/modules/azure/aks/k8.tf new file mode 100644 index 000000000..437f6e9af --- /dev/null +++ b/terraform/modules/azure/aks/k8.tf @@ -0,0 +1,71 @@ +resource "azurerm_resource_group" "k8s" { + name = var.resource_group_name + location = var.location +} + +resource "random_id" "log_analytics_workspace_name_suffix" { + byte_length = 8 +} + +resource "azurerm_log_analytics_workspace" "test" { + # The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant. + name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}" + location = var.log_analytics_workspace_location + resource_group_name = azurerm_resource_group.k8s.name + sku = var.log_analytics_workspace_sku +} + +resource "azurerm_log_analytics_solution" "test" { + solution_name = "ContainerInsights" + location = azurerm_log_analytics_workspace.test.location + resource_group_name = azurerm_resource_group.k8s.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id + workspace_name = azurerm_log_analytics_workspace.test.name + + plan { + publisher = "Microsoft" + product = "OMSGallery/ContainerInsights" + } +} + +resource "azurerm_kubernetes_cluster" "k8s" { + name = var.cluster_name + location = azurerm_resource_group.k8s.location + resource_group_name = azurerm_resource_group.k8s.name + dns_prefix = var.dns_prefix + + linux_profile { + admin_username = "ubuntu" + + ssh_key { + key_data = file(var.ssh_public_key) + } + } + + default_node_pool { + name = "agentpool" + node_count = var.agent_count + vm_size = "Standard_D2_v2" + } + + service_principal { + client_id = var.client_id + client_secret = var.client_secret + } + + addon_profile { + oms_agent { + enabled = true + log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id + } + } + + network_profile { + load_balancer_sku = "Standard" + network_plugin = "kubenet" + } + + tags = { + Environment = "Development" + } +} \ No newline at end of file diff --git a/terraform/modules/azure/aks/main.tf b/terraform/modules/azure/aks/main.tf new file mode 100644 index 000000000..556695485 --- /dev/null +++ b/terraform/modules/azure/aks/main.tf @@ -0,0 +1,4 @@ + +terraform { + backend "azurerm" {} +} \ No newline at end of file diff --git a/terraform/modules/azure/aks/output.tf b/terraform/modules/azure/aks/output.tf new file mode 100644 index 000000000..0be106473 --- /dev/null +++ b/terraform/modules/azure/aks/output.tf @@ -0,0 +1,27 @@ +output "client_key" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key +} + +output "client_certificate" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate +} + +output "cluster_ca_certificate" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate +} + +output "cluster_username" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.username +} + +output "cluster_password" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.password +} + +output "kube_config" { + value = azurerm_kubernetes_cluster.k8s.kube_config_raw +} + +output "host" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.host +} \ No newline at end of file diff --git a/terraform/modules/azure/aks/variable.tf b/terraform/modules/azure/aks/variable.tf new file mode 100644 index 000000000..ddc5e6557 --- /dev/null +++ b/terraform/modules/azure/aks/variable.tf @@ -0,0 +1,40 @@ +variable "client_id" {} +variable "client_secret" {} + +variable "agent_count" { + default = 3 +} + +variable "ssh_public_key" { + default = "~/.ssh/id_rsa.pub" +} + +variable "dns_prefix" { + default = "k8stest" +} + +variable cluster_name { + default = "k8stest" +} + +variable resource_group_name { + default = "azure-k8stest" +} + +variable location { + default = "Central US" +} + +variable log_analytics_workspace_name { + default = "testLogAnalyticsWorkspaceName" +} + +# refer https://azure.microsoft.com/global-infrastructure/services/?products=monitor for log analytics available regions +variable log_analytics_workspace_location { + default = "eastus" +} + +# refer https://azure.microsoft.com/pricing/details/monitor/ for log analytics pricing +variable log_analytics_workspace_sku { + default = "PerGB2018" +} \ No newline at end of file diff --git a/terraform/modules/azure/aks/versions.tf b/terraform/modules/azure/aks/versions.tf new file mode 100644 index 000000000..951d6c58a --- /dev/null +++ b/terraform/modules/azure/aks/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } +} \ No newline at end of file diff --git a/terraform/modules/azure/database/main.tf b/terraform/modules/azure/database/main.tf new file mode 100644 index 000000000..a968ef2c1 --- /dev/null +++ b/terraform/modules/azure/database/main.tf @@ -0,0 +1,7 @@ +resource "azurerm_mysql_database" "db" { + name = var.database_name + resource_group_name = var.db_resource_group_name + server_name = var.db_server_name + charset = "utf8" + collation = "utf8_unicode_ci" +} \ No newline at end of file diff --git a/terraform/modules/azure/database/variable.tf b/terraform/modules/azure/database/variable.tf new file mode 100644 index 000000000..fe20ef476 --- /dev/null +++ b/terraform/modules/azure/database/variable.tf @@ -0,0 +1,12 @@ +//Created by Suresh + +variable database_name{ + type =string +} + +variable db_resource_group_name { + type =string +} + variable db_server_name { + type =string + } \ No newline at end of file diff --git a/terraform/modules/azure/database/versions.tf b/terraform/modules/azure/database/versions.tf new file mode 100644 index 000000000..951d6c58a --- /dev/null +++ b/terraform/modules/azure/database/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } +} \ No newline at end of file diff --git a/terraform/modules/azure/db_server/main.tf b/terraform/modules/azure/db_server/main.tf new file mode 100644 index 000000000..3a30de244 --- /dev/null +++ b/terraform/modules/azure/db_server/main.tf @@ -0,0 +1,25 @@ +resource "azurerm_resource_group" "rg_db" { + name = var.resource_group_name + location = var.location +} + +resource "azurerm_mysql_server" "mysqlserver" { + name = var.db_server_name + location = azurerm_resource_group.rg_db.location + resource_group_name = azurerm_resource_group.rg_db.name + + administrator_login = var.administrator_login + administrator_login_password = var.administrator_login_password + + sku_name = var.sku_name + storage_mb = var.storage_mb + version = var.db_version + + auto_grow_enabled = var.dbproperties["auto_grow_enabled"] + backup_retention_days = var.dbproperties["backup_retention_days"] + geo_redundant_backup_enabled = var.dbproperties["geo_redundant_backup_enabled"] + infrastructure_encryption_enabled = var.dbproperties["infrastructure_encryption_enabled"] + public_network_access_enabled = var.dbproperties["public_network_access_enabled"] + ssl_enforcement_enabled = var.dbproperties["ssl_enforcement_enabled"] + ssl_minimal_tls_version_enforced = var.dbproperties["ssl_minimal_tls_version_enforced"] +} \ No newline at end of file diff --git a/terraform/modules/azure/db_server/variable.tf b/terraform/modules/azure/db_server/variable.tf new file mode 100644 index 000000000..82b1e8e4d --- /dev/null +++ b/terraform/modules/azure/db_server/variable.tf @@ -0,0 +1,53 @@ +//Created by Suresh + + +variable resource_group_name{ + type =string +} + +variable location{ + type =string +} + +variable db_server_name{ + type =string +} + +variable administrator_login { + type =string + default = "mysqladminun" +} + +variable administrator_login_password{ + type =string + default = "nordcloud" +} + +variable sku_name { + type =string +} + +variable storage_mb { + type = number + default = 5120 +} + +variable db_version{ + type =string + default= 5.7 +} + + +variable "dbproperties" { + type = map + default = { + auto_grow_enabled = true + backup_retention_days = 7 + geo_redundant_backup_enabled = false + infrastructure_encryption_enabled = false + public_network_access_enabled = true + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_2" + + } +} diff --git a/terraform/modules/azure/db_server/versions.tf b/terraform/modules/azure/db_server/versions.tf new file mode 100644 index 000000000..951d6c58a --- /dev/null +++ b/terraform/modules/azure/db_server/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } +} \ No newline at end of file diff --git a/terraform/modules/terraform-aws-ecs-codepipeline/fixtures.us-east-2.tfvars b/terraform/modules/terraform-aws-ecs-codepipeline/fixtures.us-east-2.tfvars deleted file mode 100644 index 165eb9002..000000000 --- a/terraform/modules/terraform-aws-ecs-codepipeline/fixtures.us-east-2.tfvars +++ /dev/null @@ -1,123 +0,0 @@ -region = "us-east-2" - -availability_zones = ["us-east-2a", "us-east-2b"] - -namespace = "eg" - -stage = "test" - -name = "ecs-codepipeline" - -vpc_cidr_block = "172.16.0.0/16" - -ecs_launch_type = "FARGATE" - -network_mode = "awsvpc" - -ignore_changes_task_definition = true - -assign_public_ip = false - -propagate_tags = "TASK_DEFINITION" - -deployment_minimum_healthy_percent = 100 - -deployment_maximum_percent = 200 - -deployment_controller_type = "ECS" - -desired_count = 1 - -task_memory = 512 - -task_cpu = 256 - -container_name = "geodesic" - -container_image = "cloudposse/geodesic" - -container_memory = 256 - -container_memory_reservation = 128 - -container_cpu = 256 - -container_essential = true - -container_readonly_root_filesystem = false - -container_environment = [ - { - name = "string_var" - value = "I am a string" - }, - { - name = "true_boolean_var" - value = true - }, - { - name = "false_boolean_var" - value = false - }, - { - name = "integer_var" - value = 42 - } -] - -container_port_mappings = [ - { - containerPort = 80 - hostPort = 80 - protocol = "tcp" - }, - { - containerPort = 443 - hostPort = 443 - protocol = "udp" - } -] - -github_oauth_token = "381cbacb0327261141808da9220815d33ad6bb1c" - -github_webhooks_token = "test" - -repo_owner = "roercik85" - -repo_name = "notejam" - -branch = "rgradzki-demo" - -build_image = "aws/codebuild/docker:17.09.0" - -build_compute_type = "BUILD_GENERAL1_SMALL" - -build_timeout = 60 - -poll_source_changes = true - -privileged_mode = true - -image_repo_name = "terraform-aws-ecs-codepipeline" - -image_tag = "latest" - -webhook_enabled = false - -s3_bucket_force_destroy = true - -environment_variables = [ - { - name = "APP_URL" - value = "https://app.example.com" - }, - { - name = "COMPANY_NAME" - value = "Cloud Posse" - }, - { - name = "TIME_ZONE" - value = "America/Los_Angeles" - - } -] diff --git a/terraform/modules/terraform-aws-ecs-codepipeline/main.tf b/terraform/modules/terraform-aws-ecs-codepipeline/main.tf deleted file mode 100644 index ee0cec9c9..000000000 --- a/terraform/modules/terraform-aws-ecs-codepipeline/main.tf +++ /dev/null @@ -1,110 +0,0 @@ -provider "aws" { - region = var.region -} - -module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0" - namespace = var.namespace - name = var.name - stage = var.stage - delimiter = var.delimiter - attributes = var.attributes - tags = var.tags -} - -module "vpc" { - source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1" - namespace = var.namespace - stage = var.stage - name = var.name - delimiter = var.delimiter - attributes = var.attributes - cidr_block = var.vpc_cidr_block - tags = var.tags -} - -module "subnets" { - source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.1" - availability_zones = var.availability_zones - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - delimiter = var.delimiter - vpc_id = module.vpc.vpc_id - igw_id = module.vpc.igw_id - cidr_block = module.vpc.vpc_cidr_block - nat_gateway_enabled = true - nat_instance_enabled = false - tags = var.tags -} - -resource "aws_ecs_cluster" "default" { - name = module.label.id - tags = module.label.tags -} - -module "container_definition" { - source = "git::https://github.com/cloudposse/terraform-aws-ecs-container-definition.git?ref=tags/0.21.0" - container_name = var.container_name - container_image = var.container_image - container_memory = var.container_memory - container_memory_reservation = var.container_memory_reservation - container_cpu = var.container_cpu - essential = var.container_essential - readonly_root_filesystem = var.container_readonly_root_filesystem - environment = var.container_environment - port_mappings = var.container_port_mappings -} - -module "ecs_alb_service_task" { - source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=master" - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - delimiter = var.delimiter - alb_security_group = module.vpc.vpc_default_security_group_id - container_definition_json = module.container_definition.json - ecs_cluster_arn = aws_ecs_cluster.default.arn - launch_type = var.ecs_launch_type - vpc_id = module.vpc.vpc_id - security_group_ids = [module.vpc.vpc_default_security_group_id] - subnet_ids = module.subnets.public_subnet_ids - tags = var.tags - ignore_changes_task_definition = var.ignore_changes_task_definition - network_mode = var.network_mode - assign_public_ip = var.assign_public_ip - propagate_tags = var.propagate_tags - deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent - deployment_maximum_percent = var.deployment_maximum_percent - deployment_controller_type = var.deployment_controller_type - desired_count = var.desired_count - task_memory = var.task_memory - task_cpu = var.task_cpu -} - -module "ecs_codepipeline" { - source = "git::https://github.com/cloudposse/terraform-aws-ecs-codepipeline.git?ref=master" - namespace = var.namespace - stage = var.stage - name = var.name - region = var.region - github_oauth_token = var.github_oauth_token - github_webhooks_token = var.github_webhooks_token - repo_owner = var.repo_owner - repo_name = var.repo_name - branch = var.branch - build_image = var.build_image - build_compute_type = var.build_compute_type - build_timeout = var.build_timeout - poll_source_changes = var.poll_source_changes - privileged_mode = var.privileged_mode - image_repo_name = var.image_repo_name - image_tag = var.image_tag - webhook_enabled = var.webhook_enabled - s3_bucket_force_destroy = var.s3_bucket_force_destroy - environment_variables = var.environment_variables - ecs_cluster_name = aws_ecs_cluster.default.name - service_name = module.ecs_alb_service_task.service_name -} diff --git a/terraform/modules/terraform-aws-ecs-codepipeline/outputs.tf b/terraform/modules/terraform-aws-ecs-codepipeline/outputs.tf deleted file mode 100644 index 042eafd30..000000000 --- a/terraform/modules/terraform-aws-ecs-codepipeline/outputs.tf +++ /dev/null @@ -1,150 +0,0 @@ -output "public_subnet_cidrs" { - value = module.subnets.public_subnet_cidrs - description = "Public subnet CIDRs" -} - -output "private_subnet_cidrs" { - value = module.subnets.private_subnet_cidrs - description = "Private subnet CIDRs" -} - -output "vpc_cidr" { - value = module.vpc.vpc_cidr_block - description = "VPC ID" -} - -output "container_definition_json" { - value = module.container_definition.json - description = "JSON encoded list of container definitions for use with other terraform resources such as aws_ecs_task_definition" -} - -output "container_definition_json_map" { - value = module.container_definition.json_map - description = "JSON encoded container definitions for use with other terraform resources such as aws_ecs_task_definition" -} - -output "ecs_cluster_id" { - value = aws_ecs_cluster.default.id - description = "ECS cluster ID" -} - -output "ecs_cluster_arn" { - value = aws_ecs_cluster.default.arn - description = "ECS cluster ARN" -} - -output "ecs_exec_role_policy_id" { - description = "The ECS service role policy ID, in the form of `role_name:role_policy_name`" - value = module.ecs_alb_service_task.ecs_exec_role_policy_id -} - -output "ecs_exec_role_policy_name" { - description = "ECS service role name" - value = module.ecs_alb_service_task.ecs_exec_role_policy_name -} - -output "service_name" { - description = "ECS Service name" - value = module.ecs_alb_service_task.service_name -} - -output "service_role_arn" { - description = "ECS Service role ARN" - value = module.ecs_alb_service_task.service_role_arn -} - -output "task_exec_role_name" { - description = "ECS Task role name" - value = module.ecs_alb_service_task.task_exec_role_name -} - -output "task_exec_role_arn" { - description = "ECS Task exec role ARN" - value = module.ecs_alb_service_task.task_exec_role_arn -} - -output "task_role_name" { - description = "ECS Task role name" - value = module.ecs_alb_service_task.task_role_name -} - -output "task_role_arn" { - description = "ECS Task role ARN" - value = module.ecs_alb_service_task.task_role_arn -} - -output "task_role_id" { - description = "ECS Task role id" - value = module.ecs_alb_service_task.task_role_id -} - -output "service_security_group_id" { - description = "Security Group ID of the ECS task" - value = module.ecs_alb_service_task.service_security_group_id -} - -output "task_definition_family" { - description = "ECS task definition family" - value = module.ecs_alb_service_task.task_definition_family -} - -output "task_definition_revision" { - description = "ECS task definition revision" - value = module.ecs_alb_service_task.task_definition_revision -} - -output "codebuild_project_name" { - description = "CodeBuild project name" - value = module.ecs_codepipeline.codebuild_project_name -} - -output "codebuild_project_id" { - description = "CodeBuild project ID" - value = module.ecs_codepipeline.codebuild_project_id -} - -output "codebuild_role_id" { - description = "CodeBuild IAM Role ID" - value = module.ecs_codepipeline.codebuild_role_id -} - -output "codebuild_role_arn" { - description = "CodeBuild IAM Role ARN" - value = module.ecs_codepipeline.codebuild_role_arn -} - -output "codebuild_cache_bucket_name" { - description = "CodeBuild cache S3 bucket name" - value = module.ecs_codepipeline.codebuild_cache_bucket_name -} - -output "codebuild_cache_bucket_arn" { - description = "CodeBuild cache S3 bucket ARN" - value = module.ecs_codepipeline.codebuild_cache_bucket_arn -} - -output "codebuild_badge_url" { - description = "The URL of the build badge when badge_enabled is enabled" - value = module.ecs_codepipeline.codebuild_badge_url -} - -output "codepipeline_id" { - description = "CodePipeline ID" - value = module.ecs_codepipeline.codepipeline_id -} - -output "codepipeline_arn" { - description = "CodePipeline ARN" - value = module.ecs_codepipeline.codepipeline_arn -} - -output "webhook_id" { - description = "The CodePipeline webhook's ID" - value = module.ecs_codepipeline.webhook_id -} - -output "webhook_url" { - description = "The CodePipeline webhook's URL. POST events to this endpoint to trigger the target" - value = module.ecs_codepipeline.webhook_url - sensitive = true -} diff --git a/terraform/modules/terraform-aws-ecs-codepipeline/variables.tf b/terraform/modules/terraform-aws-ecs-codepipeline/variables.tf deleted file mode 100644 index a3fa19eca..000000000 --- a/terraform/modules/terraform-aws-ecs-codepipeline/variables.tf +++ /dev/null @@ -1,237 +0,0 @@ -variable "region" { - type = string - description = "AWS Region for S3 bucket" -} - -variable "availability_zones" { - type = list(string) - description = "List of availability zones" -} - -variable "vpc_cidr_block" { - type = string - description = "VPC CIDR block" -} - -variable "namespace" { - type = string - description = "Namespace (e.g. `eg` or `cp`)" -} - -variable "stage" { - type = string - description = "Stage (e.g. `prod`, `dev`, `staging`)" -} - -variable "name" { - type = string - description = "Name of the application" -} - -variable "delimiter" { - type = string - default = "-" - description = "Delimiter between `namespace`, `stage`, `name` and `attributes`" -} - -variable "attributes" { - type = list(string) - description = "Additional attributes (_e.g._ \"1\")" - default = [] -} - -variable "tags" { - type = map(string) - description = "Additional tags (_e.g._ { BusinessUnit : ABC })" - default = {} -} - -variable "ecs_launch_type" { - type = string - description = "ECS launch type" -} - -variable "container_name" { - type = string - description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)" -} - -variable "container_image" { - type = string - description = "The image used to start the container. Images in the Docker Hub registry available by default" -} - -variable "container_memory" { - type = number - description = "The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container_memory of all containers in a task will need to be lower than the task memory value" -} - -variable "container_memory_reservation" { - type = number - description = "The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container_memory hard limit" -} - -variable "container_port_mappings" { - type = list(object({ - containerPort = number - hostPort = number - protocol = string - })) - - description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort" -} - -variable "container_cpu" { - type = number - description = "The number of cpu units to reserve for the container. This is optional for tasks using Fargate launch type and the total amount of container_cpu of all containers in a task will need to be lower than the task-level cpu value" -} - -variable "container_essential" { - type = bool - description = "Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value" -} - -variable "container_environment" { - type = list(object({ - name = string - value = string - })) - description = "The environment variables to pass to the container. This is a list of maps" -} - -variable "container_readonly_root_filesystem" { - type = bool - description = "Determines whether a container is given read-only access to its root filesystem. Due to how Terraform type casts booleans in json it is required to double quote this value" -} - -variable "network_mode" { - type = string - description = "The network mode to use for the task. This is required to be `awsvpc` for `FARGATE` `launch_type`" -} - -variable "task_cpu" { - type = number - description = "The number of CPU units used by the task. If using `FARGATE` launch type `task_cpu` must match supported memory values (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size)" -} - -variable "task_memory" { - type = number - description = "The amount of memory (in MiB) used by the task. If using Fargate launch type `task_memory` must match supported cpu value (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size)" -} - -variable "desired_count" { - type = number - description = "The number of instances of the task definition to place and keep running" -} - -variable "deployment_controller_type" { - type = string - description = "Type of deployment controller. Valid values are `CODE_DEPLOY` and `ECS`" -} - -variable "deployment_maximum_percent" { - type = number - description = "The upper limit of the number of tasks (as a percentage of `desired_count`) that can be running in a service during a deployment" -} - -variable "deployment_minimum_healthy_percent" { - type = number - description = "The lower limit (as a percentage of `desired_count`) of the number of tasks that must remain running and healthy in a service during a deployment" -} - -variable "ignore_changes_task_definition" { - type = bool - description = "Whether to ignore changes in container definition and task definition in the ECS service" -} - -variable "assign_public_ip" { - type = bool - description = "Assign a public IP address to the ENI (Fargate launch type only). Valid values are `true` or `false`. Default `false`" -} - -variable "propagate_tags" { - type = string - description = "Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION" -} - -variable "github_oauth_token" { - type = string - description = "GitHub OAuth Token with permissions to access private repositories" -} - -variable "github_webhooks_token" { - type = string - description = "GitHub OAuth Token with permissions to create webhooks. If not provided, can be sourced from the `GITHUB_TOKEN` environment variable" -} - -variable "repo_owner" { - type = string - description = "GitHub Organization or Username" -} - -variable "repo_name" { - type = string - description = "GitHub repository name of the application to be built and deployed to ECS" -} - -variable "branch" { - type = string - description = "Branch of the GitHub repository, _e.g._ `master`" -} - -variable "build_image" { - type = string - description = "Docker image for build environment, _e.g._ `aws/codebuild/docker:docker:17.09.0`" -} - -variable "build_compute_type" { - type = string - description = "`CodeBuild` instance size. Possible values are: `BUILD_GENERAL1_SMALL` `BUILD_GENERAL1_MEDIUM` `BUILD_GENERAL1_LARGE`" -} - -variable "build_timeout" { - type = number - description = "How long in minutes, from 5 to 480 (8 hours), for AWS CodeBuild to wait until timing out any related build that does not get marked as completed" -} - -# https://www.terraform.io/docs/configuration/variables.html -# It is recommended you avoid using boolean values and use explicit strings -variable "poll_source_changes" { - type = bool - description = "Periodically check the location of your source content and run the pipeline if changes are detected" -} - -variable "privileged_mode" { - type = bool - description = "If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images" -} - -variable "image_repo_name" { - type = string - description = "ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html)" -} - -variable "image_tag" { - type = string - description = "Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html)" -} - -variable "environment_variables" { - type = list(object( - { - name = string - value = string - })) - - description = "A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build" -} - -variable "webhook_enabled" { - type = bool - description = "Set to false to prevent the module from creating any webhook resources" -} - -variable "s3_bucket_force_destroy" { - type = bool - description = "A boolean that indicates all objects should be deleted from the CodePipeline artifact store S3 bucket so that the bucket can be destroyed without error" -} diff --git a/terraform/modules/terraform-aws-ecs-codepipeline/versions.tf b/terraform/modules/terraform-aws-ecs-codepipeline/versions.tf deleted file mode 100644 index 517cebf43..000000000 --- a/terraform/modules/terraform-aws-ecs-codepipeline/versions.tf +++ /dev/null @@ -1,11 +0,0 @@ -terraform { - required_version = "~> 0.12.0" - - required_providers { - aws = "~> 2.0" - template = "~> 2.0" - local = "~> 1.2" - random = "~> 2.1" - null = "~> 2.0" - } -} diff --git a/terraform/modules/terraform-aws-elastic-beanstalk-environment/fixtures.us-east-2.tfvars b/terraform/modules/terraform-aws-elastic-beanstalk-environment/fixtures.us-east-2.tfvars deleted file mode 100644 index 875795045..000000000 --- a/terraform/modules/terraform-aws-elastic-beanstalk-environment/fixtures.us-east-2.tfvars +++ /dev/null @@ -1,96 +0,0 @@ -region = "us-east-2" - -availability_zones = ["us-east-2a", "us-east-2b"] - -namespace = "eg" - -stage = "test" - -name = "notejam" - -description = "Test elastic-beanstalk-environment" - -tier = "WebServer" - -environment_type = "LoadBalanced" - -loadbalancer_type = "application" - -availability_zone_selector = "Any 2" - -instance_type = "t3.micro" - -autoscale_min = 1 - -autoscale_max = 2 - -wait_for_ready_timeout = "20m" - - -force_destroy = true - -rolling_update_enabled = true - -rolling_update_type = "Health" - -updating_min_in_service = 0 - -updating_max_batch = 1 - -healthcheck_url = "/" - -application_port = 80 - -root_volume_size = 8 - -root_volume_type = "gp2" - -autoscale_measure_name = "CPUUtilization" - -autoscale_statistic = "Average" - -autoscale_unit = "Percent" - -autoscale_lower_bound = 20 - -autoscale_lower_increment = -1 - -autoscale_upper_bound = 80 - -autoscale_upper_increment = 1 - -elb_scheme = "public" - -// https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html -// https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.docker -solution_stack_name = "64bit Amazon Linux 2018.03 v2.9.5 running Python 2.7" - -version_label = "" - -dns_zone_id = "Z3SO0TKDDQ0RGG" - -// https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html -additional_settings = [ - { - namespace = "aws:elasticbeanstalk:environment:process:default" - name = "StickinessEnabled" - value = "false" - }, - { - namespace = "aws:elasticbeanstalk:managedactions" - name = "ManagedActionsEnabled" - value = "false" - }, - { - namespace = "aws:elasticbeanstalk:container:python" - name = "WSGIPath" - value = "notejam/wsgi.py" - } -] - -env_vars = { - "DB_HOST" = "xxxxxxxxxxxxxx" - "DB_USERNAME" = "yyyyyyyyyyyyy" - "DB_PASSWORD" = "zzzzzzzzzzzzzzzzzzz" - "ANOTHER_ENV_VAR" = "123456789" -} diff --git a/terraform/modules/terraform-aws-elastic-beanstalk-environment/main.tf b/terraform/modules/terraform-aws-elastic-beanstalk-environment/main.tf deleted file mode 100644 index 53a025bd9..000000000 --- a/terraform/modules/terraform-aws-elastic-beanstalk-environment/main.tf +++ /dev/null @@ -1,99 +0,0 @@ -provider "aws" { - region = var.region -} - -module "vpc" { - source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.0" - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - tags = var.tags - delimiter = var.delimiter - cidr_block = "172.16.0.0/16" -} - -module "subnets" { - source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.0" - availability_zones = var.availability_zones - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - tags = var.tags - delimiter = var.delimiter - vpc_id = module.vpc.vpc_id - igw_id = module.vpc.igw_id - cidr_block = module.vpc.vpc_cidr_block - nat_gateway_enabled = true - nat_instance_enabled = false -} - -module "elastic_beanstalk_application" { - source = "git::https://github.com/cloudposse/terraform-aws-elastic-beanstalk-application.git?ref=tags/0.3.0" - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - tags = var.tags - delimiter = var.delimiter - description = "Test elastic_beanstalk_application" -} - -module "elastic_beanstalk_environment" { - source = "git::https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment.git?ref=tags/0.18.0" - namespace = var.namespace - stage = var.stage - name = var.name - attributes = var.attributes - tags = var.tags - delimiter = var.delimiter - description = var.description - region = var.region - availability_zone_selector = var.availability_zone_selector - dns_zone_id = var.dns_zone_id - - wait_for_ready_timeout = var.wait_for_ready_timeout - elastic_beanstalk_application_name = module.elastic_beanstalk_application.elastic_beanstalk_application_name - environment_type = var.environment_type - loadbalancer_type = var.loadbalancer_type - elb_scheme = var.elb_scheme - tier = var.tier - version_label = var.version_label - force_destroy = var.force_destroy - - instance_type = var.instance_type - root_volume_size = var.root_volume_size - root_volume_type = var.root_volume_type - - autoscale_min = var.autoscale_min - autoscale_max = var.autoscale_max - autoscale_measure_name = var.autoscale_measure_name - autoscale_statistic = var.autoscale_statistic - autoscale_unit = var.autoscale_unit - autoscale_lower_bound = var.autoscale_lower_bound - autoscale_lower_increment = var.autoscale_lower_increment - autoscale_upper_bound = var.autoscale_upper_bound - autoscale_upper_increment = var.autoscale_upper_increment - - vpc_id = module.vpc.vpc_id - loadbalancer_subnets = module.subnets.public_subnet_ids - application_subnets = module.subnets.private_subnet_ids - allowed_security_groups = [module.vpc.vpc_default_security_group_id] - - rolling_update_enabled = var.rolling_update_enabled - rolling_update_type = var.rolling_update_type - updating_min_in_service = var.updating_min_in_service - updating_max_batch = var.updating_max_batch - - healthcheck_url = var.healthcheck_url - application_port = var.application_port - - // https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html - // https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.docker - solution_stack_name = var.solution_stack_name - - additional_settings = var.additional_settings - env_vars = var.env_vars -} - diff --git a/terraform/modules/terraform-aws-elastic-beanstalk-environment/outputs.tf b/terraform/modules/terraform-aws-elastic-beanstalk-environment/outputs.tf deleted file mode 100644 index 6119d3bb0..000000000 --- a/terraform/modules/terraform-aws-elastic-beanstalk-environment/outputs.tf +++ /dev/null @@ -1,105 +0,0 @@ -output "public_subnet_cidrs" { - value = module.subnets.public_subnet_cidrs - description = "Public subnet CIDRs" -} - -output "private_subnet_cidrs" { - value = module.subnets.private_subnet_cidrs - description = "Private subnet CIDRs" -} - -output "vpc_cidr" { - value = module.vpc.vpc_cidr_block - description = "VPC ID" -} - -output "elastic_beanstalk_application_name" { - value = module.elastic_beanstalk_application.elastic_beanstalk_application_name - description = "Elastic Beanstalk Application name" -} - -output "elastic_beanstalk_environment_hostname" { - value = module.elastic_beanstalk_environment.hostname - description = "DNS hostname" -} - -output "elastic_beanstalk_environment_id" { - description = "ID of the Elastic Beanstalk environment" - value = module.elastic_beanstalk_environment.id -} - -output "elastic_beanstalk_environment_name" { - value = module.elastic_beanstalk_environment.name - description = "Name" -} - -output "elastic_beanstalk_environment_security_group_id" { - value = module.elastic_beanstalk_environment.security_group_id - description = "Security group id" -} - -output "elastic_beanstalk_environment_elb_zone_id" { - value = module.elastic_beanstalk_environment.elb_zone_id - description = "ELB zone id" -} - -output "elastic_beanstalk_environment_ec2_instance_profile_role_name" { - value = module.elastic_beanstalk_environment.ec2_instance_profile_role_name - description = "Instance IAM role name" -} - -output "elastic_beanstalk_environment_tier" { - description = "The environment tier" - value = module.elastic_beanstalk_environment.tier -} - -output "elastic_beanstalk_environment_application" { - description = "The Elastic Beanstalk Application specified for this environment" - value = module.elastic_beanstalk_environment.application -} - -output "elastic_beanstalk_environment_setting" { - description = "Settings specifically set for this environment" - value = module.elastic_beanstalk_environment.setting -} - -output "elastic_beanstalk_environment_all_settings" { - description = "List of all option settings configured in the environment. These are a combination of default settings and their overrides from setting in the configuration" - value = module.elastic_beanstalk_environment.all_settings -} - -output "elastic_beanstalk_environment_endpoint" { - description = "Fully qualified DNS name for the environment" - value = module.elastic_beanstalk_environment.endpoint -} - -output "elastic_beanstalk_environment_autoscaling_groups" { - description = "The autoscaling groups used by this environment" - value = module.elastic_beanstalk_environment.autoscaling_groups -} - -output "elastic_beanstalk_environment_instances" { - description = "Instances used by this environment" - value = module.elastic_beanstalk_environment.instances -} - -output "elastic_beanstalk_environment_launch_configurations" { - description = "Launch configurations in use by this environment" - value = module.elastic_beanstalk_environment.launch_configurations -} - -output "elastic_beanstalk_environment_load_balancers" { - description = "Elastic Load Balancers in use by this environment" - value = module.elastic_beanstalk_environment.load_balancers -} - -output "elastic_beanstalk_environment_queues" { - description = "SQS queues in use by this environment" - value = module.elastic_beanstalk_environment.queues -} - -output "elastic_beanstalk_environment_triggers" { - description = "Autoscaling triggers in use by this environment" - value = module.elastic_beanstalk_environment.triggers -} - diff --git a/terraform/modules/terraform-aws-elastic-beanstalk-environment/variables.tf b/terraform/modules/terraform-aws-elastic-beanstalk-environment/variables.tf deleted file mode 100644 index 12a0b345e..000000000 --- a/terraform/modules/terraform-aws-elastic-beanstalk-environment/variables.tf +++ /dev/null @@ -1,204 +0,0 @@ -variable "region" { - type = string - description = "AWS region" -} - -variable "availability_zones" { - type = list(string) - description = "List of availability zones" -} - -variable "namespace" { - type = string - description = "Namespace, which could be your organization name, e.g. 'eg' or 'cp'" -} - -variable "stage" { - type = string - description = "Stage, e.g. 'prod', 'staging', 'dev', or 'test'" -} - -variable "name" { - type = string - description = "Solution name, e.g. 'app' or 'cluster'" -} - -variable "delimiter" { - type = string - default = "-" - description = "Delimiter to be used between `name`, `namespace`, `stage`, etc." -} - -variable "attributes" { - type = list(string) - default = [] - description = "Additional attributes (e.g. `1`)" -} - -variable "tags" { - type = map(string) - default = {} - description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)" -} - -variable "description" { - type = string - description = "Short description of the Environment" -} - -variable "environment_type" { - type = string - description = "Environment type, e.g. 'LoadBalanced' or 'SingleInstance'. If setting to 'SingleInstance', `rolling_update_type` must be set to 'Time', `updating_min_in_service` must be set to 0, and `loadbalancer_subnets` will be unused (it applies to the ELB, which does not exist in SingleInstance environments)" -} - -variable "loadbalancer_type" { - type = string - description = "Load Balancer type, e.g. 'application' or 'classic'" -} - -variable "dns_zone_id" { - type = string - description = "Route53 parent zone ID. The module will create sub-domain DNS record in the parent zone for the EB environment" -} - -variable "availability_zone_selector" { - type = string - description = "Availability Zone selector" -} - -variable "instance_type" { - type = string - description = "Instances type" -} - -variable "autoscale_min" { - type = number - description = "Minumum instances to launch" -} - -variable "autoscale_max" { - type = number - description = "Maximum instances to launch" -} - -variable "solution_stack_name" { - type = string - description = "Elastic Beanstalk stack, e.g. Docker, Go, Node, Java, IIS. For more info, see https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html" -} - -variable "wait_for_ready_timeout" { - type = string - description = "The maximum duration to wait for the Elastic Beanstalk Environment to be in a ready state before timing out" -} - -variable "tier" { - type = string - description = "Elastic Beanstalk Environment tier, e.g. 'WebServer' or 'Worker'" -} - -variable "version_label" { - type = string - description = "Elastic Beanstalk Application version to deploy" -} - -variable "force_destroy" { - type = bool - description = "Force destroy the S3 bucket for load balancer logs" -} - -variable "rolling_update_enabled" { - type = bool - description = "Whether to enable rolling update" -} - -variable "rolling_update_type" { - type = string - description = "`Health` or `Immutable`. Set it to `Immutable` to apply the configuration change to a fresh group of instances" -} - -variable "updating_min_in_service" { - type = number - description = "Minimum number of instances in service during update" -} - -variable "updating_max_batch" { - type = number - description = "Maximum number of instances to update at once" -} - -variable "healthcheck_url" { - type = string - description = "Application Health Check URL. Elastic Beanstalk will call this URL to check the health of the application running on EC2 instances" -} - -variable "application_port" { - type = number - description = "Port application is listening on" -} - -variable "root_volume_size" { - type = number - description = "The size of the EBS root volume" -} - -variable "root_volume_type" { - type = string - description = "The type of the EBS root volume" -} - -variable "autoscale_measure_name" { - type = string - description = "Metric used for your Auto Scaling trigger" -} - -variable "autoscale_statistic" { - type = string - description = "Statistic the trigger should use, such as Average" -} - -variable "autoscale_unit" { - type = string - description = "Unit for the trigger measurement, such as Bytes" -} - -variable "autoscale_lower_bound" { - type = number - description = "Minimum level of autoscale metric to remove an instance" -} - -variable "autoscale_lower_increment" { - type = number - description = "How many Amazon EC2 instances to remove when performing a scaling activity." -} - -variable "autoscale_upper_bound" { - type = number - description = "Maximum level of autoscale metric to add an instance" -} - -variable "autoscale_upper_increment" { - type = number - description = "How many Amazon EC2 instances to add when performing a scaling activity" -} - -variable "elb_scheme" { - type = string - description = "Specify `internal` if you want to create an internal load balancer in your Amazon VPC so that your Elastic Beanstalk application cannot be accessed from outside your Amazon VPC" -} - -variable "additional_settings" { - type = list(object({ - namespace = string - name = string - value = string - })) - - description = "Additional Elastic Beanstalk setttings. For full list of options, see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html" - default = [] -} - -variable "env_vars" { - type = map(string) - default = {} - description = "Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' }" -} diff --git a/terraform/modules/terraform-aws-elastic-beanstalk-environment/versions.tf b/terraform/modules/terraform-aws-elastic-beanstalk-environment/versions.tf deleted file mode 100644 index 4c7776f92..000000000 --- a/terraform/modules/terraform-aws-elastic-beanstalk-environment/versions.tf +++ /dev/null @@ -1,8 +0,0 @@ -terraform { - required_version = "~> 0.12.0" - - required_providers { - aws = "~> 2.0" - null = "~> 2.0" - } -} diff --git a/terraform/notejam-tf/provider.tf b/terraform/notejam-tf/provider.tf new file mode 100644 index 000000000..0119b8b2a --- /dev/null +++ b/terraform/notejam-tf/provider.tf @@ -0,0 +1,11 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf new file mode 100644 index 000000000..0c947f7d5 --- /dev/null +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -0,0 +1,11 @@ +module "app-cluster" { + source = "../modules/azure/aks" + location = var.location + resource_group_name = var.cluster["app_resourcegroup"] + agent_count = 1 + dns_prefix = var.cluster["dns_prefix"] + cluster_name = var.cluster["app_name"] + log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] + client_id = var.client_id + client_secret = var.client_secret +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-database.tf b/terraform/notejam-tf/resource-database.tf new file mode 100644 index 000000000..cfbdbe1c8 --- /dev/null +++ b/terraform/notejam-tf/resource-database.tf @@ -0,0 +1,7 @@ +module "app-db" { + source = "../modules/azure/database" + database_name = var.database_name + db_resource_group_name = var.db_resource_group_name + db_server_name = var.db_server_name + depends_on = [module.app-datbase-server] +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-db-server.tf b/terraform/notejam-tf/resource-db-server.tf new file mode 100644 index 000000000..7418851ab --- /dev/null +++ b/terraform/notejam-tf/resource-db-server.tf @@ -0,0 +1,12 @@ +module "app-datbase-server" { + source = "../modules/azure/db_server" + db_server_name = var.db_server_name + administrator_login = var.administrator_login + administrator_login_password = var.administrator_login_password + sku_name = var.sku_name + storage_mb = var.storage_mb + db_version = var.db_version + resource_group_name = var.db_resource_group_name + location = var.location +} + diff --git a/terraform/notejam-tf/resource-rg.tf b/terraform/notejam-tf/resource-rg.tf new file mode 100644 index 000000000..1c92c4258 --- /dev/null +++ b/terraform/notejam-tf/resource-rg.tf @@ -0,0 +1,16 @@ +// Hub is where Hub-networks stays + + +// Spoke is where AKS stays +resource "azurerm_resource_group" "rg_hub" { + name = var.vnet-hub["vnet_resourcegroup"] + location = var.location +} + + + +// Spoke is where AKS stays +resource "azurerm_resource_group" "rg_spoke" { + name = var.cluster["app_resourcegroup"] + location = var.location +} diff --git a/terraform/notejam-tf/resource-vnet.tf b/terraform/notejam-tf/resource-vnet.tf new file mode 100644 index 000000000..e69de29bb diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars new file mode 100644 index 000000000..165167cfd --- /dev/null +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -0,0 +1,42 @@ + +location = "East US" +client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" +client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" +//Spoke +cluster = { + app_name = "aks-notejam" + app_resourcegroup = "rg-app" + dns_prefix = "nj" + log_analytics_workspace_name = "ws-notejam" +} +//Hub +vnet-hub = { + vnet_resourcegroup = "rg-hub-network" +} + +//DB +db_server_name = "nordcloud-mysqlserver" +database_name = "dbnotejam" +db_resource_group_name = "rg-notejam-db" + + +administrator_login = "mysqladminun" +administrator_login_password = "H@Sh1CoR3!" + +sku_name = "B_Gen5_2" +storage_mb = 5120 +db_version = "5.7" + + + +dbproperties = { + auto_grow_enabled = true + backup_retention_days = 7 + geo_redundant_backup_enabled = false + infrastructure_encryption_enabled = false + public_network_access_enabled = true + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_2" + + +} diff --git a/terraform/notejam-tf/terraform.tfstate b/terraform/notejam-tf/terraform.tfstate new file mode 100644 index 000000000..268cd7717 --- /dev/null +++ b/terraform/notejam-tf/terraform.tfstate @@ -0,0 +1,8 @@ +{ + "version": 4, + "terraform_version": "0.13.5", + "serial": 19, + "lineage": "e349672b-937a-9816-1456-3541ca27b938", + "outputs": {}, + "resources": [] +} diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf new file mode 100644 index 000000000..73480b5c0 --- /dev/null +++ b/terraform/notejam-tf/variables.tf @@ -0,0 +1,86 @@ + +variable "location" { + type = string +} +variable "client_id" { + type = string +} +variable "client_secret" { + type = string +} +# Variables related to application deployment cluster +variable "cluster" { + type = map + default = { + app_name = "aks-notejam" + app_resourcegroup = "rg-app" + dns_prefix = "nj" + log_analytics_workspace_name = "ws-notejam" + } +} +variable "vnet-hub" { + type = map + default = { + vnet_resourcegroup = "rg-hub-network" + + } +} + + +variable db_server_name { + type = string +} + +variable database_name { + type = string +} + + +variable administrator_login { + type = string +} + +variable administrator_login_password { + type = string + +} +variable db_resource_group_name { + type = string + default = "rg-notejam-db" +} + + + +variable sku_name { + type = string +} + +variable storage_mb { + type = number + default = 5120 +} + +variable db_version { + type = string + default = 5.7 +} + + + +variable "dbproperties" { + type = map + default = { + auto_grow_enabled = true + backup_retention_days = 7 + geo_redundant_backup_enabled = false + infrastructure_encryption_enabled = false + public_network_access_enabled = true + ssl_enforcement_enabled = true + ssl_minimal_tls_version_enforced = "TLS1_2" + + } +} + + + + From a7a753e0957f9f3a7e991a7968b08c85e6115334 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 12 Mar 2021 20:28:21 +0000 Subject: [PATCH 03/44] Terraform resources added --- .gitignore | 3 +- spring/pom.xml | 5 ++ .../src/main/resources/application.properties | 21 ++++++- terraform/modules/azure/aks/k8.tf | 57 ++++++++++++++----- terraform/modules/azure/aks/main.tf | 4 +- terraform/modules/azure/aks/output.tf | 5 ++ terraform/modules/azure/aks/variable.tf | 1 + terraform/modules/azure/database/main.tf | 1 + terraform/modules/azure/database/versions.tf | 1 + terraform/modules/azure/db_server/main.tf | 1 + terraform/modules/azure/db_server/variable.tf | 4 +- terraform/modules/azure/db_server/versions.tf | 1 + terraform/notejam-tf/main.tf | 9 +++ terraform/notejam-tf/resource-acr.tf | 20 +++++++ terraform/notejam-tf/resource-app-cluster.tf | 1 + terraform/notejam-tf/resource-database.tf | 7 ++- terraform/notejam-tf/resource-db-server.tf | 5 ++ terraform/notejam-tf/resource-rg.tf | 12 ++-- terraform/notejam-tf/resource-vnet.tf | 1 + terraform/notejam-tf/terraform.auto.tfvars | 20 +++++-- terraform/notejam-tf/terraform.tfstate | 4 +- terraform/notejam-tf/variables.tf | 43 ++++++++------ 22 files changed, 175 insertions(+), 51 deletions(-) create mode 100644 terraform/notejam-tf/main.tf create mode 100644 terraform/notejam-tf/resource-acr.tf diff --git a/.gitignore b/.gitignore index 5db494851..120be0dab 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,5 @@ terraform/notejam-tf/Readme.txt .terraform/** *.backup *.exte -.terraform \ No newline at end of file +.terraform +terraform/notejam-tf/terraform.tfstate diff --git a/spring/pom.xml b/spring/pom.xml index fdb6de015..b86b7c67f 100644 --- a/spring/pom.xml +++ b/spring/pom.xml @@ -70,6 +70,11 @@ spring-security-test test + + mysql + mysql-connector-java + runtime + diff --git a/spring/src/main/resources/application.properties b/spring/src/main/resources/application.properties index b28ecffca..d399c0dee 100644 --- a/spring/src/main/resources/application.properties +++ b/spring/src/main/resources/application.properties @@ -8,8 +8,8 @@ spring.mail.host= smtp.example.net email.sender=suresh.thomas@yahoo.com -spring.datasource.url=jdbc:hsqldb:file:db -spring.jpa.hibernate.ddl-auto=update +#spring.datasource.url=jdbc:hsqldb:file:db +#spring.jpa.hibernate.ddl-auto=update async.queueCapacity= 1000 @@ -18,3 +18,20 @@ recovery.lifetime= P1D #; The length of the generated password. recovery.length= 32 + + +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +#spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=update +spring.datasource.driverClassName=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mysql://nordcloud-mysqlserver.mysql.database.azure.com:3306/dbnotejam +spring.datasource.username=mysqladminun@nordcloud-mysqlserver +spring.datasource.password=H@Sh1CoR3! +spring.datasource.initialization-mode=always +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE +spring.jackson.default-property-inclusion=NON_NULL +spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file diff --git a/terraform/modules/azure/aks/k8.tf b/terraform/modules/azure/aks/k8.tf index 437f6e9af..3ea608d25 100644 --- a/terraform/modules/azure/aks/k8.tf +++ b/terraform/modules/azure/aks/k8.tf @@ -1,33 +1,64 @@ +//Suresh Thomas suresh.thomas@yahoo.com resource "azurerm_resource_group" "k8s" { name = var.resource_group_name location = var.location } - resource "random_id" "log_analytics_workspace_name_suffix" { byte_length = 8 } - -resource "azurerm_log_analytics_workspace" "test" { +resource "azurerm_log_analytics_workspace" "notejam" { # The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant. name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}" location = var.log_analytics_workspace_location resource_group_name = azurerm_resource_group.k8s.name sku = var.log_analytics_workspace_sku } - -resource "azurerm_log_analytics_solution" "test" { +//Log analytics +resource "azurerm_log_analytics_solution" "notejam" { solution_name = "ContainerInsights" - location = azurerm_log_analytics_workspace.test.location + location = azurerm_log_analytics_workspace.notejam.location resource_group_name = azurerm_resource_group.k8s.name - workspace_resource_id = azurerm_log_analytics_workspace.test.id - workspace_name = azurerm_log_analytics_workspace.test.name + workspace_resource_id = azurerm_log_analytics_workspace.notejam.id + workspace_name = azurerm_log_analytics_workspace.notejam.name plan { publisher = "Microsoft" product = "OMSGallery/ContainerInsights" } } +//app +resource "azuread_application" "aks_sp" { + display_name = "sp-aks-${var.cluster_name}" +} +//Service principle +resource "azuread_service_principal" "aks_sp" { + application_id = azuread_application.aks_sp.application_id + app_role_assignment_required = false +} +resource "azuread_service_principal_password" "aks_sp" { + service_principal_id = azuread_service_principal.aks_sp.id + value = random_string.aks_sp_password.result + end_date_relative = "8760h" # 1 year + lifecycle { + ignore_changes = [ + value, + end_date_relative + ] + } +} +resource "random_string" "aks_sp_password" { + keepers = { + env_name = "sp-aks-${var.cluster_name}" + } + length = 24 + min_upper = 1 + min_lower = 1 + min_numeric = 1 + special = true + min_special = 1 + override_special = "!@-_=+." +} resource "azurerm_kubernetes_cluster" "k8s" { name = var.cluster_name location = azurerm_resource_group.k8s.location @@ -48,15 +79,15 @@ resource "azurerm_kubernetes_cluster" "k8s" { vm_size = "Standard_D2_v2" } - service_principal { - client_id = var.client_id - client_secret = var.client_secret - } + service_principal { + client_id = azuread_service_principal.aks_sp.application_id + client_secret = random_string.aks_sp_password.result + } addon_profile { oms_agent { enabled = true - log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id + log_analytics_workspace_id = azurerm_log_analytics_workspace.notejam.id } } diff --git a/terraform/modules/azure/aks/main.tf b/terraform/modules/azure/aks/main.tf index 556695485..e66c65c56 100644 --- a/terraform/modules/azure/aks/main.tf +++ b/terraform/modules/azure/aks/main.tf @@ -1,4 +1,4 @@ - +//Suresh Thomas suresh.thomas@yahoo.com terraform { backend "azurerm" {} -} \ No newline at end of file +} diff --git a/terraform/modules/azure/aks/output.tf b/terraform/modules/azure/aks/output.tf index 0be106473..80c7f0824 100644 --- a/terraform/modules/azure/aks/output.tf +++ b/terraform/modules/azure/aks/output.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com output "client_key" { value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key } @@ -24,4 +25,8 @@ output "kube_config" { output "host" { value = azurerm_kubernetes_cluster.k8s.kube_config.0.host +} + +output "principal_id" { + value = azuread_service_principal.aks_sp.application_id } \ No newline at end of file diff --git a/terraform/modules/azure/aks/variable.tf b/terraform/modules/azure/aks/variable.tf index ddc5e6557..e62923764 100644 --- a/terraform/modules/azure/aks/variable.tf +++ b/terraform/modules/azure/aks/variable.tf @@ -9,6 +9,7 @@ variable "ssh_public_key" { default = "~/.ssh/id_rsa.pub" } +//Suresh Thomas suresh.thomas@yahoo.com variable "dns_prefix" { default = "k8stest" } diff --git a/terraform/modules/azure/database/main.tf b/terraform/modules/azure/database/main.tf index a968ef2c1..192e449a0 100644 --- a/terraform/modules/azure/database/main.tf +++ b/terraform/modules/azure/database/main.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com resource "azurerm_mysql_database" "db" { name = var.database_name resource_group_name = var.db_resource_group_name diff --git a/terraform/modules/azure/database/versions.tf b/terraform/modules/azure/database/versions.tf index 951d6c58a..d928e570b 100644 --- a/terraform/modules/azure/database/versions.tf +++ b/terraform/modules/azure/database/versions.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com terraform { required_providers { azurerm = { diff --git a/terraform/modules/azure/db_server/main.tf b/terraform/modules/azure/db_server/main.tf index 3a30de244..7588891f1 100644 --- a/terraform/modules/azure/db_server/main.tf +++ b/terraform/modules/azure/db_server/main.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com resource "azurerm_resource_group" "rg_db" { name = var.resource_group_name location = var.location diff --git a/terraform/modules/azure/db_server/variable.tf b/terraform/modules/azure/db_server/variable.tf index 82b1e8e4d..781b9d6e8 100644 --- a/terraform/modules/azure/db_server/variable.tf +++ b/terraform/modules/azure/db_server/variable.tf @@ -1,6 +1,6 @@ //Created by Suresh - +//Suresh Thomas suresh.thomas@yahoo.com variable resource_group_name{ type =string } @@ -46,7 +46,7 @@ variable "dbproperties" { geo_redundant_backup_enabled = false infrastructure_encryption_enabled = false public_network_access_enabled = true - ssl_enforcement_enabled = true + ssl_enforcement_enabled = false ssl_minimal_tls_version_enforced = "TLS1_2" } diff --git a/terraform/modules/azure/db_server/versions.tf b/terraform/modules/azure/db_server/versions.tf index 951d6c58a..d928e570b 100644 --- a/terraform/modules/azure/db_server/versions.tf +++ b/terraform/modules/azure/db_server/versions.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com terraform { required_providers { azurerm = { diff --git a/terraform/notejam-tf/main.tf b/terraform/notejam-tf/main.tf new file mode 100644 index 000000000..1b116fb7a --- /dev/null +++ b/terraform/notejam-tf/main.tf @@ -0,0 +1,9 @@ +terraform { + backend "remote" { + organization = "notejam" + + workspaces { + name = "nordcloud-nodejam" + } + } +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-acr.tf b/terraform/notejam-tf/resource-acr.tf new file mode 100644 index 000000000..885bfacb0 --- /dev/null +++ b/terraform/notejam-tf/resource-acr.tf @@ -0,0 +1,20 @@ +//NodeJam container registry +resource "azurerm_container_registry" "acr-nodejan" { + name = var.nodejan_acr["name"] + resource_group_name = var.nodejan_acr["resource_group_name"] + location = var.location + sku = var.nodejan_acr["sku"] + admin_enabled = var.nodejan_acr_admin_enabled + tags = { + environment = "nordcloud" + } + +} + +# add the role to the identity the kubernetes cluster was assigned +resource "azurerm_role_assignment" "acr-nodejan" { + scope = azurerm_container_registry.acr-nodejan.id + role_definition_name = "AcrPull" + principal_id = module.app-cluster.principal_id +} + diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 0c947f7d5..9e624adc6 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com module "app-cluster" { source = "../modules/azure/aks" location = var.location diff --git a/terraform/notejam-tf/resource-database.tf b/terraform/notejam-tf/resource-database.tf index cfbdbe1c8..9ac69d775 100644 --- a/terraform/notejam-tf/resource-database.tf +++ b/terraform/notejam-tf/resource-database.tf @@ -1,7 +1,8 @@ +//Suresh Thomas suresh.thomas@yahoo.com module "app-db" { - source = "../modules/azure/database" - database_name = var.database_name + source = "../modules/azure/database" + database_name = var.database_name db_resource_group_name = var.db_resource_group_name db_server_name = var.db_server_name - depends_on = [module.app-datbase-server] + depends_on = [module.app-datbase-server] } \ No newline at end of file diff --git a/terraform/notejam-tf/resource-db-server.tf b/terraform/notejam-tf/resource-db-server.tf index 7418851ab..e83e84c9b 100644 --- a/terraform/notejam-tf/resource-db-server.tf +++ b/terraform/notejam-tf/resource-db-server.tf @@ -1,3 +1,4 @@ +//Suresh Thomas suresh.thomas@yahoo.com module "app-datbase-server" { source = "../modules/azure/db_server" db_server_name = var.db_server_name @@ -8,5 +9,9 @@ module "app-datbase-server" { db_version = var.db_version resource_group_name = var.db_resource_group_name location = var.location + + #public_network_access_enabled = var.dbproperties["public_network_access_enabled"] + # ssl_enforcement_enabled = var.dbproperties["ssl_enforcement_enabled"] + #ssl_minimal_tls_version_enforced = var.dbproperties["ssl_minimal_tls_version_enforced"] } diff --git a/terraform/notejam-tf/resource-rg.tf b/terraform/notejam-tf/resource-rg.tf index 1c92c4258..adc889be8 100644 --- a/terraform/notejam-tf/resource-rg.tf +++ b/terraform/notejam-tf/resource-rg.tf @@ -1,16 +1,18 @@ -// Hub is where Hub-networks stays - - +//Suresh Thomas suresh.thomas@yahoo.com // Spoke is where AKS stays resource "azurerm_resource_group" "rg_hub" { name = var.vnet-hub["vnet_resourcegroup"] location = var.location } - - // Spoke is where AKS stays resource "azurerm_resource_group" "rg_spoke" { name = var.cluster["app_resourcegroup"] location = var.location } + +// Spoke is where AKS stays +resource "azurerm_resource_group" "rg_acr" { + name = var.nodejan_acr["resource_group_name"] + location = var.location +} diff --git a/terraform/notejam-tf/resource-vnet.tf b/terraform/notejam-tf/resource-vnet.tf index e69de29bb..6d807976d 100644 --- a/terraform/notejam-tf/resource-vnet.tf +++ b/terraform/notejam-tf/resource-vnet.tf @@ -0,0 +1 @@ +//Suresh Thomas suresh.thomas@yahoo.com \ No newline at end of file diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index 165167cfd..94ad87524 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,7 +1,8 @@ - -location = "East US" -client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" -client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" +//Suresh Thomas suresh.thomas@yahoo.com +location = "East US" +standby_location = "West Europe" +client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" +client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" //Spoke cluster = { app_name = "aks-notejam" @@ -35,8 +36,17 @@ dbproperties = { geo_redundant_backup_enabled = false infrastructure_encryption_enabled = false public_network_access_enabled = true - ssl_enforcement_enabled = true + ssl_enforcement_enabled = false ssl_minimal_tls_version_enforced = "TLS1_2" +} +//Related to ACR +nodejan_acr = { + name = "acrnoedjam" + resource_group_name = "rg-acr" + sku = "Standard" } + +nodejan_acr_admin_enabled = false + diff --git a/terraform/notejam-tf/terraform.tfstate b/terraform/notejam-tf/terraform.tfstate index 268cd7717..b93bad124 100644 --- a/terraform/notejam-tf/terraform.tfstate +++ b/terraform/notejam-tf/terraform.tfstate @@ -1,8 +1,8 @@ { "version": 4, "terraform_version": "0.13.5", - "serial": 19, - "lineage": "e349672b-937a-9816-1456-3541ca27b938", + "serial": 17, + "lineage": "0ef84003-a3ed-648d-b7a8-27b717fdbf3c", "outputs": {}, "resources": [] } diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf index 73480b5c0..793b4c5ed 100644 --- a/terraform/notejam-tf/variables.tf +++ b/terraform/notejam-tf/variables.tf @@ -1,7 +1,14 @@ - +//Suresh Thomas suresh.thomas@yahoo.com +// General variables variable "location" { type = string } + +variable "standby_location" { + type = string +} + + variable "client_id" { type = string } @@ -25,32 +32,23 @@ variable "vnet-hub" { } } - - +// These variables are related to DB variable db_server_name { type = string } - variable database_name { type = string } - - variable administrator_login { type = string } - variable administrator_login_password { type = string - } variable db_resource_group_name { type = string default = "rg-notejam-db" } - - - variable sku_name { type = string } @@ -59,14 +57,11 @@ variable storage_mb { type = number default = 5120 } - variable db_version { type = string default = 5.7 } - - - +//SQl specific database variable "dbproperties" { type = map default = { @@ -75,12 +70,28 @@ variable "dbproperties" { geo_redundant_backup_enabled = false infrastructure_encryption_enabled = false public_network_access_enabled = true - ssl_enforcement_enabled = true + ssl_enforcement_enabled = false ssl_minimal_tls_version_enforced = "TLS1_2" + + } } +//Related to ACR +variable "nodejan_acr" { + type = map + default = { + name = "acrnoedjam" + resource_group_name = "rg-acr" + sku = "Standard" + } +} +variable nodejan_acr_admin_enabled { + type = bool + default = false +} + \ No newline at end of file From 97d810de66a1ace6fdc9cfb863fb00b7fdd23bc9 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 12 Mar 2021 20:45:59 +0000 Subject: [PATCH 04/44] Terraform modified --- .../{modules/azure => notejam-tf/azure_modules}/aks/k8.tf | 0 .../azure => notejam-tf/azure_modules}/aks/main.tf | 0 .../azure => notejam-tf/azure_modules}/aks/output.tf | 0 .../azure => notejam-tf/azure_modules}/aks/variable.tf | 0 .../azure => notejam-tf/azure_modules}/aks/versions.tf | 0 .../azure => notejam-tf/azure_modules}/database/main.tf | 0 .../azure_modules}/database/variable.tf | 0 .../azure_modules}/database/versions.tf | 0 .../azure => notejam-tf/azure_modules}/db_server/main.tf | 0 .../azure_modules}/db_server/variable.tf | 0 .../azure_modules}/db_server/versions.tf | 0 terraform/notejam-tf/provider.tf | 2 +- terraform/notejam-tf/resource-app-cluster.tf | 2 +- terraform/notejam-tf/resource-database.tf | 2 +- terraform/notejam-tf/resource-db-server.tf | 2 +- terraform/notejam-tf/terraform.tfstate | 8 -------- 16 files changed, 4 insertions(+), 12 deletions(-) rename terraform/{modules/azure => notejam-tf/azure_modules}/aks/k8.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/aks/main.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/aks/output.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/aks/variable.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/aks/versions.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/database/main.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/database/variable.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/database/versions.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/db_server/main.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/db_server/variable.tf (100%) rename terraform/{modules/azure => notejam-tf/azure_modules}/db_server/versions.tf (100%) delete mode 100644 terraform/notejam-tf/terraform.tfstate diff --git a/terraform/modules/azure/aks/k8.tf b/terraform/notejam-tf/azure_modules/aks/k8.tf similarity index 100% rename from terraform/modules/azure/aks/k8.tf rename to terraform/notejam-tf/azure_modules/aks/k8.tf diff --git a/terraform/modules/azure/aks/main.tf b/terraform/notejam-tf/azure_modules/aks/main.tf similarity index 100% rename from terraform/modules/azure/aks/main.tf rename to terraform/notejam-tf/azure_modules/aks/main.tf diff --git a/terraform/modules/azure/aks/output.tf b/terraform/notejam-tf/azure_modules/aks/output.tf similarity index 100% rename from terraform/modules/azure/aks/output.tf rename to terraform/notejam-tf/azure_modules/aks/output.tf diff --git a/terraform/modules/azure/aks/variable.tf b/terraform/notejam-tf/azure_modules/aks/variable.tf similarity index 100% rename from terraform/modules/azure/aks/variable.tf rename to terraform/notejam-tf/azure_modules/aks/variable.tf diff --git a/terraform/modules/azure/aks/versions.tf b/terraform/notejam-tf/azure_modules/aks/versions.tf similarity index 100% rename from terraform/modules/azure/aks/versions.tf rename to terraform/notejam-tf/azure_modules/aks/versions.tf diff --git a/terraform/modules/azure/database/main.tf b/terraform/notejam-tf/azure_modules/database/main.tf similarity index 100% rename from terraform/modules/azure/database/main.tf rename to terraform/notejam-tf/azure_modules/database/main.tf diff --git a/terraform/modules/azure/database/variable.tf b/terraform/notejam-tf/azure_modules/database/variable.tf similarity index 100% rename from terraform/modules/azure/database/variable.tf rename to terraform/notejam-tf/azure_modules/database/variable.tf diff --git a/terraform/modules/azure/database/versions.tf b/terraform/notejam-tf/azure_modules/database/versions.tf similarity index 100% rename from terraform/modules/azure/database/versions.tf rename to terraform/notejam-tf/azure_modules/database/versions.tf diff --git a/terraform/modules/azure/db_server/main.tf b/terraform/notejam-tf/azure_modules/db_server/main.tf similarity index 100% rename from terraform/modules/azure/db_server/main.tf rename to terraform/notejam-tf/azure_modules/db_server/main.tf diff --git a/terraform/modules/azure/db_server/variable.tf b/terraform/notejam-tf/azure_modules/db_server/variable.tf similarity index 100% rename from terraform/modules/azure/db_server/variable.tf rename to terraform/notejam-tf/azure_modules/db_server/variable.tf diff --git a/terraform/modules/azure/db_server/versions.tf b/terraform/notejam-tf/azure_modules/db_server/versions.tf similarity index 100% rename from terraform/modules/azure/db_server/versions.tf rename to terraform/notejam-tf/azure_modules/db_server/versions.tf diff --git a/terraform/notejam-tf/provider.tf b/terraform/notejam-tf/provider.tf index 0119b8b2a..b662ca80a 100644 --- a/terraform/notejam-tf/provider.tf +++ b/terraform/notejam-tf/provider.tf @@ -8,4 +8,4 @@ terraform { } provider "azurerm" { features {} -} \ No newline at end of file +} diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 9e624adc6..726e02ebb 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -1,6 +1,6 @@ //Suresh Thomas suresh.thomas@yahoo.com module "app-cluster" { - source = "../modules/azure/aks" + source = "./azure_modules/aks" location = var.location resource_group_name = var.cluster["app_resourcegroup"] agent_count = 1 diff --git a/terraform/notejam-tf/resource-database.tf b/terraform/notejam-tf/resource-database.tf index 9ac69d775..9e837fa9c 100644 --- a/terraform/notejam-tf/resource-database.tf +++ b/terraform/notejam-tf/resource-database.tf @@ -1,6 +1,6 @@ //Suresh Thomas suresh.thomas@yahoo.com module "app-db" { - source = "../modules/azure/database" + source = "./azure_modules/database" database_name = var.database_name db_resource_group_name = var.db_resource_group_name db_server_name = var.db_server_name diff --git a/terraform/notejam-tf/resource-db-server.tf b/terraform/notejam-tf/resource-db-server.tf index e83e84c9b..8363110ff 100644 --- a/terraform/notejam-tf/resource-db-server.tf +++ b/terraform/notejam-tf/resource-db-server.tf @@ -1,6 +1,6 @@ //Suresh Thomas suresh.thomas@yahoo.com module "app-datbase-server" { - source = "../modules/azure/db_server" + source = "./azure_modules/db_server" db_server_name = var.db_server_name administrator_login = var.administrator_login administrator_login_password = var.administrator_login_password diff --git a/terraform/notejam-tf/terraform.tfstate b/terraform/notejam-tf/terraform.tfstate deleted file mode 100644 index b93bad124..000000000 --- a/terraform/notejam-tf/terraform.tfstate +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 4, - "terraform_version": "0.13.5", - "serial": 17, - "lineage": "0ef84003-a3ed-648d-b7a8-27b717fdbf3c", - "outputs": {}, - "resources": [] -} From 8f3d303b14acce4d0dd84914b322d6e3c634bf95 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 20:48:48 +0000 Subject: [PATCH 05/44] Create terraform.yml --- .github/workflows/terraform.yml | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .github/workflows/terraform.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 000000000..b0fc2dac8 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,91 @@ +# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file +# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run +# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events +# to the master branch, `terraform apply` will be executed. +# +# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform +# +# To use this workflow, you will need to complete the following setup steps. +# +# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined. +# Example `main.tf`: +# # The configuration for the `remote` backend. +# terraform { +# backend "remote" { +# # The name of your Terraform Cloud organization. +# organization = "example-organization" +# +# # The name of the Terraform Cloud workspace to store Terraform state files in. +# workspaces { +# name = "example-workspace" +# } +# } +# } +# +# # An example resource that does nothing. +# resource "null_resource" "example" { +# triggers = { +# value = "A example resource that does nothing!" +# } +# } +# +# +# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository. +# Documentation: +# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html +# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets +# +# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action. +# Example: +# - name: Setup Terraform +# uses: hashicorp/setup-terraform@v1 +# with: +# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + +name: 'Terraform' + +on: + push: + branches: + - master + pull_request: + +jobs: + terraform: + name: 'Terraform' + runs-on: ubuntu-latest + environment: production + + # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest + defaults: + run: + shell: bash + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v2 + + # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + run: terraform init + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + run: terraform fmt -check + + # Generates an execution plan for Terraform + - name: Terraform Plan + run: terraform plan + + # On push to master, build or change infrastructure according to Terraform configuration files + # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks + - name: Terraform Apply + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + run: terraform apply -auto-approve From 0c588a2861fc2b53db8f6efe4edd73393beb47fe Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:19:12 +0000 Subject: [PATCH 06/44] Update terraform.yml --- .github/workflows/terraform.yml | 53 ++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index b0fc2dac8..11cbdc556 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -42,17 +42,19 @@ # with: # cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} -name: 'Terraform' +name: 'NordCloud' -on: - push: - branches: - - master - pull_request: +on: + workflow_dispatch: + inputs: + createUpdateEnv: + description: 'Apply the env' + required: true + default: 'false' jobs: terraform: - name: 'Terraform' + name: 'notejam' runs-on: ubuntu-latest environment: production @@ -60,6 +62,7 @@ jobs: defaults: run: shell: bash + working-directory: "terraform/notejam-tf" steps: # Checkout the repository to the GitHub Actions runner @@ -79,13 +82,41 @@ jobs: # Checks that all Terraform configuration files adhere to a canonical format - name: Terraform Format run: terraform fmt -check + continue-on-error: true # Generates an execution plan for Terraform - name: Terraform Plan - run: terraform plan + id: plan + if: github.event_name == 'pull_request' + run: terraform plan -no-color + continue-on-error: false + + - uses: actions/github-script@0.9.0 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` +
Show Plan + \`\`\`${process.env.PLAN}\`\`\` +
+ *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 - # On push to master, build or change infrastructure according to Terraform configuration files - # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks - name: Terraform Apply - if: github.ref == 'refs/heads/master' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event.inputs.createUpdateEnv == 'true' run: terraform apply -auto-approve From ee11f0144034c01a4b5ad8ac2f73ebca66c5a803 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:30:00 +0000 Subject: [PATCH 07/44] Update terraform.yml --- .github/workflows/terraform.yml | 56 ++++----------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 11cbdc556..184f39891 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,47 +1,3 @@ -# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file -# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run -# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events -# to the master branch, `terraform apply` will be executed. -# -# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform -# -# To use this workflow, you will need to complete the following setup steps. -# -# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined. -# Example `main.tf`: -# # The configuration for the `remote` backend. -# terraform { -# backend "remote" { -# # The name of your Terraform Cloud organization. -# organization = "example-organization" -# -# # The name of the Terraform Cloud workspace to store Terraform state files in. -# workspaces { -# name = "example-workspace" -# } -# } -# } -# -# # An example resource that does nothing. -# resource "null_resource" "example" { -# triggers = { -# value = "A example resource that does nothing!" -# } -# } -# -# -# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository. -# Documentation: -# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html -# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets -# -# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action. -# Example: -# - name: Setup Terraform -# uses: hashicorp/setup-terraform@v1 -# with: -# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} - name: 'NordCloud' on: @@ -62,7 +18,7 @@ jobs: defaults: run: shell: bash - working-directory: "terraform/notejam-tf" + working-directory: "terraform/notejam-tf/" steps: # Checkout the repository to the GitHub Actions runner @@ -74,16 +30,16 @@ jobs: uses: hashicorp/setup-terraform@v1 with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + run: terraform fmt -check + continue-on-error: true # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init run: terraform init - # Checks that all Terraform configuration files adhere to a canonical format - - name: Terraform Format - run: terraform fmt -check - continue-on-error: true - # Generates an execution plan for Terraform - name: Terraform Plan id: plan From c37240046366563a2b356956e4946ed7bedc37c9 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:41:56 +0000 Subject: [PATCH 08/44] Update terraform.yml --- .github/workflows/terraform.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 184f39891..e69138c63 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -32,9 +32,9 @@ jobs: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} # Checks that all Terraform configuration files adhere to a canonical format - - name: Terraform Format - run: terraform fmt -check - continue-on-error: true + #- name: Terraform Format + # run: terraform fmt -check + # continue-on-error: true # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init From 0c24a9390391d3cda924b2556ae8e7370cb89c0c Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:44:47 +0000 Subject: [PATCH 09/44] Update terraform.yml --- .github/workflows/terraform.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e69138c63..184f39891 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -32,9 +32,9 @@ jobs: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} # Checks that all Terraform configuration files adhere to a canonical format - #- name: Terraform Format - # run: terraform fmt -check - # continue-on-error: true + - name: Terraform Format + run: terraform fmt -check + continue-on-error: true # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init From 7b230fffe028d7cdd6f83f55837a9271c36625fa Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:48:21 +0000 Subject: [PATCH 10/44] Update terraform.yml --- .github/workflows/terraform.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 184f39891..19ff8b940 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,16 +1,17 @@ name: 'NordCloud' on: - workflow_dispatch: - inputs: - createUpdateEnv: - description: 'Apply the env' - required: true - default: 'false' + push: + branches: + - master + paths: + - "**/*.tf" + - "**/*.yml" + - "**/*.sh" jobs: terraform: - name: 'notejam' + name: 'notejam-pr-apply' runs-on: ubuntu-latest environment: production @@ -33,11 +34,13 @@ jobs: # Checks that all Terraform configuration files adhere to a canonical format - name: Terraform Format + id: fmt run: terraform fmt -check continue-on-error: true # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init + id: init run: terraform init # Generates an execution plan for Terraform @@ -74,5 +77,5 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event.inputs.createUpdateEnv == 'true' + if: github.ref == 'refs/heads/main' && && github.event_name == 'push' run: terraform apply -auto-approve From ceee3ac7deea007f764db5f0052c8013eda81af9 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 12 Mar 2021 21:50:39 +0000 Subject: [PATCH 11/44] added main --- terraform/notejam-tf/main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/terraform/notejam-tf/main.tf b/terraform/notejam-tf/main.tf index 1b116fb7a..28613e5f9 100644 --- a/terraform/notejam-tf/main.tf +++ b/terraform/notejam-tf/main.tf @@ -6,4 +6,5 @@ terraform { name = "nordcloud-nodejam" } } -} \ No newline at end of file +} + From f1a4cb4fce74e52b8a0d785ce4466c94c4f38e41 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 21:52:27 +0000 Subject: [PATCH 12/44] Update terraform.yml --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 19ff8b940..8134079d2 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -77,5 +77,5 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.ref == 'refs/heads/main' && && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve From bf22528bdaddb392d1994baaf1fa6cc0daa09b09 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 22:58:37 +0000 Subject: [PATCH 13/44] Update terraform.yml --- .github/workflows/terraform.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 8134079d2..781f8c62a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -14,6 +14,12 @@ jobs: name: 'notejam-pr-apply' runs-on: ubuntu-latest environment: production + + env: + ARM_CLIENT_ID: ${{ secrets.TF_VAR_ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.TF_VAR_ARM_CLIENT_SECRET }} + ARM_SUBSCRIPTION_ID: ${{ secrets.TF_VAR_ARM_SUBSCRIPTION_ID }} + ARM_TENANT_ID: ${{ secrets.TF_VAR_ARM_TENANT_ID }} # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest defaults: From 296149aa14391399abce3e18b5dab599c4f08e89 Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Fri, 12 Mar 2021 23:13:19 +0000 Subject: [PATCH 14/44] Update terraform.yml --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 781f8c62a..4f8febe80 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -25,7 +25,7 @@ jobs: defaults: run: shell: bash - working-directory: "terraform/notejam-tf/" + working-directory: "terraform/notejam-tf" steps: # Checkout the repository to the GitHub Actions runner From 8f2bd13d071e82c8c5bb289d2d47360a45d291e3 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 12 Mar 2021 23:18:25 +0000 Subject: [PATCH 15/44] Added files --- terraform/notejam-tf/main.tf | 10 ---------- terraform/notejam-tf/terraform.auto.tfvars | 4 +--- terraform/notejam-tf/variables.tf | 7 ------- 3 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 terraform/notejam-tf/main.tf diff --git a/terraform/notejam-tf/main.tf b/terraform/notejam-tf/main.tf deleted file mode 100644 index 28613e5f9..000000000 --- a/terraform/notejam-tf/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -terraform { - backend "remote" { - organization = "notejam" - - workspaces { - name = "nordcloud-nodejam" - } - } -} - diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index 94ad87524..59a44fffb 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,9 +1,7 @@ //Suresh Thomas suresh.thomas@yahoo.com location = "East US" standby_location = "West Europe" -client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" -client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" -//Spoke + cluster = { app_name = "aks-notejam" app_resourcegroup = "rg-app" diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf index 793b4c5ed..4f5b9691d 100644 --- a/terraform/notejam-tf/variables.tf +++ b/terraform/notejam-tf/variables.tf @@ -8,13 +8,6 @@ variable "standby_location" { type = string } - -variable "client_id" { - type = string -} -variable "client_secret" { - type = string -} # Variables related to application deployment cluster variable "cluster" { type = map From 4ffd512ff8a99261fa277fca6e9f4b468ddcc55b Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 00:17:26 +0000 Subject: [PATCH 16/44] client secret removed --- terraform/notejam-tf/resource-app-cluster.tf | 2 -- terraform/notejam-tf/variables.tf | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 726e02ebb..76f53ef37 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -7,6 +7,4 @@ module "app-cluster" { dns_prefix = var.cluster["dns_prefix"] cluster_name = var.cluster["app_name"] log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] - client_id = var.client_id - client_secret = var.client_secret } \ No newline at end of file diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf index 4f5b9691d..cbee00a3d 100644 --- a/terraform/notejam-tf/variables.tf +++ b/terraform/notejam-tf/variables.tf @@ -8,6 +8,7 @@ variable "standby_location" { type = string } + # Variables related to application deployment cluster variable "cluster" { type = map From d4e23eba4ae36be99d97581475172c9de6cb8b32 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 13:51:56 +0000 Subject: [PATCH 17/44] IaC completed --- terraform/notejam-tf/azure_modules/aks/k8.tf | 14 +++++++++----- terraform/notejam-tf/azure_modules/aks/output.tf | 4 ---- .../notejam-tf/azure_modules/database/main.tf | 1 + .../notejam-tf/azure_modules/db_server/main.tf | 9 ++++++++- terraform/notejam-tf/resource-acr.tf | 11 +++++++++-- terraform/notejam-tf/resource-app-cluster.tf | 2 ++ terraform/notejam-tf/resource-rg.tf | 9 +++++++++ terraform/notejam-tf/resource-vnet.tf | 1 - terraform/notejam-tf/terraform.auto.tfvars | 3 +++ terraform/notejam-tf/variables.tf | 5 ++++- 10 files changed, 45 insertions(+), 14 deletions(-) delete mode 100644 terraform/notejam-tf/resource-vnet.tf diff --git a/terraform/notejam-tf/azure_modules/aks/k8.tf b/terraform/notejam-tf/azure_modules/aks/k8.tf index 3ea608d25..9d91c4c61 100644 --- a/terraform/notejam-tf/azure_modules/aks/k8.tf +++ b/terraform/notejam-tf/azure_modules/aks/k8.tf @@ -27,6 +27,7 @@ resource "azurerm_log_analytics_solution" "notejam" { } } //app +/* resource "azuread_application" "aks_sp" { display_name = "sp-aks-${var.cluster_name}" } @@ -58,7 +59,7 @@ resource "random_string" "aks_sp_password" { special = true min_special = 1 override_special = "!@-_=+." -} +}*/ resource "azurerm_kubernetes_cluster" "k8s" { name = var.cluster_name location = azurerm_resource_group.k8s.location @@ -79,10 +80,13 @@ resource "azurerm_kubernetes_cluster" "k8s" { vm_size = "Standard_D2_v2" } - service_principal { - client_id = azuread_service_principal.aks_sp.application_id - client_secret = random_string.aks_sp_password.result + + + service_principal { + client_id = var.client_id + client_secret = var.client_secret } + addon_profile { oms_agent { @@ -97,6 +101,6 @@ resource "azurerm_kubernetes_cluster" "k8s" { } tags = { - Environment = "Development" + environment = "nordcloud notejam test" } } \ No newline at end of file diff --git a/terraform/notejam-tf/azure_modules/aks/output.tf b/terraform/notejam-tf/azure_modules/aks/output.tf index 80c7f0824..e0df98e87 100644 --- a/terraform/notejam-tf/azure_modules/aks/output.tf +++ b/terraform/notejam-tf/azure_modules/aks/output.tf @@ -26,7 +26,3 @@ output "kube_config" { output "host" { value = azurerm_kubernetes_cluster.k8s.kube_config.0.host } - -output "principal_id" { - value = azuread_service_principal.aks_sp.application_id -} \ No newline at end of file diff --git a/terraform/notejam-tf/azure_modules/database/main.tf b/terraform/notejam-tf/azure_modules/database/main.tf index 192e449a0..c5a01bfaa 100644 --- a/terraform/notejam-tf/azure_modules/database/main.tf +++ b/terraform/notejam-tf/azure_modules/database/main.tf @@ -5,4 +5,5 @@ resource "azurerm_mysql_database" "db" { server_name = var.db_server_name charset = "utf8" collation = "utf8_unicode_ci" + } \ No newline at end of file diff --git a/terraform/notejam-tf/azure_modules/db_server/main.tf b/terraform/notejam-tf/azure_modules/db_server/main.tf index 7588891f1..06db2d704 100644 --- a/terraform/notejam-tf/azure_modules/db_server/main.tf +++ b/terraform/notejam-tf/azure_modules/db_server/main.tf @@ -2,6 +2,9 @@ resource "azurerm_resource_group" "rg_db" { name = var.resource_group_name location = var.location + tags = { + environment = "nordcloud notejam test" + } } resource "azurerm_mysql_server" "mysqlserver" { @@ -22,5 +25,9 @@ resource "azurerm_mysql_server" "mysqlserver" { infrastructure_encryption_enabled = var.dbproperties["infrastructure_encryption_enabled"] public_network_access_enabled = var.dbproperties["public_network_access_enabled"] ssl_enforcement_enabled = var.dbproperties["ssl_enforcement_enabled"] - ssl_minimal_tls_version_enforced = var.dbproperties["ssl_minimal_tls_version_enforced"] + #ssl_minimal_tls_version_enforced = var.dbproperties["ssl_minimal_tls_version_enforced"] + + tags = { + environment = "nordcloud notejam test" + } } \ No newline at end of file diff --git a/terraform/notejam-tf/resource-acr.tf b/terraform/notejam-tf/resource-acr.tf index 885bfacb0..c079faca4 100644 --- a/terraform/notejam-tf/resource-acr.tf +++ b/terraform/notejam-tf/resource-acr.tf @@ -1,4 +1,11 @@ //NodeJam container registry + + + +data "azuread_service_principal" "aks_principal" { + application_id = var.client_id +} + resource "azurerm_container_registry" "acr-nodejan" { name = var.nodejan_acr["name"] resource_group_name = var.nodejan_acr["resource_group_name"] @@ -6,7 +13,7 @@ resource "azurerm_container_registry" "acr-nodejan" { sku = var.nodejan_acr["sku"] admin_enabled = var.nodejan_acr_admin_enabled tags = { - environment = "nordcloud" + environment = "nordcloud notejam test" } } @@ -15,6 +22,6 @@ resource "azurerm_container_registry" "acr-nodejan" { resource "azurerm_role_assignment" "acr-nodejan" { scope = azurerm_container_registry.acr-nodejan.id role_definition_name = "AcrPull" - principal_id = module.app-cluster.principal_id + principal_id = data.azuread_service_principal.aks_principal.id } diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 76f53ef37..726e02ebb 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -7,4 +7,6 @@ module "app-cluster" { dns_prefix = var.cluster["dns_prefix"] cluster_name = var.cluster["app_name"] log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] + client_id = var.client_id + client_secret = var.client_secret } \ No newline at end of file diff --git a/terraform/notejam-tf/resource-rg.tf b/terraform/notejam-tf/resource-rg.tf index adc889be8..f8f9012a4 100644 --- a/terraform/notejam-tf/resource-rg.tf +++ b/terraform/notejam-tf/resource-rg.tf @@ -3,16 +3,25 @@ resource "azurerm_resource_group" "rg_hub" { name = var.vnet-hub["vnet_resourcegroup"] location = var.location + tags = { + environment = "nordcloud notejam test" + } } // Spoke is where AKS stays resource "azurerm_resource_group" "rg_spoke" { name = var.cluster["app_resourcegroup"] location = var.location + tags = { + environment = "nordcloud notejam test" + } } // Spoke is where AKS stays resource "azurerm_resource_group" "rg_acr" { name = var.nodejan_acr["resource_group_name"] location = var.location + tags = { + environment = "nordcloud notejam test" + } } diff --git a/terraform/notejam-tf/resource-vnet.tf b/terraform/notejam-tf/resource-vnet.tf deleted file mode 100644 index 6d807976d..000000000 --- a/terraform/notejam-tf/resource-vnet.tf +++ /dev/null @@ -1 +0,0 @@ -//Suresh Thomas suresh.thomas@yahoo.com \ No newline at end of file diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index 59a44fffb..b960a8fcc 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,3 +1,6 @@ +client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" +client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" + //Suresh Thomas suresh.thomas@yahoo.com location = "East US" standby_location = "West Europe" diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf index cbee00a3d..92863b1ae 100644 --- a/terraform/notejam-tf/variables.tf +++ b/terraform/notejam-tf/variables.tf @@ -8,7 +8,10 @@ variable "standby_location" { type = string } - + +variable "client_id" {} +variable "client_secret" {} + # Variables related to application deployment cluster variable "cluster" { type = map From 8497ef8653c91ed94dad0dab759c183d9bcfb2ce Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:57:10 +0000 Subject: [PATCH 18/44] Update terraform.auto.tfvars --- terraform/notejam-tf/terraform.auto.tfvars | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index 94ad87524..b8ec94a94 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,8 +1,8 @@ //Suresh Thomas suresh.thomas@yahoo.com location = "East US" standby_location = "West Europe" -client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" -client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" +client_id = "" +client_secret = "" //Spoke cluster = { app_name = "aks-notejam" From 443fed3f1d6cf9339a824afc57176806de2a047a Mon Sep 17 00:00:00 2001 From: Suresh Thomas <67327008+st185229@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:57:33 +0000 Subject: [PATCH 19/44] Update terraform.auto.tfvars --- terraform/notejam-tf/terraform.auto.tfvars | 2 -- 1 file changed, 2 deletions(-) diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index b8ec94a94..025622e48 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,8 +1,6 @@ //Suresh Thomas suresh.thomas@yahoo.com location = "East US" standby_location = "West Europe" -client_id = "" -client_secret = "" //Spoke cluster = { app_name = "aks-notejam" From 2a4d63db3a1671ef96fd4c89d173aea8402eafd1 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 13:58:41 +0000 Subject: [PATCH 20/44] IaC completed --- terraform/notejam-tf/terraform.auto.tfvars | 2 -- 1 file changed, 2 deletions(-) diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index b960a8fcc..6bc586122 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -1,5 +1,3 @@ -client_id = "80684b5b-8d63-4191-bb79-76ebe0a08f84" -client_secret = "PUD8cvslf-jRUeNAQ9p_mHvSsxz5465k5_" //Suresh Thomas suresh.thomas@yahoo.com location = "East US" From bfb12b6f047a0a64dcf745b1049dae5ccd71d666 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 14:19:50 +0000 Subject: [PATCH 21/44] IaC completed --- terraform/notejam-tf/provider.tf | 3 +++ terraform/notejam-tf/resource-app-cluster.tf | 2 ++ 2 files changed, 5 insertions(+) diff --git a/terraform/notejam-tf/provider.tf b/terraform/notejam-tf/provider.tf index b662ca80a..bbd00a2b3 100644 --- a/terraform/notejam-tf/provider.tf +++ b/terraform/notejam-tf/provider.tf @@ -8,4 +8,7 @@ terraform { } provider "azurerm" { features {} + + subscription_id = "81432554-220c-405f-9b16-8c1ef66ecfe5" + tenant_id = "614a2ce2-e1f9-4ce4-824e-0ec9bd92cb65" } diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 726e02ebb..194109312 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -9,4 +9,6 @@ module "app-cluster" { log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] client_id = var.client_id client_secret = var.client_secret + ssh_public_key = "${file("keys/cloud-init-jenkins.txt")}" + } \ No newline at end of file From f1830499c70e1fe6258b44b0936b4da8664c0f36 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 14:22:36 +0000 Subject: [PATCH 22/44] Added files --- terraform/notejam-tf/azure_key.pub | 1 + .../notejam-tf/azure_modules/aks/provider.tf | 3 + terraform/notejam-tf/cloud-init-jenkins.txt | 22 +++ .../notejam-tf/resource-jenkins-bastian.tf | 134 ++++++++++++++++++ .../notejam-tf/resource-security-ddos.tf | 10 ++ .../resource-security-firewall-nsg.tf | 49 +++++++ .../notejam-tf/resource-sub-spoke-peering.tf | 25 ++++ terraform/notejam-tf/resource-vnet-hub.tf | 47 ++++++ terraform/notejam-tf/resource-vnet-spoke.tf | 47 ++++++ 9 files changed, 338 insertions(+) create mode 100644 terraform/notejam-tf/azure_key.pub create mode 100644 terraform/notejam-tf/azure_modules/aks/provider.tf create mode 100644 terraform/notejam-tf/cloud-init-jenkins.txt create mode 100644 terraform/notejam-tf/resource-jenkins-bastian.tf create mode 100644 terraform/notejam-tf/resource-security-ddos.tf create mode 100644 terraform/notejam-tf/resource-security-firewall-nsg.tf create mode 100644 terraform/notejam-tf/resource-sub-spoke-peering.tf create mode 100644 terraform/notejam-tf/resource-vnet-hub.tf create mode 100644 terraform/notejam-tf/resource-vnet-spoke.tf diff --git a/terraform/notejam-tf/azure_key.pub b/terraform/notejam-tf/azure_key.pub new file mode 100644 index 000000000..e827756a5 --- /dev/null +++ b/terraform/notejam-tf/azure_key.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3qIAICP03Egq8bt8GT+pht4bzmhQNtGW/43O+SPCdgATR8PSxPkH4+GJZ9Oj/Qi9m6L2KVpJfV4L6N5Kx7qdV7hHKUvDB8mjJ3ffdx7Q3weo3i/36P3W/fy/XmrpHF8+URFkxvQUTZ+NQA89yjHEVFuhlN5keaw4+Jeku5OYbS1bACDgi6NcOIBW7akWb/uzWXMKyJznfV4C0R/NUZ5J6ZykSk5w+JKOmJTl4jOLyY5WX39s3xzocQaKE+KOQPwfAxQ7i+qYQodWKqyh3Pa+EsyYM6C5Ek1zJ0KbWvrJJv1wxkeQmx3YUowxeECZQhbRkP8sHEqB9YsbP7CMdIy2r corp\st185229@WUKST185229-4KJ \ No newline at end of file diff --git a/terraform/notejam-tf/azure_modules/aks/provider.tf b/terraform/notejam-tf/azure_modules/aks/provider.tf new file mode 100644 index 000000000..283b6125c --- /dev/null +++ b/terraform/notejam-tf/azure_modules/aks/provider.tf @@ -0,0 +1,3 @@ +provider "azuread" { + version = "~>0.7" +} \ No newline at end of file diff --git a/terraform/notejam-tf/cloud-init-jenkins.txt b/terraform/notejam-tf/cloud-init-jenkins.txt new file mode 100644 index 000000000..3c5a44c19 --- /dev/null +++ b/terraform/notejam-tf/cloud-init-jenkins.txt @@ -0,0 +1,22 @@ +#cloud-config +package_upgrade: true +write_files: + - path: /etc/systemd/system/docker.service.d/docker.conf + content: | + [Service] + ExecStart= + ExecStart=/usr/bin/dockerd + - path: /etc/docker/daemon.json + content: | + { + "hosts": ["fd://","tcp://127.0.0.1:2375"] + } +runcmd: + - apt install openjdk-8-jre-headless -y + - wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add - + - sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' + - apt-get update && apt-get install jenkins -y + - curl -sSL https://get.docker.com/ | sh + - usermod -aG docker azureuser + - usermod -aG docker jenkins + - service jenkins restart \ No newline at end of file diff --git a/terraform/notejam-tf/resource-jenkins-bastian.tf b/terraform/notejam-tf/resource-jenkins-bastian.tf new file mode 100644 index 000000000..7deffa551 --- /dev/null +++ b/terraform/notejam-tf/resource-jenkins-bastian.tf @@ -0,0 +1,134 @@ + +//Take from hub resource group +data "azurerm_resource_group" "rg_hub" { + name = var.vnet-hub["vnet_resourcegroup"] + depends_on = [azurerm_resource_group.rg_hub] + +} + +# refer hub vnet + +/*data "azurerm_virtual_network" "hub_vnet" { + name = "hubVirtualNetwork" + depends_on = [azurerm_resource_group.rg_hub] +}*/ + +# refer bastin-jenkins subnet +data "azurerm_subnet" "bastian-subnet" { + name = "hub_bastian" + virtual_network_name = data.azurerm_virtual_network.hub_vnet.name + resource_group_name = data.azurerm_resource_group.rg_hub.name + depends_on = [azurerm_virtual_network.hub_vnet] +} + + +# Create public IPs +resource "azurerm_public_ip" "bastian_public_ip" { + name = "bastianPubIP" + location = var.location + resource_group_name = data.azurerm_resource_group.rg_hub.name + allocation_method = "Dynamic" + + tags = { + environment = "nordcloud notejam test" + } +} + +# Create network interface +resource "azurerm_network_interface" "bastian_nic" { + name = "bastianNIC" + location = var.location + resource_group_name = data.azurerm_resource_group.rg_hub.name + + ip_configuration { + name = "bastianNICConfiguration" + subnet_id = data.azurerm_subnet.bastian-subnet.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.bastian_public_ip.id + } + + tags = { + environment = "nordcloud notejam test" + } +} + +# Connect the security group to the network interface +resource "azurerm_network_interface_security_group_association" "nsg_associate" { + network_interface_id = azurerm_network_interface.bastian_nic.id + network_security_group_id = azurerm_network_security_group.ssh-80-8080.id +} + +# Generate random text for a unique storage account name +resource "random_id" "randomId" { + keepers = { + # Generate a new ID only when a new resource group is defined + resource_group = data.azurerm_resource_group.rg_hub.name + } + + byte_length = 8 +} + +# Create storage account for boot diagnostics +resource "azurerm_storage_account" "nordcloudstorageaccount" { + name = "diag${random_id.randomId.hex}" + resource_group_name = data.azurerm_resource_group.rg_hub.name + location = var.location + account_tier = "Standard" + account_replication_type = "LRS" + + tags = { + environment = "nordcloud notejam test" + } +} + +# Create (and display) an SSH key +resource "tls_private_key" "bastian_ssh" { + algorithm = "RSA" + rsa_bits = 4096 +} +output "tls_private_key" { value = tls_private_key.bastian_ssh.private_key_pem } + +# Create virtual machine +resource "azurerm_linux_virtual_machine" "bastian_jenkins_vm" { + name = "bastjenknc" + location = var.location + resource_group_name = data.azurerm_resource_group.rg_hub.name + network_interface_ids = [azurerm_network_interface.bastian_nic.id] + size = "Standard_DS1_v2" + + + #custom_data = ${filebase64(${file("cloud-init-jenkins.txt")}) + + custom_data = "${filebase64("cloud-init-jenkins.txt")}" + + + os_disk { + name = "norddisk" + caching = "ReadWrite" + storage_account_type = "Premium_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } + + computer_name = "bastjenknc" + admin_username = "azureuser" + disable_password_authentication = true + + admin_ssh_key { + username = "azureuser" + public_key = tls_private_key.bastian_ssh.public_key_openssh + } + + boot_diagnostics { + storage_account_uri = azurerm_storage_account.nordcloudstorageaccount.primary_blob_endpoint + } + + tags = { + environment = "nordcloud notejam test" + } +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf new file mode 100644 index 000000000..d52f18ef9 --- /dev/null +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -0,0 +1,10 @@ +resource "azurerm_network_ddos_protection_plan" "notejamprotect" { + name = "nordddosprotect" + location = data.azurerm_resource_group.app_rg.location + resource_group_name = data.azurerm_resource_group.app_rg.name + tags = { + environment = "nordcloud notejam test" + } +} + + \ No newline at end of file diff --git a/terraform/notejam-tf/resource-security-firewall-nsg.tf b/terraform/notejam-tf/resource-security-firewall-nsg.tf new file mode 100644 index 000000000..d21259c83 --- /dev/null +++ b/terraform/notejam-tf/resource-security-firewall-nsg.tf @@ -0,0 +1,49 @@ +# Create Network Security Group and rule +resource "azurerm_network_security_group" "ssh-80-8080" { + name = "bastian-jenkins-sg" + location = var.location + resource_group_name = data.azurerm_resource_group.rg_hub.name + + security_rule { + name = "SSH" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" + } + + tags = { + environment = "nordcloud notejam test" + } +} + +resource "azurerm_network_security_rule" "allow8080" { + name = "HTTP_8080" + priority = 1002 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "8080" + source_address_prefix = "*" + destination_address_prefix = "*" + resource_group_name = data.azurerm_resource_group.rg_hub.name + network_security_group_name = azurerm_network_security_group.ssh-80-8080.name +} +resource "azurerm_network_security_rule" "allow80" { + name = "HTTP_80" + priority = 1003 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "80" + source_address_prefix = "*" + destination_address_prefix = "*" + resource_group_name = data.azurerm_resource_group.rg_hub.name + network_security_group_name = azurerm_network_security_group.ssh-80-8080.name +} diff --git a/terraform/notejam-tf/resource-sub-spoke-peering.tf b/terraform/notejam-tf/resource-sub-spoke-peering.tf new file mode 100644 index 000000000..c15eb8305 --- /dev/null +++ b/terraform/notejam-tf/resource-sub-spoke-peering.tf @@ -0,0 +1,25 @@ +data "azurerm_virtual_network" "hub_vnet" { + name = "hubVirtualNetwork" + resource_group_name = data.azurerm_resource_group.hub_rg.name + depends_on = [azurerm_virtual_network.hub_vnet] + +} +data "azurerm_virtual_network" "app_vnet" { + name = "spokeVirtualNetwork" + resource_group_name = data.azurerm_resource_group.app_rg.name + depends_on = [azurerm_virtual_network.app_vnet] +} +resource "azurerm_virtual_network_peering" "HubToSpoke1" { + name = "peerHtoS" + resource_group_name = var.vnet-hub["vnet_resourcegroup"] + virtual_network_name = data.azurerm_virtual_network.hub_vnet.name + remote_virtual_network_id = data.azurerm_virtual_network.app_vnet.id + +} +resource "azurerm_virtual_network_peering" "Spoke1ToHub" { + name = "peerStoH" + resource_group_name = var.vnet-hub["vnet_resourcegroup"] + virtual_network_name = data.azurerm_virtual_network.app_vnet.name + remote_virtual_network_id = data.azurerm_virtual_network.hub_vnet.id +} + diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf new file mode 100644 index 000000000..c0181c8b0 --- /dev/null +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -0,0 +1,47 @@ + + +# Get Resources from a Resource Group +data "azurerm_resource_group" "hub_rg" { + name = var.vnet-hub["vnet_resourcegroup"] + + depends_on = [azurerm_resource_group.rg_hub] +} + + +resource "azurerm_network_security_group" "hub_nsg" { + name = "hubSecurityGroup" + location = data.azurerm_resource_group.hub_rg.location + resource_group_name = data.azurerm_resource_group.hub_rg.name + tags = { + environment = "nordcloud notejam test" + } +} + + +resource "azurerm_virtual_network" "hub_vnet" { + name = "hubVirtualNetwork" + location = data.azurerm_resource_group.hub_rg.location + resource_group_name = data.azurerm_resource_group.hub_rg.name + address_space = ["10.0.0.0/22"] + #dns_servers = ["10.0.0.4", "10.0.0.5"] + depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] + + ddos_protection_plan { + id = azurerm_network_ddos_protection_plan.notejamprotect.id + enable = true + } + + subnet { + name = "hub_subnet_fwall" + address_prefix = "10.0.0.0/24" + } + + subnet { + name = "hub_bastian" + address_prefix = "10.0.1.0/24" + } + + tags = { + environment = "nordcloud notejam test" + } +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf new file mode 100644 index 000000000..f0f1886dd --- /dev/null +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -0,0 +1,47 @@ + + +# Get Resources from a Resource Group +data "azurerm_resource_group" "app_rg" { + name = var.cluster["app_resourcegroup"] + depends_on = [azurerm_resource_group.rg_spoke] +} + +resource "azurerm_network_security_group" "app_nsg" { + name = "appSecurityGroup" + location = data.azurerm_resource_group.app_rg.location + resource_group_name = data.azurerm_resource_group.app_rg.name + tags = { + environment = "nordcloud notejam test" + } +} + + + +resource "azurerm_virtual_network" "app_vnet" { + name = "spokeVirtualNetwork" + location = data.azurerm_resource_group.app_rg.location + resource_group_name = data.azurerm_resource_group.app_rg.name + address_space = ["10.0.0.0/22"] + #dns_servers = ["10.0.0.4", "10.0.0.5"] + depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] + + ddos_protection_plan { + id = azurerm_network_ddos_protection_plan.notejamprotect.id + enable = true + } + + subnet { + name = "ingress_subnet" + address_prefix = "10.0.4.0/24" + } + + subnet { + name = "kube_node_subnet" + address_prefix = "10.0.5.0/24" + } + + tags = { + environment = "nordcloud notejam test" + } + +} \ No newline at end of file From f3c1500f34f0bdfa931bf42f472d4267517c50f8 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 14:25:08 +0000 Subject: [PATCH 23/44] Added files --- terraform/notejam-tf/resource-app-cluster.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 194109312..241d787bc 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -9,6 +9,6 @@ module "app-cluster" { log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] client_id = var.client_id client_secret = var.client_secret - ssh_public_key = "${file("keys/cloud-init-jenkins.txt")}" + ssh_public_key = "${file("azure_key.pub")}" } \ No newline at end of file From a9ff855861a6b5e04ada3fbc4e14937819dd8d91 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 14:26:57 +0000 Subject: [PATCH 24/44] Added files --- terraform/notejam-tf/resource-app-cluster.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/notejam-tf/resource-app-cluster.tf b/terraform/notejam-tf/resource-app-cluster.tf index 241d787bc..ecdcb6f88 100644 --- a/terraform/notejam-tf/resource-app-cluster.tf +++ b/terraform/notejam-tf/resource-app-cluster.tf @@ -9,6 +9,6 @@ module "app-cluster" { log_analytics_workspace_name = var.cluster["log_analytics_workspace_name"] client_id = var.client_id client_secret = var.client_secret - ssh_public_key = "${file("azure_key.pub")}" + ssh_public_key = "azure_key.pub" } \ No newline at end of file From 09a93f36dcd20b171489df7007161094f3a3cbdd Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 14:38:23 +0000 Subject: [PATCH 25/44] Github actions updated --- .github/workflows/terraform.yml | 108 +++++++++++++++----------------- 1 file changed, 52 insertions(+), 56 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index b0fc2dac8..07d996338 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,65 +1,31 @@ -# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file -# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run -# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events -# to the master branch, `terraform apply` will be executed. -# -# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform -# -# To use this workflow, you will need to complete the following setup steps. -# -# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined. -# Example `main.tf`: -# # The configuration for the `remote` backend. -# terraform { -# backend "remote" { -# # The name of your Terraform Cloud organization. -# organization = "example-organization" -# -# # The name of the Terraform Cloud workspace to store Terraform state files in. -# workspaces { -# name = "example-workspace" -# } -# } -# } -# -# # An example resource that does nothing. -# resource "null_resource" "example" { -# triggers = { -# value = "A example resource that does nothing!" -# } -# } -# -# -# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository. -# Documentation: -# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html -# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets -# -# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action. -# Example: -# - name: Setup Terraform -# uses: hashicorp/setup-terraform@v1 -# with: -# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} +name: 'NordCloud' -name: 'Terraform' - -on: +on: push: branches: - master - pull_request: + paths: + - "**/*.tf" + - "**/*.yml" + - "**/*.sh" jobs: terraform: - name: 'Terraform' + name: 'notejam-pr-apply' runs-on: ubuntu-latest environment: production + + env: + ARM_CLIENT_ID: ${{ secrets.TF_VAR_ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.TF_VAR_ARM_CLIENT_SECRET }} + ARM_SUBSCRIPTION_ID: ${{ secrets.TF_VAR_ARM_SUBSCRIPTION_ID }} + ARM_TENANT_ID: ${{ secrets.TF_VAR_ARM_TENANT_ID }} # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest defaults: run: shell: bash + working-directory: "terraform/notejam-tf" steps: # Checkout the repository to the GitHub Actions runner @@ -71,21 +37,51 @@ jobs: uses: hashicorp/setup-terraform@v1 with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + id: fmt + run: terraform fmt -check + continue-on-error: true # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init + id: init run: terraform init - # Checks that all Terraform configuration files adhere to a canonical format - - name: Terraform Format - run: terraform fmt -check - # Generates an execution plan for Terraform - name: Terraform Plan - run: terraform plan + id: plan + #if: github.event_name == 'pull_request' + run: terraform plan -no-color + continue-on-error: false + + - uses: actions/github-script@0.9.0 + #if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` +
Show Plan + \`\`\`${process.env.PLAN}\`\`\` +
+ *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 - # On push to master, build or change infrastructure according to Terraform configuration files - # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks - name: Terraform Apply - if: github.ref == 'refs/heads/master' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve From 7f6a33928655a2a894400d8de32f967d41c99d4f Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 17:10:37 +0000 Subject: [PATCH 26/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-jenkins-bastian.tf | 4 ++-- terraform/notejam-tf/resource-security-ddos.tf | 5 ++++- terraform/notejam-tf/resource-vnet-hub.tf | 5 +++-- terraform/notejam-tf/resource-vnet-spoke.tf | 3 +++ terraform/notejam-tf/terraform.auto.tfvars | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/terraform/notejam-tf/resource-jenkins-bastian.tf b/terraform/notejam-tf/resource-jenkins-bastian.tf index 7deffa551..622709e52 100644 --- a/terraform/notejam-tf/resource-jenkins-bastian.tf +++ b/terraform/notejam-tf/resource-jenkins-bastian.tf @@ -94,7 +94,7 @@ resource "azurerm_linux_virtual_machine" "bastian_jenkins_vm" { location = var.location resource_group_name = data.azurerm_resource_group.rg_hub.name network_interface_ids = [azurerm_network_interface.bastian_nic.id] - size = "Standard_DS1_v2" + size = "Standard_A2_v2" #custom_data = ${filebase64(${file("cloud-init-jenkins.txt")}) @@ -105,7 +105,7 @@ resource "azurerm_linux_virtual_machine" "bastian_jenkins_vm" { os_disk { name = "norddisk" caching = "ReadWrite" - storage_account_type = "Premium_LRS" + storage_account_type = "Standard_LRS" } source_image_reference { diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf index d52f18ef9..7f2e7440f 100644 --- a/terraform/notejam-tf/resource-security-ddos.tf +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -1,3 +1,6 @@ +//Total monthly bill for DDoS Standard will be £2,194/month +// So keeping this commended +/* resource "azurerm_network_ddos_protection_plan" "notejamprotect" { name = "nordddosprotect" location = data.azurerm_resource_group.app_rg.location @@ -6,5 +9,5 @@ resource "azurerm_network_ddos_protection_plan" "notejamprotect" { environment = "nordcloud notejam test" } } - +*/ \ No newline at end of file diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf index c0181c8b0..b1bffdd89 100644 --- a/terraform/notejam-tf/resource-vnet-hub.tf +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -26,10 +26,11 @@ resource "azurerm_virtual_network" "hub_vnet" { #dns_servers = ["10.0.0.4", "10.0.0.5"] depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] - ddos_protection_plan { + //Working code but commended due to cost + /*ddos_protection_plan { id = azurerm_network_ddos_protection_plan.notejamprotect.id enable = true - } + }*/ subnet { name = "hub_subnet_fwall" diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index f0f1886dd..7a9b6cd0a 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -25,10 +25,13 @@ resource "azurerm_virtual_network" "app_vnet" { #dns_servers = ["10.0.0.4", "10.0.0.5"] depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] +//Working code but commended due to cost +/* ddos_protection_plan { id = azurerm_network_ddos_protection_plan.notejamprotect.id enable = true } + */ subnet { name = "ingress_subnet" diff --git a/terraform/notejam-tf/terraform.auto.tfvars b/terraform/notejam-tf/terraform.auto.tfvars index 11cd0fc19..6d88ed16e 100644 --- a/terraform/notejam-tf/terraform.auto.tfvars +++ b/terraform/notejam-tf/terraform.auto.tfvars @@ -31,7 +31,7 @@ db_version = "5.7" dbproperties = { auto_grow_enabled = true - backup_retention_days = 7 + backup_retention_days = 1 geo_redundant_backup_enabled = false infrastructure_encryption_enabled = false public_network_access_enabled = true @@ -44,7 +44,7 @@ dbproperties = { nodejan_acr = { name = "acrnoedjam" resource_group_name = "rg-acr" - sku = "Standard" + sku = "Basic" } nodejan_acr_admin_enabled = false From 2cec29e216be4fc0fcca33ccd8df4a82d0b5a031 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 17:12:26 +0000 Subject: [PATCH 27/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-vnet-spoke.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index 7a9b6cd0a..cc98d4265 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -25,8 +25,8 @@ resource "azurerm_virtual_network" "app_vnet" { #dns_servers = ["10.0.0.4", "10.0.0.5"] depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] -//Working code but commended due to cost -/* + //Working code but commended due to cost + /* ddos_protection_plan { id = azurerm_network_ddos_protection_plan.notejamprotect.id enable = true From 6340853aaa35e323e77ca4fa9398ee31ca686ba5 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 17:25:12 +0000 Subject: [PATCH 28/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-vnet-hub.tf | 2 +- terraform/notejam-tf/resource-vnet-spoke.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf index b1bffdd89..0726c493d 100644 --- a/terraform/notejam-tf/resource-vnet-hub.tf +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -24,7 +24,7 @@ resource "azurerm_virtual_network" "hub_vnet" { resource_group_name = data.azurerm_resource_group.hub_rg.name address_space = ["10.0.0.0/22"] #dns_servers = ["10.0.0.4", "10.0.0.5"] - depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] + #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] //Working code but commended due to cost /*ddos_protection_plan { diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index cc98d4265..6dabdc6e9 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -23,7 +23,7 @@ resource "azurerm_virtual_network" "app_vnet" { resource_group_name = data.azurerm_resource_group.app_rg.name address_space = ["10.0.0.0/22"] #dns_servers = ["10.0.0.4", "10.0.0.5"] - depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] + # depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] //Working code but commended due to cost /* From 070625da6220038a72fc14e91253ddd79ad87286 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 17:35:20 +0000 Subject: [PATCH 29/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-vnet-hub.tf | 10 +++++----- terraform/notejam-tf/resource-vnet-spoke.tf | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf index 0726c493d..2d9aef718 100644 --- a/terraform/notejam-tf/resource-vnet-hub.tf +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -26,11 +26,11 @@ resource "azurerm_virtual_network" "hub_vnet" { #dns_servers = ["10.0.0.4", "10.0.0.5"] #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] - //Working code but commended due to cost - /*ddos_protection_plan { - id = azurerm_network_ddos_protection_plan.notejamprotect.id - enable = true - }*/ + #Working code but commended due to cost + #ddos_protection_plan { + # id = azurerm_network_ddos_protection_plan.notejamprotect.id + # enable = true + #} subnet { name = "hub_subnet_fwall" diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index 6dabdc6e9..c67ae9e47 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -23,15 +23,15 @@ resource "azurerm_virtual_network" "app_vnet" { resource_group_name = data.azurerm_resource_group.app_rg.name address_space = ["10.0.0.0/22"] #dns_servers = ["10.0.0.4", "10.0.0.5"] - # depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] - - //Working code but commended due to cost - /* - ddos_protection_plan { - id = azurerm_network_ddos_protection_plan.notejamprotect.id - enable = true - } - */ + #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] + + #Working code but commended due to cost + + #ddos_protection_plan { + # id = azurerm_network_ddos_protection_plan.notejamprotect.id + # enable = true + #} + subnet { name = "ingress_subnet" From 4c266e1411e3714bf8db07c333bb2e5eddf2a522 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 18:07:42 +0000 Subject: [PATCH 30/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-vnet-spoke.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index c67ae9e47..b2abd81f0 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -21,7 +21,7 @@ resource "azurerm_virtual_network" "app_vnet" { name = "spokeVirtualNetwork" location = data.azurerm_resource_group.app_rg.location resource_group_name = data.azurerm_resource_group.app_rg.name - address_space = ["10.0.0.0/22"] + address_space = ["10.0.4.0/22"] #dns_servers = ["10.0.0.4", "10.0.0.5"] #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] From 84f7c04ca6523fe3a1edceb28a0af05c64de74b3 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 18:36:35 +0000 Subject: [PATCH 31/44] Machines are reduced to save the cost --- terraform/notejam-tf/resource-sub-spoke-peering.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/notejam-tf/resource-sub-spoke-peering.tf b/terraform/notejam-tf/resource-sub-spoke-peering.tf index c15eb8305..40ab482eb 100644 --- a/terraform/notejam-tf/resource-sub-spoke-peering.tf +++ b/terraform/notejam-tf/resource-sub-spoke-peering.tf @@ -18,8 +18,7 @@ resource "azurerm_virtual_network_peering" "HubToSpoke1" { } resource "azurerm_virtual_network_peering" "Spoke1ToHub" { name = "peerStoH" - resource_group_name = var.vnet-hub["vnet_resourcegroup"] + resource_group_name = var.cluster["app_resourcegroup"] virtual_network_name = data.azurerm_virtual_network.app_vnet.name remote_virtual_network_id = data.azurerm_virtual_network.hub_vnet.id } - From 02f6ebc302d9ed4f0cf614c3168706998439ff83 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:08:47 +0000 Subject: [PATCH 32/44] workflow changes --- .github/workflows/terraform.yml | 15 ++-- .github/workflows/terraform_manual_apply.yml | 85 ++++++++++++++++++++ 2 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/terraform_manual_apply.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 07d996338..584c83079 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -8,10 +8,14 @@ on: - "**/*.tf" - "**/*.yml" - "**/*.sh" + + pull_request: + paths: + - 'terraform/notejam-tf/**' jobs: terraform: - name: 'notejam-pr-apply' + name: 'notejam-azure-validate' runs-on: ubuntu-latest environment: production @@ -24,7 +28,6 @@ jobs: # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest defaults: run: - shell: bash working-directory: "terraform/notejam-tf" steps: @@ -52,12 +55,12 @@ jobs: # Generates an execution plan for Terraform - name: Terraform Plan id: plan - #if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' run: terraform plan -no-color continue-on-error: false - uses: actions/github-script@0.9.0 - #if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' env: PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" with: @@ -81,7 +84,3 @@ jobs: - name: Terraform Plan Status if: steps.plan.outcome == 'failure' run: exit 1 - - - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -auto-approve diff --git a/.github/workflows/terraform_manual_apply.yml b/.github/workflows/terraform_manual_apply.yml new file mode 100644 index 000000000..88954be71 --- /dev/null +++ b/.github/workflows/terraform_manual_apply.yml @@ -0,0 +1,85 @@ +name: 'NordCloud' + +on: + workflow_dispatch: + inputs: + createUpdateEnv: + description: 'Apply the env' + required: true + default: 'false'' + +jobs: + terraform: + name: 'notejam-azure-apply' + runs-on: ubuntu-latest + environment: production + + env: + ARM_CLIENT_ID: ${{ secrets.TF_VAR_ARM_CLIENT_ID }} + ARM_CLIENT_SECRET: ${{ secrets.TF_VAR_ARM_CLIENT_SECRET }} + ARM_SUBSCRIPTION_ID: ${{ secrets.TF_VAR_ARM_SUBSCRIPTION_ID }} + ARM_TENANT_ID: ${{ secrets.TF_VAR_ARM_TENANT_ID }} + + # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest + defaults: + run: + working-directory: "terraform/notejam-tf" + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v2 + + # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + id: fmt + run: terraform fmt -check + continue-on-error: true + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + id: init + run: terraform init + + # Generates an execution plan for Terraform + - name: Terraform Plan + id: plan + if: github.event_name == 'pull_request' + run: terraform plan -no-color + continue-on-error: false + + - uses: actions/github-script@0.9.0 + if: github.event_name == 'pull_request' + env: + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` +
Show Plan + \`\`\`${process.env.PLAN}\`\`\` +
+ *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + if: github.ref == 'refs/heads/master' && github.event.inputs.createUpdateEnv == 'true' + run: terraform apply -auto-approve From d0dfda7db033ad4157433cd1c6818f3fdbb8be76 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:14:30 +0000 Subject: [PATCH 33/44] workflow changes --- .github/workflows/terraform_manual_apply.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform_manual_apply.yml b/.github/workflows/terraform_manual_apply.yml index 88954be71..e749bb777 100644 --- a/.github/workflows/terraform_manual_apply.yml +++ b/.github/workflows/terraform_manual_apply.yml @@ -6,13 +6,12 @@ on: createUpdateEnv: description: 'Apply the env' required: true - default: 'false'' + default: 'false' jobs: terraform: - name: 'notejam-azure-apply' + name: "notejam-azure-apply" runs-on: ubuntu-latest - environment: production env: ARM_CLIENT_ID: ${{ secrets.TF_VAR_ARM_CLIENT_ID }} From febf47b5417a8bccb4b7e2a163351e6ad0ee1bf2 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:16:22 +0000 Subject: [PATCH 34/44] workflow changes --- .github/workflows/terraform_manual_apply.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform_manual_apply.yml b/.github/workflows/terraform_manual_apply.yml index e749bb777..76f30610b 100644 --- a/.github/workflows/terraform_manual_apply.yml +++ b/.github/workflows/terraform_manual_apply.yml @@ -80,5 +80,5 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.ref == 'refs/heads/master' && github.event.inputs.createUpdateEnv == 'true' - run: terraform apply -auto-approve + if: github.ref == 'refs/heads/master' && github.event.inputs.createUpdateEnv == 'true' + run: terraform apply -auto-approve From d9ccf9321498762a730b1d3746bb51313ee076eb Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:43:38 +0000 Subject: [PATCH 35/44] Added terraform backend --- .gitignore | 1 + terraform/notejam-tf/.terraformignore | 1 + terraform/notejam-tf/azure_modules/aks/provider.tf | 3 --- terraform/notejam-tf/notejam.tf | 11 +++++++++++ terraform/notejam-tf/provider.tf | 2 ++ terraform/notejam-tf/resource-security-ddos.tf | 6 ++---- 6 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 terraform/notejam-tf/.terraformignore delete mode 100644 terraform/notejam-tf/azure_modules/aks/provider.tf create mode 100644 terraform/notejam-tf/notejam.tf diff --git a/.gitignore b/.gitignore index 120be0dab..0cae87497 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ terraform/notejam-tf/Readme.txt *.exte .terraform terraform/notejam-tf/terraform.tfstate +terraform/notejam-tf/.terraform.lock.hcl diff --git a/terraform/notejam-tf/.terraformignore b/terraform/notejam-tf/.terraformignore new file mode 100644 index 000000000..e4472bb79 --- /dev/null +++ b/terraform/notejam-tf/.terraformignore @@ -0,0 +1 @@ +resource-security-ddos.tf \ No newline at end of file diff --git a/terraform/notejam-tf/azure_modules/aks/provider.tf b/terraform/notejam-tf/azure_modules/aks/provider.tf deleted file mode 100644 index 283b6125c..000000000 --- a/terraform/notejam-tf/azure_modules/aks/provider.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "azuread" { - version = "~>0.7" -} \ No newline at end of file diff --git a/terraform/notejam-tf/notejam.tf b/terraform/notejam-tf/notejam.tf new file mode 100644 index 000000000..5bdbcd553 --- /dev/null +++ b/terraform/notejam-tf/notejam.tf @@ -0,0 +1,11 @@ +terraform { + backend "remote" { + # The name of your Terraform Cloud organization. + organization = "notejam" + + # The name of the Terraform Cloud workspace to store Terraform state files in. + workspaces { + name = "notejam" + } + } + } \ No newline at end of file diff --git a/terraform/notejam-tf/provider.tf b/terraform/notejam-tf/provider.tf index bbd00a2b3..34f6a5e4e 100644 --- a/terraform/notejam-tf/provider.tf +++ b/terraform/notejam-tf/provider.tf @@ -12,3 +12,5 @@ provider "azurerm" { subscription_id = "81432554-220c-405f-9b16-8c1ef66ecfe5" tenant_id = "614a2ce2-e1f9-4ce4-824e-0ec9bd92cb65" } +provider "azuread" { +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf index 7f2e7440f..c03a51b6e 100644 --- a/terraform/notejam-tf/resource-security-ddos.tf +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -1,6 +1,4 @@ -//Total monthly bill for DDoS Standard will be £2,194/month -// So keeping this commended -/* + resource "azurerm_network_ddos_protection_plan" "notejamprotect" { name = "nordddosprotect" location = data.azurerm_resource_group.app_rg.location @@ -9,5 +7,5 @@ resource "azurerm_network_ddos_protection_plan" "notejamprotect" { environment = "nordcloud notejam test" } } -*/ + \ No newline at end of file From dc390a8d85e88be6cff854c84707a6ac8d0aeb5b Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:53:53 +0000 Subject: [PATCH 36/44] Added terraform backend --- terraform/notejam-tf/resource-security-ddos.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf index c03a51b6e..07ae15ed7 100644 --- a/terraform/notejam-tf/resource-security-ddos.tf +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -1,4 +1,4 @@ - +/* resource "azurerm_network_ddos_protection_plan" "notejamprotect" { name = "nordddosprotect" location = data.azurerm_resource_group.app_rg.location @@ -8,4 +8,4 @@ resource "azurerm_network_ddos_protection_plan" "notejamprotect" { } } - \ No newline at end of file + */ \ No newline at end of file From 96fab49f5a50cb6e628b076076140ba0030fcec2 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 19:56:59 +0000 Subject: [PATCH 37/44] Iac completed --- terraform/notejam-tf/notejam.tf | 18 ++++++------- .../notejam-tf/resource-jenkins-bastian.tf | 2 +- terraform/notejam-tf/resource-vnet-spoke.tf | 4 +-- terraform/notejam-tf/variables.tf | 26 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/terraform/notejam-tf/notejam.tf b/terraform/notejam-tf/notejam.tf index 5bdbcd553..e2f740e33 100644 --- a/terraform/notejam-tf/notejam.tf +++ b/terraform/notejam-tf/notejam.tf @@ -1,11 +1,11 @@ terraform { - backend "remote" { - # The name of your Terraform Cloud organization. - organization = "notejam" + backend "remote" { + # The name of your Terraform Cloud organization. + organization = "notejam" - # The name of the Terraform Cloud workspace to store Terraform state files in. - workspaces { - name = "notejam" - } - } - } \ No newline at end of file + # The name of the Terraform Cloud workspace to store Terraform state files in. + workspaces { + name = "notejam" + } + } +} \ No newline at end of file diff --git a/terraform/notejam-tf/resource-jenkins-bastian.tf b/terraform/notejam-tf/resource-jenkins-bastian.tf index 622709e52..a42072a75 100644 --- a/terraform/notejam-tf/resource-jenkins-bastian.tf +++ b/terraform/notejam-tf/resource-jenkins-bastian.tf @@ -99,7 +99,7 @@ resource "azurerm_linux_virtual_machine" "bastian_jenkins_vm" { #custom_data = ${filebase64(${file("cloud-init-jenkins.txt")}) - custom_data = "${filebase64("cloud-init-jenkins.txt")}" + custom_data = filebase64("cloud-init-jenkins.txt") os_disk { diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index b2abd81f0..ea2c09b26 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -26,12 +26,12 @@ resource "azurerm_virtual_network" "app_vnet" { #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] #Working code but commended due to cost - + #ddos_protection_plan { # id = azurerm_network_ddos_protection_plan.notejamprotect.id # enable = true #} - + subnet { name = "ingress_subnet" diff --git a/terraform/notejam-tf/variables.tf b/terraform/notejam-tf/variables.tf index 92863b1ae..508d61367 100644 --- a/terraform/notejam-tf/variables.tf +++ b/terraform/notejam-tf/variables.tf @@ -14,7 +14,7 @@ variable "client_secret" {} # Variables related to application deployment cluster variable "cluster" { - type = map + type = map(any) default = { app_name = "aks-notejam" app_resourcegroup = "rg-app" @@ -23,44 +23,44 @@ variable "cluster" { } } variable "vnet-hub" { - type = map + type = map(any) default = { vnet_resourcegroup = "rg-hub-network" } } // These variables are related to DB -variable db_server_name { +variable "db_server_name" { type = string } -variable database_name { +variable "database_name" { type = string } -variable administrator_login { +variable "administrator_login" { type = string } -variable administrator_login_password { +variable "administrator_login_password" { type = string } -variable db_resource_group_name { +variable "db_resource_group_name" { type = string default = "rg-notejam-db" } -variable sku_name { +variable "sku_name" { type = string } -variable storage_mb { +variable "storage_mb" { type = number default = 5120 } -variable db_version { +variable "db_version" { type = string default = 5.7 } //SQl specific database variable "dbproperties" { - type = map + type = map(any) default = { auto_grow_enabled = true backup_retention_days = 7 @@ -76,7 +76,7 @@ variable "dbproperties" { } //Related to ACR variable "nodejan_acr" { - type = map + type = map(any) default = { name = "acrnoedjam" resource_group_name = "rg-acr" @@ -84,7 +84,7 @@ variable "nodejan_acr" { } } -variable nodejan_acr_admin_enabled { +variable "nodejan_acr_admin_enabled" { type = bool default = false } From 375a5f73c0cb6414f2193635bcbd602a4eca85e3 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 22:23:21 +0000 Subject: [PATCH 38/44] Test database added --- .../resources/application-test.properties | 24 ++++++++++++++++++- terraform/notejam-tf/resource-database.tf | 8 +++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/spring/src/test/resources/application-test.properties b/spring/src/test/resources/application-test.properties index ba26b60f9..091ced108 100644 --- a/spring/src/test/resources/application-test.properties +++ b/spring/src/test/resources/application-test.properties @@ -1 +1,23 @@ -spring.datasource.url=jdbc:hsqldb:mem:test +#email.sender: Markus Malkusch + +#; If you want to have mail transport, configure at least the property spring.mail.host, +#; otherwise mail transport is not available. +#; For further mail configuration see http://docs.spring.io/spring-boot/docs/current/api/index.html?org/springframework/boot/autoconfigure/mail/MailProperties.html +#; +spring.mail.host= smtp.example.net +email.sender=suresh.thomas@yahoo.com +spring.datasource.url=jdbc:hsqldb:file:db +spring.jpa.hibernate.ddl-auto=create-drop +async.queueCapacity= 1000 +#; ISO 8601 period until a recovery token expires. +recovery.lifetime= P1D +#; The length of the generated password. +recovery.length= 32 +#spring.jpa.show-sql=true +#spring.jpa.properties.hibernate.format_sql=true +#spring.datasource.initialization-mode=always +#logging.level.org.hibernate.SQL=DEBUG +#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +#logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +#logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE +#spring.jackson.default-property-inclusion=NON_NULL diff --git a/terraform/notejam-tf/resource-database.tf b/terraform/notejam-tf/resource-database.tf index 9e837fa9c..55b505c10 100644 --- a/terraform/notejam-tf/resource-database.tf +++ b/terraform/notejam-tf/resource-database.tf @@ -5,4 +5,12 @@ module "app-db" { db_resource_group_name = var.db_resource_group_name db_server_name = var.db_server_name depends_on = [module.app-datbase-server] +} + +module "test-db" { + source = "./azure_modules/database" + database_name = "testdbnotejam" + db_resource_group_name = var.db_resource_group_name + db_server_name = var.db_server_name + depends_on = [module.app-datbase-server] } \ No newline at end of file From b2a744968ac8e667c3dfc8123ccfb01d47b11b97 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 22:31:48 +0000 Subject: [PATCH 39/44] Test database added --- terraform/notejam-tf/resource-jenkins-bastian.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/notejam-tf/resource-jenkins-bastian.tf b/terraform/notejam-tf/resource-jenkins-bastian.tf index a42072a75..406530845 100644 --- a/terraform/notejam-tf/resource-jenkins-bastian.tf +++ b/terraform/notejam-tf/resource-jenkins-bastian.tf @@ -27,7 +27,7 @@ resource "azurerm_public_ip" "bastian_public_ip" { name = "bastianPubIP" location = var.location resource_group_name = data.azurerm_resource_group.rg_hub.name - allocation_method = "Dynamic" + allocation_method = "Static" tags = { environment = "nordcloud notejam test" From bc98707f73b93f0460aece7693a03779e33281ea Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Sat, 13 Mar 2021 22:44:04 +0000 Subject: [PATCH 40/44] Spring database changes --- .../resources/application-test.properties | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/spring/src/test/resources/application-test.properties b/spring/src/test/resources/application-test.properties index 091ced108..9999cd55d 100644 --- a/spring/src/test/resources/application-test.properties +++ b/spring/src/test/resources/application-test.properties @@ -6,18 +6,32 @@ #; spring.mail.host= smtp.example.net email.sender=suresh.thomas@yahoo.com -spring.datasource.url=jdbc:hsqldb:file:db -spring.jpa.hibernate.ddl-auto=create-drop + + +#spring.datasource.url=jdbc:hsqldb:file:db +#spring.jpa.hibernate.ddl-auto=update + async.queueCapacity= 1000 + #; ISO 8601 period until a recovery token expires. recovery.lifetime= P1D + #; The length of the generated password. recovery.length= 32 -#spring.jpa.show-sql=true -#spring.jpa.properties.hibernate.format_sql=true -#spring.datasource.initialization-mode=always -#logging.level.org.hibernate.SQL=DEBUG -#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE -#logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG -#logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE -#spring.jackson.default-property-inclusion=NON_NULL + + +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +#spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.driverClassName=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mysql://nordcloud-mysqlserver.mysql.database.azure.com:3306/testdbnotejam +spring.datasource.username=mysqladminun@nordcloud-mysqlserver +spring.datasource.password=H@Sh1CoR3! +spring.datasource.initialization-mode=always +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE +spring.jackson.default-property-inclusion=NON_NULL +spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file From a331230a5ae8d49b94b8323d5b4da86d5fcffd07 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 19 Mar 2021 10:27:35 +0000 Subject: [PATCH 41/44] added few resources --- terraform/notejam-tf/resource-acr.tf | 2 -- terraform/notejam-tf/resource-security-ddos.tf | 4 ++-- terraform/notejam-tf/resource-vnet-hub.tf | 8 ++++---- terraform/notejam-tf/resource-vnet-spoke.tf | 12 ++++-------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/terraform/notejam-tf/resource-acr.tf b/terraform/notejam-tf/resource-acr.tf index c079faca4..e1d82c56b 100644 --- a/terraform/notejam-tf/resource-acr.tf +++ b/terraform/notejam-tf/resource-acr.tf @@ -1,7 +1,5 @@ //NodeJam container registry - - data "azuread_service_principal" "aks_principal" { application_id = var.client_id } diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf index 07ae15ed7..c03a51b6e 100644 --- a/terraform/notejam-tf/resource-security-ddos.tf +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -1,4 +1,4 @@ -/* + resource "azurerm_network_ddos_protection_plan" "notejamprotect" { name = "nordddosprotect" location = data.azurerm_resource_group.app_rg.location @@ -8,4 +8,4 @@ resource "azurerm_network_ddos_protection_plan" "notejamprotect" { } } - */ \ No newline at end of file + \ No newline at end of file diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf index 2d9aef718..3d9a69553 100644 --- a/terraform/notejam-tf/resource-vnet-hub.tf +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -27,10 +27,10 @@ resource "azurerm_virtual_network" "hub_vnet" { #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] #Working code but commended due to cost - #ddos_protection_plan { - # id = azurerm_network_ddos_protection_plan.notejamprotect.id - # enable = true - #} + ddos_protection_plan { + id = azurerm_network_ddos_protection_plan.notejamprotect.id + enable = true + } subnet { name = "hub_subnet_fwall" diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index ea2c09b26..6d330ac0a 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -14,9 +14,6 @@ resource "azurerm_network_security_group" "app_nsg" { environment = "nordcloud notejam test" } } - - - resource "azurerm_virtual_network" "app_vnet" { name = "spokeVirtualNetwork" location = data.azurerm_resource_group.app_rg.location @@ -27,11 +24,10 @@ resource "azurerm_virtual_network" "app_vnet" { #Working code but commended due to cost - #ddos_protection_plan { - # id = azurerm_network_ddos_protection_plan.notejamprotect.id - # enable = true - #} - + ddos_protection_plan { + id = azurerm_network_ddos_protection_plan.notejamprotect.id + enable = true + } subnet { name = "ingress_subnet" From fd52aa5290e2b23a42a634f1fe3168922d7ed392 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 19 Mar 2021 11:58:46 +0000 Subject: [PATCH 42/44] changes ddos --- terraform/notejam-tf/resource-security-ddos.tf | 4 ++-- terraform/notejam-tf/resource-vnet-hub.tf | 4 ++-- terraform/notejam-tf/resource-vnet-spoke.tf | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/terraform/notejam-tf/resource-security-ddos.tf b/terraform/notejam-tf/resource-security-ddos.tf index c03a51b6e..a88dfb1ce 100644 --- a/terraform/notejam-tf/resource-security-ddos.tf +++ b/terraform/notejam-tf/resource-security-ddos.tf @@ -1,5 +1,5 @@ -resource "azurerm_network_ddos_protection_plan" "notejamprotect" { +/*resource "azurerm_network_ddos_protection_plan" "notejamprotect" { name = "nordddosprotect" location = data.azurerm_resource_group.app_rg.location resource_group_name = data.azurerm_resource_group.app_rg.name @@ -7,5 +7,5 @@ resource "azurerm_network_ddos_protection_plan" "notejamprotect" { environment = "nordcloud notejam test" } } - +*/ \ No newline at end of file diff --git a/terraform/notejam-tf/resource-vnet-hub.tf b/terraform/notejam-tf/resource-vnet-hub.tf index 3d9a69553..e0271041f 100644 --- a/terraform/notejam-tf/resource-vnet-hub.tf +++ b/terraform/notejam-tf/resource-vnet-hub.tf @@ -27,10 +27,10 @@ resource "azurerm_virtual_network" "hub_vnet" { #depends_on = [azurerm_network_ddos_protection_plan.notejamprotect] #Working code but commended due to cost - ddos_protection_plan { + /*ddos_protection_plan { id = azurerm_network_ddos_protection_plan.notejamprotect.id enable = true - } + }*/ subnet { name = "hub_subnet_fwall" diff --git a/terraform/notejam-tf/resource-vnet-spoke.tf b/terraform/notejam-tf/resource-vnet-spoke.tf index 6d330ac0a..e605455bf 100644 --- a/terraform/notejam-tf/resource-vnet-spoke.tf +++ b/terraform/notejam-tf/resource-vnet-spoke.tf @@ -24,10 +24,10 @@ resource "azurerm_virtual_network" "app_vnet" { #Working code but commended due to cost - ddos_protection_plan { + /*ddos_protection_plan { id = azurerm_network_ddos_protection_plan.notejamprotect.id enable = true - } + }*/ subnet { name = "ingress_subnet" From 33ab9716c3c0f5cfb8e2f14976fccceef6be7a65 Mon Sep 17 00:00:00 2001 From: Suresh Thomas Date: Fri, 19 Mar 2021 14:00:14 +0000 Subject: [PATCH 43/44] Spring removed and moved to different project as microservice refactoring --- spring/.gitignore | 5 - spring/Dockerfile | 4 - spring/README.rst | 103 ---- spring/pom.xml | 191 ------- .../java/net/notejam/spring/Application.java | 138 ------ .../java/net/notejam/spring/URITemplates.java | 95 ---- .../spring/error/ForcedErrorController.java | 24 - .../error/ResourceNotFoundException.java | 17 - .../error/UnsupportedLocaleException.java | 31 -- .../notejam/spring/error/package-info.java | 7 - .../converter/StringToPeriodConverter.java | 20 - .../spring/helper/converter/package-info.java | 7 - .../spring/helper/reflection/Annotated.java | 62 --- .../helper/reflection/ReflectionUtils.java | 82 --- .../helper/reflection/package-info.java | 7 - .../java/net/notejam/spring/note/Note.java | 153 ------ .../notejam/spring/note/NoteRepository.java | 48 -- .../net/notejam/spring/note/NoteService.java | 142 ------ .../note/controller/AllNotesController.java | 55 --- .../note/controller/CreateNoteController.java | 94 ---- .../note/controller/DeleteNoteController.java | 70 --- .../note/controller/EditNoteController.java | 94 ---- .../note/controller/ViewNoteController.java | 55 --- .../spring/note/controller/package-info.java | 7 - .../net/notejam/spring/note/package-info.java | 7 - .../java/net/notejam/spring/package-info.java | 7 - .../main/java/net/notejam/spring/pad/Pad.java | 100 ---- .../net/notejam/spring/pad/PadRepository.java | 26 - .../net/notejam/spring/pad/PadService.java | 106 ---- .../pad/controller/CreatePadController.java | 90 ---- .../pad/controller/DeletePadController.java | 70 --- .../pad/controller/EditPadController.java | 94 ---- .../spring/pad/controller/PadsAdvice.java | 60 --- .../controller/ViewPadNotesController.java | 83 ---- .../spring/pad/controller/package-info.java | 7 - .../net/notejam/spring/pad/package-info.java | 7 - .../spring/security/LoginController.java | 23 - .../security/SecurityConfiguration.java | 74 --- .../spring/security/SecurityService.java | 58 --- .../security/UserDetailsServiceImpl.java | 37 -- .../notejam/spring/security/owner/Owned.java | 22 - .../spring/security/owner/PermitOwner.java | 20 - .../security/owner/PermitOwnerAspect.java | 126 ----- .../spring/security/owner/package-info.java | 7 - .../notejam/spring/security/package-info.java | 7 - .../java/net/notejam/spring/user/User.java | 77 --- .../notejam/spring/user/UserRepository.java | 24 - .../net/notejam/spring/user/UserService.java | 100 ---- .../notejam/spring/user/account/Account.java | 96 ---- .../user/account/AccountController.java | 66 --- .../account/constraints/CurrentPassword.java | 46 -- .../constraints/CurrentPasswordValidator.java | 47 -- .../account/constraints/package-info.java | 7 - .../spring/user/account/package-info.java | 7 - .../spring/user/constraints/Password.java | 47 -- .../spring/user/constraints/package-info.java | 7 - .../spring/user/forgot/ForgotPassword.java | 39 -- .../user/forgot/ForgotPasswordController.java | 86 ---- .../user/forgot/InvalidTokenException.java | 13 - .../user/forgot/PasswordRecoveryService.java | 239 --------- .../forgot/RecoverPasswordController.java | 62 --- .../spring/user/forgot/RecoveryToken.java | 102 ---- .../user/forgot/RecoveryTokenRepository.java | 37 -- .../spring/user/forgot/package-info.java | 7 - .../net/notejam/spring/user/package-info.java | 7 - .../notejam/spring/user/signup/Signup.java | 97 ---- .../spring/user/signup/SignupController.java | 63 --- .../user/signup/constraints/UniqueEmail.java | 46 -- .../constraints/UniqueEmailValidator.java | 40 -- .../user/signup/constraints/package-info.java | 7 - .../spring/user/signup/package-info.java | 7 - .../spring/view/ViewConfiguration.java | 27 - .../dialect/NaturalLanguageDateProcessor.java | 47 -- .../view/dialect/NoteTextProcessor.java | 54 -- .../spring/view/dialect/NotejamDialect.java | 35 -- .../spring/view/dialect/ProcessorUtil.java | 44 -- .../spring/view/dialect/package-info.java | 7 - .../net/notejam/spring/view/package-info.java | 7 - .../src/main/resources/application.properties | 37 -- .../src/main/resources/messages_de.properties | 122 ----- .../src/main/resources/messages_en.properties | 122 ----- .../src/main/resources/static/css/style.css | 467 ------------------ .../src/main/resources/templates/error.html | 16 - .../src/main/resources/templates/layout.html | 102 ---- .../main/resources/templates/note/create.html | 47 -- .../main/resources/templates/note/delete.html | 21 - .../main/resources/templates/note/edit.html | 43 -- .../main/resources/templates/note/view.html | 37 -- .../src/main/resources/templates/notes.html | 61 --- .../main/resources/templates/pad/create.html | 29 -- .../main/resources/templates/pad/delete.html | 21 - .../main/resources/templates/pad/edit.html | 34 -- .../resources/templates/user/account.html | 51 -- .../templates/user/forgot-password.html | 29 -- .../main/resources/templates/user/login.html | 40 -- .../templates/user/reveal-password.html | 20 - .../main/resources/templates/user/signup.html | 45 -- spring/src/main/tomcatconf/server.xml | 38 -- spring/src/main/tomcatconf/tomcat-users.xml | 9 - .../StringToPeriodConverterTest.java | 24 - .../spring/note/CreateNoteControllerTest.java | 142 ------ .../spring/note/DeleteNoteControllerTest.java | 104 ---- .../spring/note/EditNoteControllerTest.java | 169 ------- .../notejam/spring/note/NoteServiceTest.java | 98 ---- .../spring/note/ViewNoteControllerTest.java | 94 ---- .../spring/pad/CreatePadControllerTest.java | 83 ---- .../spring/pad/DeletePadControllerTest.java | 104 ---- .../spring/pad/EditPadControllerTest.java | 133 ----- .../spring/pad/ViewPadControllerTest.java | 94 ---- .../spring/security/LoginControllerTest.java | 79 --- .../spring/security/SecurityServiceTest.java | 61 --- .../security/owner/PermitOwnerAspectTest.java | 91 ---- .../owner/PermitOwnerIntegrationTest.java | 178 ------- .../notejam/spring/test/IntegrationTest.java | 30 -- .../notejam/spring/test/MockMvcProvider.java | 40 -- .../java/net/notejam/spring/test/UriUtil.java | 72 --- .../spring/user/SignedUpUserProvider.java | 63 --- .../notejam/spring/user/UserServiceTest.java | 50 -- .../user/signup/SignupControllerTest.java | 145 ------ .../resources/application-test.properties | 37 -- 120 files changed, 7421 deletions(-) delete mode 100644 spring/.gitignore delete mode 100644 spring/Dockerfile delete mode 100644 spring/README.rst delete mode 100644 spring/pom.xml delete mode 100644 spring/src/main/java/net/notejam/spring/Application.java delete mode 100644 spring/src/main/java/net/notejam/spring/URITemplates.java delete mode 100644 spring/src/main/java/net/notejam/spring/error/ForcedErrorController.java delete mode 100644 spring/src/main/java/net/notejam/spring/error/ResourceNotFoundException.java delete mode 100644 spring/src/main/java/net/notejam/spring/error/UnsupportedLocaleException.java delete mode 100644 spring/src/main/java/net/notejam/spring/error/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/helper/converter/StringToPeriodConverter.java delete mode 100644 spring/src/main/java/net/notejam/spring/helper/converter/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/helper/reflection/Annotated.java delete mode 100644 spring/src/main/java/net/notejam/spring/helper/reflection/ReflectionUtils.java delete mode 100644 spring/src/main/java/net/notejam/spring/helper/reflection/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/Note.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/NoteRepository.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/NoteService.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/AllNotesController.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/CreateNoteController.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/DeleteNoteController.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/EditNoteController.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/ViewNoteController.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/controller/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/note/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/Pad.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/PadRepository.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/PadService.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/CreatePadController.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/DeletePadController.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/EditPadController.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/PadsAdvice.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/ViewPadNotesController.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/controller/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/pad/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/LoginController.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/SecurityConfiguration.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/SecurityService.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/UserDetailsServiceImpl.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/owner/Owned.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/owner/PermitOwner.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/owner/PermitOwnerAspect.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/owner/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/security/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/User.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/UserRepository.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/UserService.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/Account.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/AccountController.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPassword.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPasswordValidator.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/constraints/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/account/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/constraints/Password.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/constraints/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/ForgotPassword.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/ForgotPasswordController.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/InvalidTokenException.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/PasswordRecoveryService.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/RecoverPasswordController.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/RecoveryToken.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/RecoveryTokenRepository.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/forgot/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/Signup.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/SignupController.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmail.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmailValidator.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/constraints/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/user/signup/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/ViewConfiguration.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/dialect/NaturalLanguageDateProcessor.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/dialect/NoteTextProcessor.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/dialect/NotejamDialect.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/dialect/ProcessorUtil.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/dialect/package-info.java delete mode 100644 spring/src/main/java/net/notejam/spring/view/package-info.java delete mode 100644 spring/src/main/resources/application.properties delete mode 100644 spring/src/main/resources/messages_de.properties delete mode 100644 spring/src/main/resources/messages_en.properties delete mode 100644 spring/src/main/resources/static/css/style.css delete mode 100644 spring/src/main/resources/templates/error.html delete mode 100644 spring/src/main/resources/templates/layout.html delete mode 100644 spring/src/main/resources/templates/note/create.html delete mode 100644 spring/src/main/resources/templates/note/delete.html delete mode 100644 spring/src/main/resources/templates/note/edit.html delete mode 100644 spring/src/main/resources/templates/note/view.html delete mode 100644 spring/src/main/resources/templates/notes.html delete mode 100644 spring/src/main/resources/templates/pad/create.html delete mode 100644 spring/src/main/resources/templates/pad/delete.html delete mode 100644 spring/src/main/resources/templates/pad/edit.html delete mode 100644 spring/src/main/resources/templates/user/account.html delete mode 100644 spring/src/main/resources/templates/user/forgot-password.html delete mode 100644 spring/src/main/resources/templates/user/login.html delete mode 100644 spring/src/main/resources/templates/user/reveal-password.html delete mode 100644 spring/src/main/resources/templates/user/signup.html delete mode 100644 spring/src/main/tomcatconf/server.xml delete mode 100644 spring/src/main/tomcatconf/tomcat-users.xml delete mode 100644 spring/src/test/java/net/notejam/spring/helper/converter/StringToPeriodConverterTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/note/CreateNoteControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/note/DeleteNoteControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/note/EditNoteControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/note/NoteServiceTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/note/ViewNoteControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/pad/CreatePadControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/pad/DeletePadControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/pad/EditPadControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/pad/ViewPadControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/security/LoginControllerTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/security/SecurityServiceTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/security/owner/PermitOwnerAspectTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/security/owner/PermitOwnerIntegrationTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/test/IntegrationTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/test/MockMvcProvider.java delete mode 100644 spring/src/test/java/net/notejam/spring/test/UriUtil.java delete mode 100644 spring/src/test/java/net/notejam/spring/user/SignedUpUserProvider.java delete mode 100644 spring/src/test/java/net/notejam/spring/user/UserServiceTest.java delete mode 100644 spring/src/test/java/net/notejam/spring/user/signup/SignupControllerTest.java delete mode 100644 spring/src/test/resources/application-test.properties diff --git a/spring/.gitignore b/spring/.gitignore deleted file mode 100644 index f9c08aa47..000000000 --- a/spring/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/target/ -db.* -application.properties -/.idea/ -/spring.iml diff --git a/spring/Dockerfile b/spring/Dockerfile deleted file mode 100644 index 2519c1b87..000000000 --- a/spring/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -# we are extending everything from tomcat:8.0 image ... -FROM openjdk:8-jdk-alpine -COPY target/notejam-0.0.1-SNAPSHOT.jar app.jar -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/spring/README.rst b/spring/README.rst deleted file mode 100644 index 2e3b57aa3..000000000 --- a/spring/README.rst +++ /dev/null @@ -1,103 +0,0 @@ -*************** -Notejam: Spring -*************** - -Notejam application implemented using `Spring `_ framework. - -Spring version: 4.2.3 - -The full stack is: - -- `Spring Boot `_ (Spring configuration) -- `Thymeleaf `_ (View) -- `Spring Security `_ (Security framework) -- `Spring`_ (DI and MVC framework) -- `Spring Data `_ (Persistence abstraction) -- `JPA `_ (Persistence API) -- `Hibernate `_ (JPA implementation) - -The application is maintained by `@malkusch `_. - -========================== -Installation and launching -========================== - ------ -Clone ------ - -Clone the repo: - -.. code-block:: bash - - $ git clone https://github.com/komarserjio/notejam YOUR_PROJECT_DIR/ - -------- -Install -------- - -Install a `JDK `_ and `Maven `_. - -------------- -Configuration -------------- - -The application has a password recovery process which involves sending an email. -If you want to enable that, you have to create a local application.properties file -and set there the property spring.mail.host to your SMTP server (e.g. spring.mail.host = smtp.example.net). - -.. code-block:: bash - - $ cd YOUR_PROJECT_DIR/spring/ - $ vi application.properties - -See `MailProperties `_ -for more mail properties. - ------- -Launch ------- - -Compile and launch the application: - -.. code-block:: bash - - $ cd YOUR_PROJECT_DIR/spring/ - $ mvn spring-boot:run - -Go to http://localhost:8080/ in your browser. - -~~~~~~~~~~~~ -Localization -~~~~~~~~~~~~ - -This application comes with support for the languages German and English. The locale is -determined by the Accept-Language request header. If the header is not present the -content will be served with the default locale of the JVM. The application will not -start if the default locale is non of the supported languages. - ---------- -Run tests ---------- - -Run functional and unit tests: - -.. code-block:: bash - - $ cd YOUR_PROJECT_DIR/spring/ - $ mvn test - -============ -Contribution -============ - -Do you have Java/Spring experience? Help the application to follow Java and Spring best practices. - -Please send your pull requests in the ``master`` branch. -Always prepend your commits with framework name: - -.. code-block:: bash - - Spring: Implement sign in functionality - -Read `contribution guide `_ for details. diff --git a/spring/pom.xml b/spring/pom.xml deleted file mode 100644 index b86b7c67f..000000000 --- a/spring/pom.xml +++ /dev/null @@ -1,191 +0,0 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 1.3.0.RELEASE - - net.notejam - notejam - jar - 0.0.1-SNAPSHOT - notejam - Implements notejam with Spring - - 1.8 - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-mail - - - org.springframework.boot - spring-boot-starter-security - - - org.thymeleaf.extras - thymeleaf-extras-springsecurity4 - - - org.hsqldb - hsqldb - runtime - - - org.hibernate - hibernate-validator - - - org.apache.commons - commons-lang3 - 3.4 - - - org.ocpsoft.prettytime - prettytime - 4.0.0.Final - - - de.malkusch.validation - validation - 0.3.0 - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - - mysql - mysql-connector-java - runtime - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.codehaus.mojo - aspectj-maven-plugin - 1.8 - - true - ${java.version} - ${java.version} - ignore - ${java.version} - UTF-8 - false - - - org.springframework - spring-aspects - - - - - - - compile - test-compile - - - - - - org.aspectj - aspectjrt - 1.8.7 - - - org.aspectj - aspectjtools - 1.8.7 - - - - - io.fabric8 - docker-maven-plugin - 0.34.1 - - - - notejam:0.0.1.0 - dockerfile - - - ${project.basedir} - - rootWar - - - - - development - ${project.version} - - - 8080:8080 - - - seccomp=unconfined - - - DEMO - ISO8601 - blue - - - - - - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.1 - - / - ${project.build.directory}/${project.build.finalName} - - - - tomcat-run - - exec-war-only - - package - - / - - src/main/tomcatconf/server.xml - - - - - - - - - \ No newline at end of file diff --git a/spring/src/main/java/net/notejam/spring/Application.java b/spring/src/main/java/net/notejam/spring/Application.java deleted file mode 100644 index df4e3a24f..000000000 --- a/spring/src/main/java/net/notejam/spring/Application.java +++ /dev/null @@ -1,138 +0,0 @@ -package net.notejam.spring; - -import java.util.Locale; -import java.util.concurrent.Executor; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.orm.jpa.EntityScan; -import org.springframework.context.MessageSource; -import org.springframework.context.NoSuchMessageException; -import org.springframework.context.annotation.AdviceMode; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.context.annotation.aspectj.EnableSpringConfigured; -import org.springframework.core.convert.ConversionService; -import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.core.env.PropertySource; -import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; - -import net.notejam.spring.error.UnsupportedLocaleException; -import net.notejam.spring.helper.converter.StringToPeriodConverter; - -/** - * Configures the Spring framework. - * - * @author markus@malkusch.de - * @see Donations - */ -@SpringBootApplication -@EnableSpringConfigured -@EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class }) -@EnableAspectJAutoProxy -public class Application { - - /** - * Configures concurrency. - * - * @author markus@malkusch.de - * @see Donations - */ - @EnableAsync(mode = AdviceMode.ASPECTJ) - @Configuration - @EnableScheduling - public static class AsyncConfiguration { - - /** - * The queue capacity. - */ - @Value("${async.queueCapacity}") - private int queueCapacity; - - /** - * The mail sending thread. - * - * @return The mail executor. - */ - @Bean - public Executor mailExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setCorePoolSize(1); - executor.setMaxPoolSize(1); - executor.setQueueCapacity(queueCapacity); - executor.setThreadPriority(Thread.MIN_PRIORITY); - executor.initialize(); - return executor; - } - - } - - /** - * Starts the application. - * - * @param args - * The commandline arguments. - */ - public static void main(final String[] args) { - SpringApplication.run(Application.class, args); - } - - /** - * Provides the locale resolver. - * - * @param messageSource - * The messageSource - * @return The locale resolver. - * @throws UnsupportedLocaleException - * The JVM's default locale does not support any of the - * {@link MessageSource} languages. - */ - @Bean - public LocaleResolver localeResolver(final MessageSource messageSource) throws UnsupportedLocaleException { - checkDefaultLocale(messageSource); - return new AcceptHeaderLocaleResolver(); - } - - /** - * Checks if the default locale is supported by the messageSource. - * - * @param messageSource - * The message source - * @throws UnsupportedLocaleException - * The JVM's default locale does not support any of the - * {@link MessageSource} languages. - */ - private static void checkDefaultLocale(final MessageSource messageSource) throws UnsupportedLocaleException { - try { - messageSource.getMessage("bootstrap.locale", null, Locale.getDefault()); - - } catch (NoSuchMessageException e) { - throw new UnsupportedLocaleException(String.format( - "The JVM runs with the locale %s. This locale is not supported by this application. Please start the JVM with a supported locale, e.g. en.", - Locale.getDefault()), e); - } - } - - /** - * The conversion service. - * - * The conversion service helps to convert strings from e.g. a - * {@link PropertySource} into other types. - * - * @return The conversion service. - */ - @Bean - public ConversionService conversionService() { - DefaultConversionService service = new DefaultConversionService(); - service.addConverter(new StringToPeriodConverter()); - return service; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/URITemplates.java b/spring/src/main/java/net/notejam/spring/URITemplates.java deleted file mode 100644 index fc4289a25..000000000 --- a/spring/src/main/java/net/notejam/spring/URITemplates.java +++ /dev/null @@ -1,95 +0,0 @@ -package net.notejam.spring; - -/** - * URI templates. - * - * @author markus@malkusch.de - * - * @see Donations - * @see - * Requirements - */ -public interface URITemplates { - - /** - * The sign up path. - */ - String SIGNUP = "/signup"; - - /** - * The sign in path. - */ - String SIGNIN = "/signin"; - - /** - * The sign out path. - */ - String SIGNOUT = "/signout"; - - /** - * The settings path. - */ - String SETTINGS = "/settings"; - - /** - * The forgot password path. - */ - String FORGOT_PASSWORD = "/forgot-password"; - - /** - * The recover password path. - */ - String RECOVER_PASSWORD = "/recover-password/{id}/{token}"; - - /** - * The create pad path. - */ - String CREATE_PAD = "/pads/create"; - - /** - * The edit pad path. - */ - String EDIT_PAD = "/pads/{id}/edit"; - - /** - * The view pad path. - */ - String VIEW_PAD = "/pads/{id}"; - - /** - * The delete pad path. - */ - String DELETE_PAD = "/pads/{id}/delete"; - - /** - * The create note path. - */ - String CREATE_NOTE = "/notes/create"; - - /** - * The create note with a preselected pad path. - */ - String CREATE_NOTE_FOR_PAD = CREATE_NOTE + "?pad={id}"; - - /** - * The edit note path. - */ - String EDIT_NOTE = "/notes/{id}/edit"; - - /** - * The view note path. - */ - String VIEW_NOTE = "/notes/{id}"; - - /** - * The delete note path. - */ - String DELETE_NOTE = "/notes/{id}/delete"; - - /** - * The view all notes path. This is the default path. - */ - String VIEW_ALL_NOTES = "/"; - -} diff --git a/spring/src/main/java/net/notejam/spring/error/ForcedErrorController.java b/spring/src/main/java/net/notejam/spring/error/ForcedErrorController.java deleted file mode 100644 index 616c1da92..000000000 --- a/spring/src/main/java/net/notejam/spring/error/ForcedErrorController.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.notejam.spring.error; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Forces an error. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping("/error") -public class ForcedErrorController { - - /** - * Throws an exception on purpose to demonstrate the error handler. - */ - @RequestMapping("/unhandled") - public void forceUnexpectedException() { - throw new RuntimeException("This exception was forced."); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/error/ResourceNotFoundException.java b/spring/src/main/java/net/notejam/spring/error/ResourceNotFoundException.java deleted file mode 100644 index be39c5281..000000000 --- a/spring/src/main/java/net/notejam/spring/error/ResourceNotFoundException.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.notejam.spring.error; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * The resource was not found. - * - * @author markus@malkusch.de - * @see Donations - */ -@ResponseStatus(HttpStatus.NOT_FOUND) -public class ResourceNotFoundException extends RuntimeException { - - private static final long serialVersionUID = -8156443636276732179L; - -} diff --git a/spring/src/main/java/net/notejam/spring/error/UnsupportedLocaleException.java b/spring/src/main/java/net/notejam/spring/error/UnsupportedLocaleException.java deleted file mode 100644 index e35014a3a..000000000 --- a/spring/src/main/java/net/notejam/spring/error/UnsupportedLocaleException.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.notejam.spring.error; - -import org.springframework.context.NoSuchMessageException; - -/** - * An exception for an unsupported locale. - * - * @author markus@malkusch.de - * @see Donations - */ -public class UnsupportedLocaleException extends Exception { - - private static final long serialVersionUID = 1370162885847665856L; - - /** - * Constructs a new exception with the specified detail message. - * - * @param message - * the detail message. The detail message is saved for later - * retrieval by the {@link #getMessage()} method. - * @param cause - * the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - */ - public UnsupportedLocaleException(final String message, final NoSuchMessageException cause) { - super(message, cause); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/error/package-info.java b/spring/src/main/java/net/notejam/spring/error/package-info.java deleted file mode 100644 index 066ccaa3e..000000000 --- a/spring/src/main/java/net/notejam/spring/error/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for error concerns. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.error; diff --git a/spring/src/main/java/net/notejam/spring/helper/converter/StringToPeriodConverter.java b/spring/src/main/java/net/notejam/spring/helper/converter/StringToPeriodConverter.java deleted file mode 100644 index 3ba55ec63..000000000 --- a/spring/src/main/java/net/notejam/spring/helper/converter/StringToPeriodConverter.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.notejam.spring.helper.converter; - -import java.time.Period; - -import org.springframework.core.convert.converter.Converter; - -/** - * Converts an ISO-8601 period into a Period. - * - * @author markus@malkusch.de - * @see Donations - */ -public final class StringToPeriodConverter implements Converter { - - @Override - public Period convert(final String period) { - return Period.parse(period); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/helper/converter/package-info.java b/spring/src/main/java/net/notejam/spring/helper/converter/package-info.java deleted file mode 100644 index 61f93a537..000000000 --- a/spring/src/main/java/net/notejam/spring/helper/converter/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides type converters. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.helper.converter; diff --git a/spring/src/main/java/net/notejam/spring/helper/reflection/Annotated.java b/spring/src/main/java/net/notejam/spring/helper/reflection/Annotated.java deleted file mode 100644 index b77d46ffe..000000000 --- a/spring/src/main/java/net/notejam/spring/helper/reflection/Annotated.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.notejam.spring.helper.reflection; - -import java.lang.annotation.Annotation; - -/** - * Representation of an annotated object. - * - * @author markus@malkusch.de - * @see Donations - * - * @param The annotated object type. - * @param The annotation. - */ -public final class Annotated { - - /** - * The annotation. - */ - private T annotation; - - /** - * The annotated object. - */ - private K object; - - /** - * Returns the annotation. - * - * @return The annotation. - */ - public T getAnnotation() { - return annotation; - } - - /** - * Sets the annotation. - * - * @param annotation The annotation. - */ - public void setAnnotation(final T annotation) { - this.annotation = annotation; - } - - /** - * Returns the annotated object. - * - * @return The annotated object. - */ - public K getObject() { - return object; - } - - /** - * Sets the annotated object. - * - * @param object The annotated object. - */ - public void setObject(final K object) { - this.object = object; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/helper/reflection/ReflectionUtils.java b/spring/src/main/java/net/notejam/spring/helper/reflection/ReflectionUtils.java deleted file mode 100644 index 3c4a3fd9e..000000000 --- a/spring/src/main/java/net/notejam/spring/helper/reflection/ReflectionUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -package net.notejam.spring.helper.reflection; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.reflect.MethodSignature; - -/** - * Reflection utils. - * - * @author markus@malkusch.de - * @see Donations - */ -public final class ReflectionUtils { - - /** - * No public constructor for this utility class. - */ - private ReflectionUtils() { - } - - /** - * Returns a list of arguments which have a given annotation. - * - * @param annotation - * The annotation - * @param joinPoint - * The join point - * @param - * The annotation. - * @param

- * The annotated object type. - * - * @return The matching objects. - */ - public static List> getAnnotatedArguments(final Class annotation, - final JoinPoint joinPoint) { - Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); - Object[] arguments = joinPoint.getArgs(); - return getAnnotatedArguments(annotation, method, arguments); - } - - /** - * Returns a list of arguments which have a given annotation. - * - * @param annotation - * The annotation - * @param method - * The method - * @param arguments - * The method arguments - * @param - * The annotation. - * @param

- * The annotated object type. - * - * @return The matching objects. - */ - @SuppressWarnings("unchecked") - public static List> getAnnotatedArguments(final Class annotation, - final Method method, final Object[] arguments) { - List> match = new ArrayList<>(); - int i = 0; - for (Annotation[] annotations : method.getParameterAnnotations()) { - for (Annotation paramAnotation : annotations) { - if (annotation.isAssignableFrom(paramAnotation.annotationType())) { - Annotated annotated = new Annotated<>(); - annotated.setAnnotation((T) paramAnotation); - annotated.setObject((P) arguments[i]); - match.add(annotated); - - } - } - i++; - } - return match; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/helper/reflection/package-info.java b/spring/src/main/java/net/notejam/spring/helper/reflection/package-info.java deleted file mode 100644 index 54784da6c..000000000 --- a/spring/src/main/java/net/notejam/spring/helper/reflection/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides reflection utilities. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.helper.reflection; diff --git a/spring/src/main/java/net/notejam/spring/note/Note.java b/spring/src/main/java/net/notejam/spring/note/Note.java deleted file mode 100644 index 5157a5129..000000000 --- a/spring/src/main/java/net/notejam/spring/note/Note.java +++ /dev/null @@ -1,153 +0,0 @@ -package net.notejam.spring.note; - -import java.time.Instant; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.data.jpa.domain.AbstractPersistable; - -import net.notejam.spring.pad.Pad; -import net.notejam.spring.security.owner.Owned; -import net.notejam.spring.user.User; - -/** - * The note. - * - * @author markus@malkusch.de - * @see Donations - */ -@Entity -@Table(indexes = { @Index(columnList = "updated"), @Index(columnList = "name") }) -public class Note extends AbstractPersistableimplements Owned { - - private static final long serialVersionUID = -1445367127777923455L; - - /** - * The last update time. - */ - @NotNull - private Instant updated; - - /** - * The owner. - */ - @ManyToOne - @NotNull - private User user; - - /** - * The pad. - */ - @ManyToOne - private Pad pad; - - /** - * The name. - */ - @NotEmpty - @Size(max = 100) - private String name; - - /** - * The text. - */ - @NotEmpty - @Lob - @Column(length = 10000) - private String text; - - /** - * Returns the name. - * - * @return The name. - */ - public String getName() { - return name; - } - - /** - * Sets the name. - * - * @param name The name. - */ - public void setName(final String name) { - this.name = name; - } - - /** - * Returns the text. - * - * @return The text - */ - public String getText() { - return text; - } - - /** - * Sets the text. - * - * @param text The text. - */ - public void setText(final String text) { - this.text = text; - } - - /** - * Returns the pad. - * - * @return The pad or null. - */ - public Pad getPad() { - return pad; - } - - /** - * Sets the pad. - * - * @param pad The pad or null. - */ - public void setPad(final Pad pad) { - this.pad = pad; - } - - /** - * Sets the owner. - * - * @param user The owner. - */ - public void setUser(final User user) { - this.user = user; - } - - @Override - public User getUser() { - return user; - } - - /** - * Returns the last update time. - * - * @return The time. - */ - public Instant getUpdated() { - return updated; - } - - /** - * Sets the last update time. - * - * @param updated The time. - */ - public void setUpdated(final Instant updated) { - this.updated = updated; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/NoteRepository.java b/spring/src/main/java/net/notejam/spring/note/NoteRepository.java deleted file mode 100644 index c5eea0950..000000000 --- a/spring/src/main/java/net/notejam/spring/note/NoteRepository.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.notejam.spring.note; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; - -import net.notejam.spring.pad.Pad; -import net.notejam.spring.user.User; - -/** - * The note repository. - * - * @author markus@malkusch.de - * @see Donations - */ -interface NoteRepository extends JpaRepository { - - /** - * Pages through all notes of a pad. - * - * @param pad - * The pad - * @param pageable - * The paging parameters - * @return The notes - */ - Page findByPad(Pad pad, Pageable pageable); - - /** - * Pages through all notes of a user. - * - * @param user - * The user - * @param pageable - * The paging parameters - * @return The notes - */ - Page findByUser(User user, Pageable pageable); - - /** - * Deletes all notes of a pad. - * - * @param pad - * The pad - */ - void deleteByPad(Pad pad); - -} diff --git a/spring/src/main/java/net/notejam/spring/note/NoteService.java b/spring/src/main/java/net/notejam/spring/note/NoteService.java deleted file mode 100644 index 6edd0f6a3..000000000 --- a/spring/src/main/java/net/notejam/spring/note/NoteService.java +++ /dev/null @@ -1,142 +0,0 @@ -package net.notejam.spring.note; - -import java.time.Instant; -import java.util.Optional; - -import javax.transaction.Transactional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; - -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.security.owner.PermitOwner; -import net.notejam.spring.user.UserService; - -/** - * The note service. - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public class NoteService { - - /** - * The note repository. - */ - @Autowired - private NoteRepository repository; - - /** - * The pad service. - */ - @Autowired - private PadService padService; - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * Loads a note from the storage. - * - * @param id - * The note id - * @return The note - */ - @PermitOwner - public Optional getNote(final int id) { - return Optional.ofNullable(repository.findOne(id)); - } - - /** - * Pages through all notes. - * - * @param pageable - * The paging parameters - * @return The notes - */ - @Transactional - public Page getNotes(final Pageable pageable) { - return repository.findByUser(userService.getAuthenticatedUser(), pageable); - } - - /** - * Pages through all notes of a pad. - * - * @param pad - * The pad - * @param pageable - * The paging parameters - * @return The notes - */ - @Transactional - public Page getPadNotes(@PermitOwner final Pad pad, final Pageable pageable) { - return repository.findByPad(pad, pageable); - } - - /** - * Builds a new empty note. - * - * The note is not save yet. Use {@link #createNote(Note)} to save it. - * - * @param padId - * The preselected pad. - * - * @return The new note - */ - public Note buildNote(final Integer padId) { - Note note = new Note(); - note.setUpdated(Instant.now()); - note.setUser(userService.getAuthenticatedUser()); - - if (padId != null) { - note.setPad(padService.getPad(padId).get()); - } - - return note; - } - - /** - * Saves a new new note. - * - * @param note - * The new note - * @param pad - * The optional pad to which this note will belong, or null - */ - @Transactional - public void saveNote(@PermitOwner final Note note, @PermitOwner final Pad pad) { - note.setPad(pad); - note.setUpdated(Instant.now()); - repository.save(note); - } - - /** - * Deletes a note. - * - * @param note - * The note - */ - @Transactional - public void deleteNote(@PermitOwner final Note note) { - repository.delete(note); - } - - /** - * Deletes all notes of a pad. - * - * @param pad - * The pad - */ - @Transactional - public void deleteNotes(@PermitOwner final Pad pad) { - repository.deleteByPad(pad); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/AllNotesController.java b/spring/src/main/java/net/notejam/spring/note/controller/AllNotesController.java deleted file mode 100644 index dd2072baf..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/AllNotesController.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.notejam.spring.note.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * A controller to show all notes. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@PreAuthorize("isAuthenticated()") -@Pads -public class AllNotesController { - - /** - * The note service. - */ - @Autowired - private NoteService noteService; - - /** - * Provide the model attribute "notes". - * - * @param pageable The paging. - * @return The model attribute "notes". - */ - @ModelAttribute("notes") - public Page notes(@PageableDefault(10) final Pageable pageable) { - return noteService.getNotes(pageable); - } - - /** - * Shows all notes. - * - * @return The view. - */ - @RequestMapping(URITemplates.VIEW_ALL_NOTES) - public String showAllNotes() { - return "notes"; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/CreateNoteController.java b/spring/src/main/java/net/notejam/spring/note/controller/CreateNoteController.java deleted file mode 100644 index 1c83c10df..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/CreateNoteController.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.notejam.spring.note.controller; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The create note controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.CREATE_NOTE) -@PreAuthorize("isAuthenticated()") -@Pads -public class CreateNoteController { - - /** - * The note service. - */ - @Autowired - private NoteService service; - - /** - * Provides the model attribute "note". - * - * @param padId - * The preselected pad id. - * @return The model attribute "note". - */ - @ModelAttribute - public Note note(@RequestParam(value = "pad", required = false) final Integer padId) { - return service.buildNote(padId); - } - - /** - * Shows the form for creating a note. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String showCreateNoteForm() { - return "note/create"; - } - - /** - * Creates a new note. - * - * @param note - * The model attribute "note". - * @param bindingResult - * The validation result. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String createNote(@Valid final Note note, final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "note/create"; - } - - service.saveNote(note, note.getPad()); - - return String.format("redirect:%s", buildCreatedNoteUri(note.getId())); - } - - /** - * Builds the URI for the created note. - * - * @param id - * The note id - * @return The URI - */ - private static String buildCreatedNoteUri(final int id) { - UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(URITemplates.VIEW_NOTE); - uriBuilder.queryParam("successful"); - return uriBuilder.buildAndExpand(id).toUriString(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/DeleteNoteController.java b/spring/src/main/java/net/notejam/spring/note/controller/DeleteNoteController.java deleted file mode 100644 index 76e17c08c..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/DeleteNoteController.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.notejam.spring.note.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The delete note controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.DELETE_NOTE) -@PreAuthorize("isAuthenticated()") -@Pads -public class DeleteNoteController { - - /** - * The note service. - */ - @Autowired - private NoteService service; - - /** - * Provides the model attribute "note". - * - * @param id - * The note id. - * @return The model attribute "note". - */ - @ModelAttribute - public Note note(@PathVariable("id") final int id) { - return service.getNote(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Shows the confirmation for deleting a note. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String confirmDeleteNote() { - return "note/delete"; - } - - /** - * Deletes a note. - * - * @param note - * The note. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String deleteNote(final Note note) { - service.deleteNote(note); - return String.format("redirect:%s?deleted", URITemplates.CREATE_NOTE); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/EditNoteController.java b/spring/src/main/java/net/notejam/spring/note/controller/EditNoteController.java deleted file mode 100644 index 07138c5ee..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/EditNoteController.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.notejam.spring.note.controller; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The edit note controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.EDIT_NOTE) -@PreAuthorize("isAuthenticated()") -@Pads -public class EditNoteController { - - /** - * The note service. - */ - @Autowired - private NoteService service; - - /** - * Provides the model attribute "note". - * - * @param id - * The note id. - * @return The model attribute "note". - */ - @ModelAttribute - public Note note(@PathVariable("id") final int id) { - return service.getNote(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Shows the form for editing a note. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String showEditNoteForm() { - return "note/edit"; - } - - /** - * Edits a new note. - * - * @param note - * The note. - * @param bindingResult - * The validation result. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String editNote(@Valid final Note note, final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "note/edit"; - } - - service.saveNote(note, note.getPad()); - - return String.format("redirect:%s", buildEditedNoteUri(note.getId())); - } - - /** - * Builds the URI for the edited note. - * - * @param id - * The note id - * @return The URI - */ - private static String buildEditedNoteUri(final int id) { - UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(URITemplates.VIEW_NOTE); - uriBuilder.queryParam("successful"); - return uriBuilder.buildAndExpand(id).toUriString(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/ViewNoteController.java b/spring/src/main/java/net/notejam/spring/note/controller/ViewNoteController.java deleted file mode 100644 index 630fed19c..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/ViewNoteController.java +++ /dev/null @@ -1,55 +0,0 @@ -package net.notejam.spring.note.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The view note controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@PreAuthorize("isAuthenticated()") -@Pads -public class ViewNoteController { - - /** - * The note service. - */ - @Autowired - private NoteService service; - - /** - * Provides the model attribute "note". - * - * @param id - * The note id. - * @return The model attribute "note". - */ - @ModelAttribute - public Note note(@PathVariable("id") final int id) { - return service.getNote(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Shows the note - * - * @return The note view - */ - @RequestMapping(URITemplates.VIEW_NOTE) - public String viewNote() { - return "note/view"; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/note/controller/package-info.java b/spring/src/main/java/net/notejam/spring/note/controller/package-info.java deleted file mode 100644 index 3512dc654..000000000 --- a/spring/src/main/java/net/notejam/spring/note/controller/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides the note controllers. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.note.controller; diff --git a/spring/src/main/java/net/notejam/spring/note/package-info.java b/spring/src/main/java/net/notejam/spring/note/package-info.java deleted file mode 100644 index 3d6a23d5c..000000000 --- a/spring/src/main/java/net/notejam/spring/note/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the note domain. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.note; diff --git a/spring/src/main/java/net/notejam/spring/package-info.java b/spring/src/main/java/net/notejam/spring/package-info.java deleted file mode 100644 index 9f7890379..000000000 --- a/spring/src/main/java/net/notejam/spring/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * The Notejam spring implementation. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring; diff --git a/spring/src/main/java/net/notejam/spring/pad/Pad.java b/spring/src/main/java/net/notejam/spring/pad/Pad.java deleted file mode 100644 index 656b80441..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/Pad.java +++ /dev/null @@ -1,100 +0,0 @@ -package net.notejam.spring.pad; - -import java.time.Instant; - -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.data.jpa.domain.AbstractPersistable; - -import net.notejam.spring.security.owner.Owned; -import net.notejam.spring.user.User; - -/** - * The pad groups notes. - * - * @author markus@malkusch.de - * @see Donations - */ -@Entity -@Table(indexes = @Index(columnList = "created")) -public class Pad extends AbstractPersistableimplements Owned { - - private static final long serialVersionUID = -1186217744141902841L; - - /** - * The time of creation. - */ - @NotNull - private Instant created; - - /** - * The name. - */ - @Size(max = 100) - @NotEmpty - private String name; - - /** - * The owner. - */ - @ManyToOne - @NotNull - private User user; - - /** - * Returns time of creation. - * - * @return time of creation. - */ - public Instant getCreated() { - return created; - } - - /** - * Sets the time of creation. - * - * @param created The time of creation. - */ - public void setCreated(final Instant created) { - this.created = created; - } - - /** - * Returns the name. - * - * @return The name. - */ - public String getName() { - return name; - } - - /** - * Sets the name. - * - * @param name The name. - */ - public void setName(final String name) { - this.name = name; - } - - /** - * Sets the owner. - * - * @param user The owner. - */ - public void setUser(final User user) { - this.user = user; - } - - @Override - public User getUser() { - return user; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/PadRepository.java b/spring/src/main/java/net/notejam/spring/pad/PadRepository.java deleted file mode 100644 index e46822d73..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/PadRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.notejam.spring.pad; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -import net.notejam.spring.user.User; - -/** - * The pad repository. - * - * @author markus@malkusch.de - * @see Donations - */ -interface PadRepository extends JpaRepository { - - /** - * Returns all pads for a user. - * - * @param user - * The user - * @return The user's pads - */ - List findByUser(User user); - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/PadService.java b/spring/src/main/java/net/notejam/spring/pad/PadService.java deleted file mode 100644 index cb0be95ad..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/PadService.java +++ /dev/null @@ -1,106 +0,0 @@ -package net.notejam.spring.pad; - -import java.time.Instant; -import java.util.List; -import java.util.Optional; - -import javax.transaction.Transactional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import net.notejam.spring.note.NoteService; -import net.notejam.spring.security.owner.PermitOwner; -import net.notejam.spring.user.User; -import net.notejam.spring.user.UserService; - -/** - * The pad service. - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public class PadService { - - /** - * The pad repository. - */ - @Autowired - private PadRepository padRepository; - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * The note service. - */ - @Autowired - private NoteService noteService; - - /** - * Returns all pads for the currently authenticated user. - * - * @return The user's pads - */ - @Transactional - public List getAllPads() { - User user = userService.getAuthenticatedUser(); - return padRepository.findByUser(user); - } - - /** - * Loads a pad from the storage. - * - * @param id - * The pad id - * @return The pad - */ - @PermitOwner - public Optional getPad(final int id) { - return Optional.ofNullable(padRepository.findOne(id)); - } - - /** - * Deletes a pad and its notes. - * - * @param pad - * The pad - */ - @Transactional - public void deletePad(@PermitOwner final Pad pad) { - noteService.deleteNotes(pad); - padRepository.delete(pad); - } - - /** - * Builds a new pad with an empty name. - * - * The pad is not save yet. Use {@link #savePad(Pad)} to save it. - * - * @return The new pad - */ - public Pad buildPad() { - Pad pad = new Pad(); - pad.setCreated(Instant.now()); - pad.setUser(userService.getAuthenticatedUser()); - return pad; - } - - /** - * Safes a pad. - * - * The pad should be created with {@link #buildPad()}. - * - * @param pad - * The unsaved pad. - */ - @Transactional - public void savePad(@PermitOwner final Pad pad) { - padRepository.save(pad); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/CreatePadController.java b/spring/src/main/java/net/notejam/spring/pad/controller/CreatePadController.java deleted file mode 100644 index 4a48dadac..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/CreatePadController.java +++ /dev/null @@ -1,90 +0,0 @@ -package net.notejam.spring.pad.controller; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The create pad controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.CREATE_PAD) -@PreAuthorize("isAuthenticated()") -@Pads -public class CreatePadController { - - /** - * The pad service. - */ - @Autowired - private PadService service; - - /** - * Provides the model attribute "pad". - * - * @return The model attribute "pad". - */ - @ModelAttribute - public Pad pad() { - return service.buildPad(); - } - - /** - * Shows the form for creating a pad. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String showCreatePadForm() { - return "pad/create"; - } - - /** - * Creates a new pad. - * - * @param pad - * The pad. - * @param bindingResult - * The validation result. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String createPad(@Valid final Pad pad, final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "pad/create"; - } - - service.savePad(pad); - - return String.format("redirect:%s", buildCreatedPadUri(pad.getId())); - } - - /** - * Builds the URI for the created pad. - * - * @param id - * The pad id - * @return The URI - */ - private static String buildCreatedPadUri(final int id) { - UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(URITemplates.VIEW_PAD); - uriBuilder.queryParam("createdSuccessfully"); - return uriBuilder.buildAndExpand(id).toUriString(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/DeletePadController.java b/spring/src/main/java/net/notejam/spring/pad/controller/DeletePadController.java deleted file mode 100644 index cd3532fc2..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/DeletePadController.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.notejam.spring.pad.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The delete pad controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.DELETE_PAD) -@PreAuthorize("isAuthenticated()") -@Pads -public class DeletePadController { - - /** - * The pad service. - */ - @Autowired - private PadService service; - - /** - * Provides the model attribute "pad". - * - * @param id - * The pad id. - * @return The model attribute "pad". - */ - @ModelAttribute - public Pad pad(@PathVariable("id") final int id) { - return service.getPad(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Shows the confirmation for deleting a pad. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String confirmDeletePad() { - return "pad/delete"; - } - - /** - * Deletes a pad and its notes. - * - * @param pad - * The pad. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String deletePad(final Pad pad) { - service.deletePad(pad); - return String.format("redirect:%s?deleted", URITemplates.CREATE_PAD); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/EditPadController.java b/spring/src/main/java/net/notejam/spring/pad/controller/EditPadController.java deleted file mode 100644 index d8754127b..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/EditPadController.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.notejam.spring.pad.controller; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The edit pad controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.EDIT_PAD) -@PreAuthorize("isAuthenticated()") -@Pads -public class EditPadController { - - /** - * The pad service. - */ - @Autowired - private PadService service; - - /** - * Provides the model attribute "pad". - * - * @param id - * The pad id. - * @return The model attribute "pad". - */ - @ModelAttribute - public Pad pad(@PathVariable("id") final int id) { - return service.getPad(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Shows the form for creating a pad. - * - * @return The view - */ - @RequestMapping(method = RequestMethod.GET) - public String showCreatePadForm() { - return "pad/edit"; - } - - /** - * Shows the form for creating a pad. - * - * @param pad - * the Pad - * @param bindingResult - * The validation result. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String editPad(@Valid final Pad pad, final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "pad/edit"; - } - - service.savePad(pad); - - return String.format("redirect:%s", buildEditedPadUri(pad.getId())); - } - - /** - * Builds the URI for the edited pad. - * - * @param id - * The pad id - * @return The URI - */ - private static String buildEditedPadUri(final int id) { - UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath(URITemplates.EDIT_PAD); - uriBuilder.queryParam("success"); - return uriBuilder.buildAndExpand(id).toUriString(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/PadsAdvice.java b/spring/src/main/java/net/notejam/spring/pad/controller/PadsAdvice.java deleted file mode 100644 index 741195602..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/PadsAdvice.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.notejam.spring.pad.controller; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ModelAttribute; - -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * Pads controller advice. - * - * This controller advice provides all pads of the authenticated user for the - * view as the model attribute pads. - * - * @author markus@malkusch.de - * @see Donations - */ -@ControllerAdvice(annotations = Pads.class) -@PreAuthorize("isAuthenticated()") -public class PadsAdvice { - - /** - * Provide all pads of the authenticated user as the model attribute pads. - * - * @author markus@malkusch.de - * @see Donations - */ - @Retention(RetentionPolicy.RUNTIME) - @Target({ ElementType.TYPE }) - public static @interface Pads { - - } - - /** - * The pad service. - */ - @Autowired - private PadService service; - - /** - * Provides the model attribute "pads". I.e. all pads of the currently - * authenticated user. - * - * @return The model attribute "pads". - */ - @ModelAttribute("pads") - public List pads() { - return service.getAllPads(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/ViewPadNotesController.java b/spring/src/main/java/net/notejam/spring/pad/controller/ViewPadNotesController.java deleted file mode 100644 index 2216670dc..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/ViewPadNotesController.java +++ /dev/null @@ -1,83 +0,0 @@ -package net.notejam.spring.pad.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.error.ResourceNotFoundException; -import net.notejam.spring.note.Note; -import net.notejam.spring.note.NoteService; -import net.notejam.spring.pad.Pad; -import net.notejam.spring.pad.PadService; -import net.notejam.spring.pad.controller.PadsAdvice.Pads; - -/** - * The view pad notes controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@PreAuthorize("isAuthenticated()") -@Pads -public class ViewPadNotesController { - - /** - * The pad service. - */ - @Autowired - private PadService padService; - - /** - * The note service. - */ - @Autowired - private NoteService noteService; - - /** - * Provides the model attribute "pad". - * - * @param id - * The pad id. - * @return The model attribute "pad". - */ - @ModelAttribute - public Pad pad(@PathVariable("id") final int id) { - return padService.getPad(id).orElseThrow(() -> new ResourceNotFoundException()); - } - - /** - * Provides the model attribute "notes". Notes are all notes of the model - * attribute "pad". - * - * @param pad - * The pad. - * @param pageable - * The paging. - * @return The model attribute "notes". - */ - @ModelAttribute("notes") - public Page notes(@ModelAttribute final Pad pad, @PageableDefault(10) final Pageable pageable) { - return noteService.getPadNotes(pad, pageable); - } - - /** - * Shows the pad notes - * - * @param pad - * The pad. - * @return The pad notes view - */ - @RequestMapping(URITemplates.VIEW_PAD) - public String viewPadNotes(final Pad pad) { - return "notes"; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/pad/controller/package-info.java b/spring/src/main/java/net/notejam/spring/pad/controller/package-info.java deleted file mode 100644 index 8258fd8d1..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/controller/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides the pad controllers. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.pad.controller; diff --git a/spring/src/main/java/net/notejam/spring/pad/package-info.java b/spring/src/main/java/net/notejam/spring/pad/package-info.java deleted file mode 100644 index e839df06e..000000000 --- a/spring/src/main/java/net/notejam/spring/pad/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the pad domain. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.pad; diff --git a/spring/src/main/java/net/notejam/spring/security/LoginController.java b/spring/src/main/java/net/notejam/spring/security/LoginController.java deleted file mode 100644 index 3bc0fcecf..000000000 --- a/spring/src/main/java/net/notejam/spring/security/LoginController.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.notejam.spring.security; - -import org.springframework.stereotype.Controller; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -import net.notejam.spring.URITemplates; - -/** - * Login controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -public class LoginController extends WebMvcConfigurerAdapter { - - @Override - public void addViewControllers(final ViewControllerRegistry registry) { - registry.addViewController(URITemplates.SIGNIN).setViewName("user/login"); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/security/SecurityConfiguration.java b/spring/src/main/java/net/notejam/spring/security/SecurityConfiguration.java deleted file mode 100644 index ba5f3476d..000000000 --- a/spring/src/main/java/net/notejam/spring/security/SecurityConfiguration.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.notejam.spring.security; - -import java.security.SecureRandom; -import java.util.Random; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; - -import net.notejam.spring.URITemplates; - -/** - * Configures the Spring Security framework. - * - * @author markus@malkusch.de - * @see Donations - */ -@Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableWebSecurity -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - /** - * The user details service. - */ - @Autowired - private UserDetailsService userDetailsService; - - @Override - protected void configure(final HttpSecurity http) throws Exception { - http.formLogin().loginPage(URITemplates.SIGNIN); - http.logout().logoutRequestMatcher(new AntPathRequestMatcher(URITemplates.SIGNOUT)); - } - - /** - * Sets the password encoder. - * - * @param auth The authentication manager builder. - */ - @Autowired - public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); - } - - /** - * Provides the password encoder. - * - * @return The password encoder. - */ - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - /** - * Provides a shared source of random. - * - * @return The random instance. - */ - @Bean - public Random random() { - return new SecureRandom(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/security/SecurityService.java b/spring/src/main/java/net/notejam/spring/security/SecurityService.java deleted file mode 100644 index 22db6ad24..000000000 --- a/spring/src/main/java/net/notejam/spring/security/SecurityService.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.notejam.spring.security; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; - -import net.notejam.spring.user.User; - -/** - * Security service. - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public final class SecurityService { - - /** - * The password encoder. - */ - private final PasswordEncoder encoder; - - /** - * Sets the password encoder. - * - * @param encoder - * The password encoder - */ - @Autowired - SecurityService(final PasswordEncoder encoder) { - this.encoder = encoder; - } - - /** - * Returns true if a password is valid for a user. - * - * @param user - * The user - * @param password - * The plain text password - * @return True if the password is valid. - */ - public boolean isPasswordValid(final User user, final String password) { - return encoder.matches(password, user.getPassword()); - } - - /** - * Encodes a plain text password for storage. - * - * @param password - * The plain password - * @return The encoded password - */ - public String encodePassword(final String password) { - return encoder.encode(password); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/security/UserDetailsServiceImpl.java b/spring/src/main/java/net/notejam/spring/security/UserDetailsServiceImpl.java deleted file mode 100644 index afca6ccaa..000000000 --- a/spring/src/main/java/net/notejam/spring/security/UserDetailsServiceImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.notejam.spring.security; - -import java.util.ArrayList; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; - -import net.notejam.spring.user.UserRepository; - -/** - * UserDetailsService Implementation - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public class UserDetailsServiceImpl implements UserDetailsService { - - /** - * The user repository. - */ - @Autowired - private UserRepository repository; - - @Override - public UserDetails loadUserByUsername(final String username) { - String password = repository.findOneByEmail(username) - .orElseThrow(() -> new UsernameNotFoundException(String.format("%s not found", username))) - .getPassword(); - return new User(username, password, new ArrayList<>()); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/security/owner/Owned.java b/spring/src/main/java/net/notejam/spring/security/owner/Owned.java deleted file mode 100644 index d451e2308..000000000 --- a/spring/src/main/java/net/notejam/spring/security/owner/Owned.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.notejam.spring.security.owner; - -import net.notejam.spring.user.User; - -/** - * An entity which has a user as its owner. - * - * @author markus@malkusch.de - * - * @see Donations - * @see PermitOwner - */ -public interface Owned { - - /** - * Returns the owner of this entity. - * - * @return The owner - */ - User getUser(); - -} diff --git a/spring/src/main/java/net/notejam/spring/security/owner/PermitOwner.java b/spring/src/main/java/net/notejam/spring/security/owner/PermitOwner.java deleted file mode 100644 index ef647ba32..000000000 --- a/spring/src/main/java/net/notejam/spring/security/owner/PermitOwner.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.notejam.spring.security.owner; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Grant access only to the authenticated owner of this object. - * - * @author markus@malkusch.de - * - * @see Donations - * @see Owned - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.PARAMETER, ElementType.METHOD }) -public @interface PermitOwner { - -} diff --git a/spring/src/main/java/net/notejam/spring/security/owner/PermitOwnerAspect.java b/spring/src/main/java/net/notejam/spring/security/owner/PermitOwnerAspect.java deleted file mode 100644 index c4aaed2a8..000000000 --- a/spring/src/main/java/net/notejam/spring/security/owner/PermitOwnerAspect.java +++ /dev/null @@ -1,126 +0,0 @@ -package net.notejam.spring.security.owner; - -import java.util.Optional; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; -import org.springframework.security.access.AccessDeniedException; - -import net.notejam.spring.helper.reflection.Annotated; -import net.notejam.spring.helper.reflection.ReflectionUtils; -import net.notejam.spring.user.User; -import net.notejam.spring.user.UserService; - -/** - * Grant access only to the authenticated owner of an object. - * - * @author markus@malkusch.de - * - * @see Donations - * @see Owned - * @see PermitOwner - */ -@Aspect -@Configurable -public class PermitOwnerAspect { - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * Sets the user service. - * - * @param userService - * The user service - */ - void setUserService(final UserService userService) { - this.userService = userService; - } - - /** - * The point cut for method arguments. - */ - @Pointcut("execution(* *(.., @PermitOwner (*), ..))") - private static void restrictOwnedEntities() { - // This is a pointcut. - } - - /** - * Checks method calls with owned arguments. - * - * @param joinPoint - * The joint point. - */ - @Before("net.notejam.spring.security.owner.PermitOwnerAspect.restrictOwnedEntities()") - public void authorizeCall(final JoinPoint joinPoint) { - for (Annotated annotated : ReflectionUtils - . getAnnotatedArguments(PermitOwner.class, joinPoint)) { - if (annotated.getObject() == null) { - continue; - - } - authorize(annotated.getObject()); - - } - } - - /** - * The point cut for return values. - */ - @Pointcut("execution(@PermitOwner * *(..))") - private static void restrictOwnedResults() { - // This is a pointcut. - } - - /** - * Checks return owned return values. - * - * @param entity - * The owned entity. - */ - @AfterReturning(pointcut = "net.notejam.spring.security.owner.PermitOwnerAspect.restrictOwnedResults()", returning = "entity") - public void authorizeReturn(final Object entity) { - if (entity instanceof Owned) { - authorize((Owned) entity); - - } else if (entity instanceof Optional) { - authorize(((Optional) entity).orElse(null)); - } - } - - /** - * Checks authorization of an owned entity. - * - * If the entity is null authorization is granted. - * - * @param owned - * The owned entity or null. - */ - private void authorize(final Owned owned) { - if (owned == null) { - return; - } - - User user = userService.getAuthenticatedUser(); - if (user == null) { - throw new AccessDeniedException(String.format("%s needs an authenticated user.", owned)); - } - - if (user.equals(owned.getUser())) { - return; - - } else { - throw new AccessDeniedException(String.format("User %s is not allowed to access object of user %s.", - user.getId(), owned.getUser().getId())); - } - } - -} diff --git a/spring/src/main/java/net/notejam/spring/security/owner/package-info.java b/spring/src/main/java/net/notejam/spring/security/owner/package-info.java deleted file mode 100644 index b095d2ad8..000000000 --- a/spring/src/main/java/net/notejam/spring/security/owner/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for ownership authorization. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.security.owner; diff --git a/spring/src/main/java/net/notejam/spring/security/package-info.java b/spring/src/main/java/net/notejam/spring/security/package-info.java deleted file mode 100644 index 602c5ee6b..000000000 --- a/spring/src/main/java/net/notejam/spring/security/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the security domain. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.security; diff --git a/spring/src/main/java/net/notejam/spring/user/User.java b/spring/src/main/java/net/notejam/spring/user/User.java deleted file mode 100644 index eb2b7c05e..000000000 --- a/spring/src/main/java/net/notejam/spring/user/User.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.notejam.spring.user; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.validation.constraints.NotNull; - -import org.springframework.data.jpa.domain.AbstractPersistable; -import org.springframework.security.crypto.password.PasswordEncoder; - -/** - * The user. - * - * @author markus@malkusch.de - * @see Donations - */ -@Entity -public class User extends AbstractPersistable { - - private static final long serialVersionUID = -7874055769861590146L; - - /** - * The email address. - */ - @NotNull - @Column(unique = true) - private String email; - - /** - * The password. - */ - @NotNull - private String password; - - /** - * Sets the password. - * - * The password should be persisted as an encoded string by an - * {@link PasswordEncoder}. - * - * @param password - * The password. - */ - public void setPassword(final String password) { - this.password = password; - } - - /** - * Returns the encoded password. - * - * Use a {@link PasswordEncoder} to check authentication. - * - * @return The encoded password. - */ - public String getPassword() { - return this.password; - } - - /** - * Returns the email address. - * - * @return The email address. - */ - public String getEmail() { - return email; - } - - /** - * Sets the email address. - * - * @param email - * The email address. - */ - public void setEmail(final String email) { - this.email = email; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/UserRepository.java b/spring/src/main/java/net/notejam/spring/user/UserRepository.java deleted file mode 100644 index 13fbe36b2..000000000 --- a/spring/src/main/java/net/notejam/spring/user/UserRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.notejam.spring.user; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * The user repository. - * - * @author markus@malkusch.de - * @see Donations - */ -public interface UserRepository extends JpaRepository { - - /** - * Finds one user by its email address. - * - * @param email - * The email. - * @return The user or null - */ - Optional findOneByEmail(String email); - -} diff --git a/spring/src/main/java/net/notejam/spring/user/UserService.java b/spring/src/main/java/net/notejam/spring/user/UserService.java deleted file mode 100644 index 95677673c..000000000 --- a/spring/src/main/java/net/notejam/spring/user/UserService.java +++ /dev/null @@ -1,100 +0,0 @@ -package net.notejam.spring.user; - -import javax.transaction.Transactional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; - -import net.notejam.spring.security.SecurityService; - -/** - * The user service. - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public class UserService { - - /** - * The user repository. - */ - @Autowired - private UserRepository repository; - - /** - * The security service. - */ - @Autowired - private SecurityService securityService; - - /** - * Checks if an email is already registered. - * - * @param email - * The email. - * @return True, if the email is already registered. - */ - public boolean isEmailRegistered(final String email) { - return repository.findOneByEmail(email).isPresent(); - } - - /** - * Returns the authenticated user. - * - * @return The currently authenticated user. - */ - public User getAuthenticatedUser() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - String email = authentication.getName(); - return repository.findOneByEmail(email).get(); - } - - /** - * Sets a new password. - * - * @param password - * The new password - */ - @Transactional - public void changePassword(final String password) { - User user = getAuthenticatedUser(); - changePassword(user, password); - } - - /** - * Sets a new password. - * - * @param user - * The user - * @param password - * The new password - */ - @Transactional - public void changePassword(final User user, final String password) { - user.setPassword(securityService.encodePassword(password)); - repository.save(user); - } - - /** - * Signs up a new user. - * - * @param email - * The email address - * @param password - * The plain text password - * - * @return The signed up user - */ - @Transactional - public User signUp(final String email, final String password) { - User user = new User(); - user.setEmail(email); - user.setPassword(securityService.encodePassword(password)); - repository.save(user); - return user; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/account/Account.java b/spring/src/main/java/net/notejam/spring/user/account/Account.java deleted file mode 100644 index d17d6fb8c..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/Account.java +++ /dev/null @@ -1,96 +0,0 @@ -package net.notejam.spring.user.account; - -import javax.validation.constraints.NotNull; - -import org.hibernate.validator.constraints.NotEmpty; - -import de.malkusch.validation.constraints.EqualProperties; -import net.notejam.spring.user.account.constraints.CurrentPassword; -import net.notejam.spring.user.constraints.Password; - -/** - * Account Settings. - * - * @author markus@malkusch.de - * @see Donations - */ -@EqualProperties(value = { "repeatedPassword", "newPassword" }, violationOnPropery = true) -public class Account { - - /** - * The current password. - */ - @NotEmpty - @CurrentPassword - private String currentPassword; - - /** - * The new password. - */ - @Password - private String newPassword; - - /** - * The new and repeated password. - */ - @NotNull - private String repeatedPassword; - - /** - * Returns the current password. - * - * @return The current password. - */ - public String getCurrentPassword() { - return currentPassword; - } - - /** - * Sets the current password. - * - * @param currentPassword - * The current password. - */ - public void setCurrentPassword(final String currentPassword) { - this.currentPassword = currentPassword; - } - - /** - * Returns the new password. - * - * @return The new password. - */ - public String getNewPassword() { - return newPassword; - } - - /** - * Sets the new password. - * - * @param newPassword - * The new password. - */ - public void setNewPassword(final String newPassword) { - this.newPassword = newPassword; - } - - /** - * Returns the new and repeated password. - * - * @return The repeated password. - */ - public String getRepeatedPassword() { - return repeatedPassword; - } - - /** - * Sets the new and repeated password. - * - * @param repeatedPassword - * The new and repeated password. - */ - public void setRepeatedPassword(final String repeatedPassword) { - this.repeatedPassword = repeatedPassword; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/account/AccountController.java b/spring/src/main/java/net/notejam/spring/user/account/AccountController.java deleted file mode 100644 index af2a58099..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/AccountController.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.notejam.spring.user.account; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.user.UserService; - -/** - * An account controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.SETTINGS) -@PreAuthorize("isAuthenticated()") -public class AccountController { - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * Shows the form. - * - * @param account - * The account settings. - * @return The view. - */ - @RequestMapping(method = RequestMethod.GET) - public String showForm(@ModelAttribute("account") final Account account) { - return "user/account"; - } - - /** - * Changes the password. - * - * @param account - * The account settings. - * @param bindingResult - * The validation result - * @return The view. - */ - @RequestMapping(method = RequestMethod.POST) - public String changePassword(@Valid @ModelAttribute("account") final Account account, - final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "user/account"; - } - - userService.changePassword(account.getNewPassword()); - - return String.format("redirect:%s?success", URITemplates.SETTINGS); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPassword.java b/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPassword.java deleted file mode 100644 index 4efec830b..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPassword.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.notejam.spring.user.account.constraints; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import javax.validation.Constraint; -import javax.validation.Payload; -import javax.validation.groups.Default; - -/** - * The password should be valid for the currently authenticated user. - * - * {@link CurrentPasswordValidator} uses a JPA entity manager. I.e. this - * validation should not happen again during a JPA life cycle event (i.e. - * validation during persistence). If this constraint validates an entity, don't - * validate against the {@link Default} validation group. - * - * @author markus@malkusch.de - * @see Donations - */ -@Target(FIELD) -@Retention(RUNTIME) -@Constraint(validatedBy = CurrentPasswordValidator.class) -@Documented -public @interface CurrentPassword { - - /** - * The validation message. - */ - String message() default "{CurrentPassword}"; - - /** - * The validation groups. - */ - Class[]groups() default {}; - - /** - * This constraint doesn't support any validation payload. - */ - Class[]payload() default {}; - -} diff --git a/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPasswordValidator.java b/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPasswordValidator.java deleted file mode 100644 index 4c334d597..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/constraints/CurrentPasswordValidator.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.notejam.spring.user.account.constraints; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; - -import net.notejam.spring.security.SecurityService; -import net.notejam.spring.user.UserService; - -/** - * A password validator. The validator matches the encoded password against the - * currently authenticated user. - * - * @author markus@malkusch.de - * @see Donations - */ -@Configurable -public class CurrentPasswordValidator implements ConstraintValidator { - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * The security service. - */ - @Autowired - private SecurityService securityService; - - @Override - public void initialize(final CurrentPassword constraintAnnotation) { - // Nothing to initialize. - } - - @Override - public boolean isValid(final String password, final ConstraintValidatorContext context) { - if (password == null) { - return true; - } - return securityService.isPasswordValid(userService.getAuthenticatedUser(), password); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/account/constraints/package-info.java b/spring/src/main/java/net/notejam/spring/user/account/constraints/package-info.java deleted file mode 100644 index 90ce3841c..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/constraints/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides account constraints. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.account.constraints; diff --git a/spring/src/main/java/net/notejam/spring/user/account/package-info.java b/spring/src/main/java/net/notejam/spring/user/account/package-info.java deleted file mode 100644 index ec65a57dc..000000000 --- a/spring/src/main/java/net/notejam/spring/user/account/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the account management. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.account; diff --git a/spring/src/main/java/net/notejam/spring/user/constraints/Password.java b/spring/src/main/java/net/notejam/spring/user/constraints/Password.java deleted file mode 100644 index 400c576d9..000000000 --- a/spring/src/main/java/net/notejam/spring/user/constraints/Password.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.notejam.spring.user.constraints; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import javax.validation.Constraint; -import javax.validation.Payload; -import javax.validation.constraints.Size; - -import org.hibernate.validator.constraints.NotEmpty; - -/** - * The password constraints. - * - * @author markus@malkusch.de - * @see Donations - */ -@Target({ METHOD, FIELD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@Documented -@Size(min = 8, max = 128) -@NotEmpty -@Constraint(validatedBy = {}) -public @interface Password { - - /** - * The validation message. - */ - String message() default "{Password}"; - - /** - * The validation groups. - */ - Class[]groups() default {}; - - /** - * This constraint doesn't support any payload. - */ - Class[]payload() default {}; - -} diff --git a/spring/src/main/java/net/notejam/spring/user/constraints/package-info.java b/spring/src/main/java/net/notejam/spring/user/constraints/package-info.java deleted file mode 100644 index 199eeb890..000000000 --- a/spring/src/main/java/net/notejam/spring/user/constraints/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides user constraints. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.constraints; diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPassword.java b/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPassword.java deleted file mode 100644 index 22e214207..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPassword.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.notejam.spring.user.forgot; - -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotEmpty; - -/** - * The forgot password request. - * - * @author markus@malkusch.de - * @see Donations - */ -public class ForgotPassword { - - /** - * The email address. - */ - @Email - @NotEmpty - private String email; - - /** - * Returns the email address. - * - * @return The email address. - */ - public String getEmail() { - return email; - } - - /** - * Sets the email address. - * - * @param email The email address. - */ - public void setEmail(final String email) { - this.email = email; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPasswordController.java b/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPasswordController.java deleted file mode 100644 index 2ee76e561..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/ForgotPasswordController.java +++ /dev/null @@ -1,86 +0,0 @@ -package net.notejam.spring.user.forgot; - -import java.util.Locale; - -import javax.servlet.http.HttpServletRequest; -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; - -/** - * The forgot password controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.FORGOT_PASSWORD) -public class ForgotPasswordController { - - /** - * The recovery service. - */ - @Autowired - private PasswordRecoveryService recoveryService; - - /** - * Shows the form. - * - * @param forgotPassword - * The model attribute. - * @return The view. - */ - @RequestMapping(method = RequestMethod.GET) - public String showForm(@ModelAttribute("forgotPassword") final ForgotPassword forgotPassword) { - return "user/forgot-password"; - } - - /** - * Starts the recovery process. - * - * This will create a token and send an email to finalize the process with - * the token. - * - * @param forgotPassword - * The model attribute with the email address. - * @param bindingResult - * The validation result. - * @param request - * The HTTP request - * @param locale - * The resolved locale - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String startPasswordRecoveryProcess( - @Valid @ModelAttribute("forgotPassword") final ForgotPassword forgotPassword, - final BindingResult bindingResult, final HttpServletRequest request, final Locale locale) { - if (bindingResult.hasErrors()) { - return "user/forgot-password"; - } - - recoveryService.startRecoveryProcess(forgotPassword.getEmail(), buildRequestUriBuilder(request), locale); - - return String.format("redirect:%s?success", URITemplates.FORGOT_PASSWORD); - } - - /** - * Build a UriComponentsBuilder from a request. - * - * @param request - * The request - * @return The request as a UriComponentsBuilder. - */ - private static UriComponentsBuilder buildRequestUriBuilder(final HttpServletRequest request) { - return UriComponentsBuilder.fromUriString(request.getRequestURL().toString()); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/InvalidTokenException.java b/spring/src/main/java/net/notejam/spring/user/forgot/InvalidTokenException.java deleted file mode 100644 index ea24ca31c..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/InvalidTokenException.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.notejam.spring.user.forgot; - -/** - * The token was not valid. - * - * @author markus@malkusch.de - * @see Donations - */ -public class InvalidTokenException extends Exception { - - private static final long serialVersionUID = 6300207371386698201L; - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/PasswordRecoveryService.java b/spring/src/main/java/net/notejam/spring/user/forgot/PasswordRecoveryService.java deleted file mode 100644 index 44cfc90a8..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/PasswordRecoveryService.java +++ /dev/null @@ -1,239 +0,0 @@ -package net.notejam.spring.user.forgot; - -import java.math.BigInteger; -import java.time.Instant; -import java.time.Period; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import java.util.Random; - -import javax.transaction.Transactional; - -import org.apache.commons.lang3.RandomStringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.MessageSource; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; -import org.springframework.web.util.UriComponentsBuilder; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.user.User; -import net.notejam.spring.user.UserRepository; -import net.notejam.spring.user.UserService; - -/** - * Service providing an API for password recovery. - * - * @author markus@malkusch.de - * @see Donations - */ -@Service -public class PasswordRecoveryService { - - /** - * The token repository. - */ - @Autowired - private RecoveryTokenRepository tokenRepository; - - /** - * The user repository. - */ - @Autowired - private UserRepository userRepository; - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * The token life time. - */ - @Value("${recovery.lifetime}") - private Period tokenLifetime; - - /** - * The length of the generated password. - */ - @Value("${recovery.length}") - private int passwordLength; - - /** - * A random instance. - */ - @Autowired - private Random random; - - /** - * The mail sender. - */ - @Autowired(required = false) - private JavaMailSender mailSender; - - /** - * The sender's email address. - */ - @Value("${email.sender}") - private String sender; - - /** - * The message source. - */ - @Autowired - private MessageSource messageSource; - - /** - * The logger. - */ - private static final Logger LOGGER = LoggerFactory.getLogger(PasswordRecoveryService.class); - - /** - * Recovers the password in exchange for a valid token. - * - * @param id - * The token id - * @param token - * The token string - * @return The new password - * @throws InvalidTokenException - * The token was not valid - */ - @Transactional - public String recoverPassword(final int id, final String token) throws InvalidTokenException { - RecoveryToken recoveryToken = tokenRepository - .findOneByIdAndTokenAndExpirationGreaterThan(id, token, Instant.now()) - .orElseThrow(() -> new InvalidTokenException()); - - String password = generatePassword(); - userService.changePassword(recoveryToken.getUser(), password); - tokenRepository.delete(recoveryToken); - return password; - } - - /** - * Generates a random password. - * - * @return The generated password - */ - private String generatePassword() { - return RandomStringUtils.randomAlphanumeric(passwordLength); - } - - /** - * Starts the password recovery process. - * - * If the email doesn't belong to a user the process stops silently. - * - * @param email - * The email - * @param uriBuilder - * A prepared uri builder with the fully qualified host name. - * @param locale - * The locale in which the process should happen - */ - @Async("mailExecutor") - @Transactional - public void startRecoveryProcess(final String email, final UriComponentsBuilder uriBuilder, final Locale locale) { - Optional user = userRepository.findOneByEmail(email); - - if (!user.isPresent()) { - LOGGER.info("Cancel password recovery for non existing user {}", email); - return; - } - - RecoveryToken token = new RecoveryToken(); - token.setUser(user.get()); - token.setToken(generateToken()); - token.setExpiration(determineExpiration()); - tokenRepository.save(token); - - sendRecoveryMail(token, uriBuilder, locale); - } - - /** - * Sends the recovery mail. - * - * @param token - * The recovery token - * @param uriBuilder - * A prepared uri builder with the fully qualified host name. - * @param locale - * The process locale - */ - private void sendRecoveryMail(final RecoveryToken token, final UriComponentsBuilder uriBuilder, - final Locale locale) { - if (mailSender == null) { - LOGGER.warn("Mail transport is not available. Consider setting spring.mail.host in application.properties"); - return; - } - - SimpleMailMessage message = new SimpleMailMessage(); - message.setFrom(sender); - message.setSubject(messageSource.getMessage("forgot.mail.subject", null, locale)); - message.setTo(token.getUser().getEmail()); - - String uri = buildRecoveryURI(token, uriBuilder); - message.setText(messageSource.getMessage("forgot.mail.message", new String[] { uri }, locale)); - - mailSender.send(message); - } - - /** - * Builds the fully qualified URI for recovering the password. - * - * @param token - * The recovery token - * @param uriBuilder - * A prepared uri builder with the fully qualified host name. - * @return The URI to recover the password - */ - private static String buildRecoveryURI(final RecoveryToken token, final UriComponentsBuilder uriBuilder) { - Map uriVariables = new HashMap<>(); - uriVariables.put("id", token.getId().toString()); - uriVariables.put("token", token.getToken()); - - return uriBuilder.replacePath(URITemplates.RECOVER_PASSWORD).buildAndExpand(uriVariables).toUriString(); - } - - /** - * Deletes expired tokens from the storage. - */ - @Transactional - @Scheduled(cron = "59 59 3 * * *") - public void purgeExpired() { - LOGGER.info("Purge expired recovery tokens"); - tokenRepository.deleteByExpirationLessThan(Instant.now()); - } - - /** - * Determines the time when a new token will expire. - * - * @return The expiration time of a new token - */ - private Instant determineExpiration() { - return Instant.now().plus(tokenLifetime); - } - - /** - * Generates a secure random string. - * - * @return A random string - * @see - * How to generate a random alpha-numeric string? - */ - private String generateToken() { - return new BigInteger(130, random).toString(32); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/RecoverPasswordController.java b/spring/src/main/java/net/notejam/spring/user/forgot/RecoverPasswordController.java deleted file mode 100644 index de1b407a8..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/RecoverPasswordController.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.notejam.spring.user.forgot; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; - -import net.notejam.spring.URITemplates; - -/** - * The password recovery controller will reveal the password in exchange for a - * token. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -public class RecoverPasswordController { - - /** - * The recovery service. - */ - @Autowired - private PasswordRecoveryService recoveryService; - - /** - * Shows the password. - * - * @param id - * The token id - * @param token - * The token - * @param password - * The generated password. - * @return The view - * @throws InvalidTokenException - * The token did not match. - */ - @RequestMapping(URITemplates.RECOVER_PASSWORD) - public String revealPassword(@PathVariable("id") final int id, @PathVariable("token") final String token, - @ModelAttribute("password") final StringBuilder password) throws InvalidTokenException { - - password.append(recoveryService.recoverPassword(id, token)); - return "user/reveal-password"; - } - - /** - * Handles non matching tokens. - * - * @return The view. - */ - @ExceptionHandler(InvalidTokenException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - public String handleInvalidToken() { - return "error"; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryToken.java b/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryToken.java deleted file mode 100644 index 523ca3ab4..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryToken.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.notejam.spring.user.forgot; - -import java.time.Instant; - -import javax.persistence.Entity; -import javax.persistence.ManyToOne; -import javax.validation.constraints.Future; -import javax.validation.constraints.NotNull; - -import org.springframework.data.jpa.domain.AbstractPersistable; - -import net.notejam.spring.user.User; - -/** - * The token to authorize a password recovery request. - * - * @author markus@malkusch.de - * @see Donations - */ -@Entity -public class RecoveryToken extends AbstractPersistable { - - private static final long serialVersionUID = 5923083445165411558L; - - /** - * The user. - */ - @NotNull - @ManyToOne - private User user; - - /** - * The token. - */ - @NotNull - private String token; - - /** - * The expiration date. - */ - @NotNull - @Future - private Instant expiration; - - /** - * Returns the date when the token expires. - * - * @return The expiration date. - */ - public Instant getExpiration() { - return expiration; - } - - /** - * Sets the date when the token expires. - * - * @param expiration - * The expiration date. - */ - public void setExpiration(final Instant expiration) { - this.expiration = expiration; - } - - /** - * Returns the user. - * - * @return The user. - */ - public User getUser() { - return user; - } - - /** - * Sets the user. - * - * @param user - * The user. - */ - public void setUser(final User user) { - this.user = user; - } - - /** - * Returns the token. - * - * @return The token. - */ - public String getToken() { - return token; - } - - /** - * Sets the token. - * - * @param token - * The token. - */ - public void setToken(final String token) { - this.token = token; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryTokenRepository.java b/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryTokenRepository.java deleted file mode 100644 index 3c7771c4d..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/RecoveryTokenRepository.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.notejam.spring.user.forgot; - -import java.time.Instant; -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * The token repository. - * - * @author markus@malkusch.de - * @see Donations - */ -public interface RecoveryTokenRepository extends JpaRepository { - - /** - * Deletes all tokens which are expired. - * - * @param date - * The time - */ - void deleteByExpirationLessThan(Instant date); - - /** - * Find a non expired token which matches the id and token. - * - * @param id - * The token id - * @param token - * The token string - * @param time - * The current time - * @return The token - */ - Optional findOneByIdAndTokenAndExpirationGreaterThan(int id, String token, Instant time); - -} diff --git a/spring/src/main/java/net/notejam/spring/user/forgot/package-info.java b/spring/src/main/java/net/notejam/spring/user/forgot/package-info.java deleted file mode 100644 index ec9c5891d..000000000 --- a/spring/src/main/java/net/notejam/spring/user/forgot/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the password recovery process. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.forgot; diff --git a/spring/src/main/java/net/notejam/spring/user/package-info.java b/spring/src/main/java/net/notejam/spring/user/package-info.java deleted file mode 100644 index 46088c616..000000000 --- a/spring/src/main/java/net/notejam/spring/user/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the user domain. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user; diff --git a/spring/src/main/java/net/notejam/spring/user/signup/Signup.java b/spring/src/main/java/net/notejam/spring/user/signup/Signup.java deleted file mode 100644 index ffbc9d698..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/Signup.java +++ /dev/null @@ -1,97 +0,0 @@ -package net.notejam.spring.user.signup; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -import org.hibernate.validator.constraints.Email; -import org.hibernate.validator.constraints.NotEmpty; - -import de.malkusch.validation.constraints.EqualProperties; -import net.notejam.spring.user.constraints.Password; -import net.notejam.spring.user.signup.constraints.UniqueEmail; - -/** - * Sign up form model. - * - * @author markus@malkusch.de - * @see Donations - */ -@EqualProperties(value = { "repeatedPassword", "password" }, violationOnPropery = true) -public class Signup { - - /** - * The email address. - */ - @NotEmpty - @Email - @UniqueEmail - @Size(max = 75) - private String email; - - /** - * The repeated password. - */ - @NotNull - private String repeatedPassword; - - /** - * The password. - */ - @Password - private String password; - - /** - * Returns the email address. - * - * @return The email address. - */ - public String getEmail() { - return email; - } - - /** - * Sets the email address. - * - * @param email The email address. - */ - public void setEmail(final String email) { - this.email = email; - } - - /** - * Sets the password. - * - * @param password The password. - */ - public void setPassword(final String password) { - this.password = password; - } - - /** - * Returns the password. - * - * @return The password. - */ - public String getPassword() { - return this.password; - } - - /** - * Returns the repeated password. - * - * @return The repeated password. - */ - public String getRepeatedPassword() { - return repeatedPassword; - } - - /** - * Sets the repeated password. - * - * @param repeatedPassword The repeated password. - */ - public void setRepeatedPassword(final String repeatedPassword) { - this.repeatedPassword = repeatedPassword; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/signup/SignupController.java b/spring/src/main/java/net/notejam/spring/user/signup/SignupController.java deleted file mode 100644 index afc3c653c..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/SignupController.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.notejam.spring.user.signup; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import net.notejam.spring.URITemplates; -import net.notejam.spring.user.UserService; - -/** - * A sign up controller. - * - * @author markus@malkusch.de - * @see Donations - */ -@Controller -@RequestMapping(URITemplates.SIGNUP) -public class SignupController { - - /** - * The user service. - */ - @Autowired - private UserService userService; - - /** - * Shows the sign up form. - * - * @param user - * The model attribute "user". - * @return The view. - */ - @RequestMapping(method = RequestMethod.GET) - public String showForm(@ModelAttribute("user") final Signup user) { - return "user/signup"; - } - - /** - * Signs up a user. - * - * @param user - * The new user. - * @param bindingResult - * The validation result. - * @return The view - */ - @RequestMapping(method = RequestMethod.POST) - public String signup(@Valid @ModelAttribute("user") final Signup user, final BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "user/signup"; - } - - userService.signUp(user.getEmail(), user.getPassword()); - - return String.format("redirect:%s?signup", URITemplates.SIGNIN); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmail.java b/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmail.java deleted file mode 100644 index 85a01651b..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmail.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.notejam.spring.user.signup.constraints; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import javax.validation.Constraint; -import javax.validation.Payload; -import javax.validation.groups.Default; - -/** - * Validation for a unique email property. - * - * {@link UniqueEmailValidator} uses a JPA entity manager. I.e. this validation - * should not happen again during a JPA life cycle event (i.e. validation during - * persistence). If this constraint validates an entity, don't validate against - * the {@link Default} validation group. - * - * @author markus@malkusch.de - * @see Donations - */ -@Target(FIELD) -@Retention(RUNTIME) -@Constraint(validatedBy = UniqueEmailValidator.class) -@Documented -public @interface UniqueEmail { - - /** - * The validation message. - */ - String message() default "{UniqueEmail}"; - - /** - * The validation groups. - */ - Class[]groups() default {}; - - /** - * This constraint doesn't support any payload. - */ - Class[]payload() default {}; - -} diff --git a/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmailValidator.java b/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmailValidator.java deleted file mode 100644 index f5779a000..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/constraints/UniqueEmailValidator.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.notejam.spring.user.signup.constraints; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; - -import net.notejam.spring.user.UserService; - -/** - * A unique email validator. This validator checks if the given email address - * was already registered. - * - * @author markus@malkusch.de - * @see Donations - */ -@Configurable -public class UniqueEmailValidator implements ConstraintValidator { - - /** - * The user service. - */ - @Autowired - private UserService userService; - - @Override - public void initialize(final UniqueEmail constraintAnnotation) { - // Nothing to initialize. - } - - @Override - public boolean isValid(final String email, final ConstraintValidatorContext context) { - if (email == null) { - return true; - } - return !userService.isEmailRegistered(email); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/user/signup/constraints/package-info.java b/spring/src/main/java/net/notejam/spring/user/signup/constraints/package-info.java deleted file mode 100644 index 87a44b609..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/constraints/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides sign up constraints. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.signup.constraints; diff --git a/spring/src/main/java/net/notejam/spring/user/signup/package-info.java b/spring/src/main/java/net/notejam/spring/user/signup/package-info.java deleted file mode 100644 index ca5dbb5bb..000000000 --- a/spring/src/main/java/net/notejam/spring/user/signup/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the sign up. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.user.signup; diff --git a/spring/src/main/java/net/notejam/spring/view/ViewConfiguration.java b/spring/src/main/java/net/notejam/spring/view/ViewConfiguration.java deleted file mode 100644 index 880e756a8..000000000 --- a/spring/src/main/java/net/notejam/spring/view/ViewConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.notejam.spring.view; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import net.notejam.spring.view.dialect.NotejamDialect; - -/** - * Configures the view. - * - * @author markus@malkusch.de - * @see Donations - */ -@Configuration -public class ViewConfiguration { - - /** - * Provide the notejam view dialect. - * - * @return The notejam dialect. - */ - @Bean - public NotejamDialect notejamDialect() { - return new NotejamDialect(); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/view/dialect/NaturalLanguageDateProcessor.java b/spring/src/main/java/net/notejam/spring/view/dialect/NaturalLanguageDateProcessor.java deleted file mode 100644 index 804e37cd7..000000000 --- a/spring/src/main/java/net/notejam/spring/view/dialect/NaturalLanguageDateProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.notejam.spring.view.dialect; - -import static net.notejam.spring.view.dialect.ProcessorUtil.getValue; - -import java.time.Instant; -import java.util.Date; -import java.util.Locale; - -import org.ocpsoft.prettytime.PrettyTime; -import org.thymeleaf.Arguments; -import org.thymeleaf.dom.Element; -import org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor; - -/** - * A natural language date formatter. - * - * @author markus@malkusch.de - * @see Donations - */ -final class NaturalLanguageDateProcessor extends AbstractTextChildModifierAttrProcessor { - - /** - * Sets the attribute name. - * - * @param attributeName - * The attribute name. - */ - NaturalLanguageDateProcessor(final String attributeName) { - super(attributeName); - } - - @Override - protected String getText(final Arguments arguments, final Element element, final String attributeName) { - Locale locale = arguments.getContext().getLocale(); - Instant instant = getValue(arguments, element, attributeName); - - PrettyTime formatter = new PrettyTime(); - formatter.setLocale(locale); - return formatter.format(Date.from(instant)); - } - - @Override - public int getPrecedence() { - return 12000; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/view/dialect/NoteTextProcessor.java b/spring/src/main/java/net/notejam/spring/view/dialect/NoteTextProcessor.java deleted file mode 100644 index 36387ea34..000000000 --- a/spring/src/main/java/net/notejam/spring/view/dialect/NoteTextProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.notejam.spring.view.dialect; - -import static net.notejam.spring.view.dialect.ProcessorUtil.getValue; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.thymeleaf.Arguments; -import org.thymeleaf.dom.Element; -import org.thymeleaf.dom.Node; -import org.thymeleaf.dom.Text; -import org.thymeleaf.processor.attr.AbstractChildrenModifierAttrProcessor; - -/** - * A note text formatter. - * - * Each empty line in a note's text delimits a paragraph. Paragraphs will be - * wrapped in <p> elements. - * - * @author markus@malkusch.de - * @see Donations - */ -final class NoteTextProcessor extends AbstractChildrenModifierAttrProcessor { - - /** - * Sets the attribute name. - * - * @param attributeName - * The attribute name. - */ - NoteTextProcessor(final String attributeName) { - super(attributeName); - } - - @Override - protected List getModifiedChildren(final Arguments arguments, final Element element, - final String attributeName) { - String text = getValue(arguments, element, attributeName); - String[] paragraphTexts = text.trim().split("\\R{2,}"); - - return Stream.of(paragraphTexts).map(paragraphText -> { - Element paragraph = new Element("p"); - paragraph.addChild(new Text(paragraphText)); - return paragraph; - }).collect(Collectors.toList()); - } - - @Override - public int getPrecedence() { - return 12000; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/view/dialect/NotejamDialect.java b/spring/src/main/java/net/notejam/spring/view/dialect/NotejamDialect.java deleted file mode 100644 index 561c484f4..000000000 --- a/spring/src/main/java/net/notejam/spring/view/dialect/NotejamDialect.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.notejam.spring.view.dialect; - -import java.util.HashSet; -import java.util.Set; - -import org.thymeleaf.dialect.AbstractDialect; -import org.thymeleaf.processor.IProcessor; - -/** - * The Notejam view dialect. - * - * The prefix of this dialect is "notejam". These are the dialect's attributes: - * - *

  • date: Formats a date into natural language. - *
  • text: Converts empty lines into paragraphs. - * - * @author markus@malkusch.de - * @see Donations - */ -public final class NotejamDialect extends AbstractDialect { - - @Override - public String getPrefix() { - return "notejam"; - } - - @Override - public Set getProcessors() { - Set processors = new HashSet(); - processors.add(new NaturalLanguageDateProcessor("date")); - processors.add(new NoteTextProcessor("text")); - return processors; - } - -} diff --git a/spring/src/main/java/net/notejam/spring/view/dialect/ProcessorUtil.java b/spring/src/main/java/net/notejam/spring/view/dialect/ProcessorUtil.java deleted file mode 100644 index acdfe488b..000000000 --- a/spring/src/main/java/net/notejam/spring/view/dialect/ProcessorUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.notejam.spring.view.dialect; - -import org.thymeleaf.Arguments; -import org.thymeleaf.Configuration; -import org.thymeleaf.dom.Element; -import org.thymeleaf.standard.expression.IStandardExpression; -import org.thymeleaf.standard.expression.IStandardExpressionParser; -import org.thymeleaf.standard.expression.StandardExpressions; - -/** - * A utility for attribute processors. - * - * @author markus@malkusch.de - * @see Donations - */ -final class ProcessorUtil { - - /** - * No public constructor for this utility class. - */ - private ProcessorUtil() { - } - - /** - * Returns the value from the attribute expression. - * - * @param arguments - * The arguments. - * @param element - * The element. - * @param attributeName - * The attribute name - * @return The text. - */ - @SuppressWarnings("unchecked") - static T getValue(final Arguments arguments, final Element element, final String attributeName) { - Configuration configuration = arguments.getConfiguration(); - String attributeValue = element.getAttributeValue(attributeName); - IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); - IStandardExpression expression = parser.parseExpression(configuration, arguments, attributeValue); - return (T) expression.execute(configuration, arguments); - } - -} diff --git a/spring/src/main/java/net/notejam/spring/view/dialect/package-info.java b/spring/src/main/java/net/notejam/spring/view/dialect/package-info.java deleted file mode 100644 index 18b396415..000000000 --- a/spring/src/main/java/net/notejam/spring/view/dialect/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the Notejam Thymeleaf dialect. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.view.dialect; diff --git a/spring/src/main/java/net/notejam/spring/view/package-info.java b/spring/src/main/java/net/notejam/spring/view/package-info.java deleted file mode 100644 index a63f06db7..000000000 --- a/spring/src/main/java/net/notejam/spring/view/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Provides classes for the view. - * - * @author markus@malkusch.de - * @see Donations - */ -package net.notejam.spring.view; diff --git a/spring/src/main/resources/application.properties b/spring/src/main/resources/application.properties deleted file mode 100644 index d399c0dee..000000000 --- a/spring/src/main/resources/application.properties +++ /dev/null @@ -1,37 +0,0 @@ -#email.sender: Markus Malkusch - -#; If you want to have mail transport, configure at least the property spring.mail.host, -#; otherwise mail transport is not available. -#; For further mail configuration see http://docs.spring.io/spring-boot/docs/current/api/index.html?org/springframework/boot/autoconfigure/mail/MailProperties.html -#; -spring.mail.host= smtp.example.net -email.sender=suresh.thomas@yahoo.com - - -#spring.datasource.url=jdbc:hsqldb:file:db -#spring.jpa.hibernate.ddl-auto=update - -async.queueCapacity= 1000 - -#; ISO 8601 period until a recovery token expires. -recovery.lifetime= P1D - -#; The length of the generated password. -recovery.length= 32 - - -spring.jpa.show-sql=true -spring.jpa.properties.hibernate.format_sql=true -#spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.ddl-auto=update -spring.datasource.driverClassName=com.mysql.jdbc.Driver -spring.datasource.url=jdbc:mysql://nordcloud-mysqlserver.mysql.database.azure.com:3306/dbnotejam -spring.datasource.username=mysqladminun@nordcloud-mysqlserver -spring.datasource.password=H@Sh1CoR3! -spring.datasource.initialization-mode=always -logging.level.org.hibernate.SQL=DEBUG -logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE -logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG -logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE -spring.jackson.default-property-inclusion=NON_NULL -spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file diff --git a/spring/src/main/resources/messages_de.properties b/spring/src/main/resources/messages_de.properties deleted file mode 100644 index bc6090842..000000000 --- a/spring/src/main/resources/messages_de.properties +++ /dev/null @@ -1,122 +0,0 @@ -bootstrap.locale: de - -error.title: Fehler - -menu.signin: Einloggen -menu.signup: Registrieren -menu.signout: Abmelden -menu.account: Kontoeinstellungen - -footer.application: Anwendung -footer.createdBy: erstellt von - -layout.pads: Meine Blöcke -layout.noPads: keine Blöcke -layout.newPad: Neuer Block - -account.title: Kontoeinstellungen -account.success: Sie haben erfolgreich Ihr Passwort geändert. -account.currentPassword: Aktuelles Passwort -account.newPassword: Neues Password -account.repeatedPassword: Wiederholen Sie das neue Passwort. - -forgot.title: Passwort vergessen? -forgot.success: Sie erhalten in kürze eine Email um Ihr Passwort zurückzusetzen. -forgot.email: Email -forgot.generate: Passwort zurücksetzen -forgot.reveal: Ihr neues Passwort lautet: {0} -forgot.mail.subject: Notejam: Passwort zurücksetzen -forgot.mail.message: Um Ihr neues Passwort für Notejam zu erhalten,\n\ - folgend Sie bitte diesem Verweis:\n\ - \n\ - <{0}>\n\ - \n\ - Mit freundlichen Grüßen\n\ - Ihr Notejam Team - -signup.title: Registrierung -signup.Email: Email -signup.Password: Passwort -signup.Password2: Wiederholen Sie bitte das Passwort -signup.Signup: Registrieren -signup.or: oder -signup.Signin: Einloggen - -login.title: Einloggen -login.email: Email -login.password: Passwort -login.error: Die Anmeldung ist fehlgeschlagen. -login.logout: Sie wurden abgemeldet. -login.signedup: Sie haben sich erfolgreich registriert. Melden Sie sich nun an. -login.signin: Einloggen -login.or: oder -login.signup: Registrieren -login.forgot: Passwort vergessen? - -note.create.title: Neue Notiz -note.create.name: Name -note.create.text: Notiz -note.create.pad: Block -note.create.nopad: -------- - -note.delete.sure: Sie sind gerade dabei die Notiz {0} zu löschen. -note.delete.delete: Ja, löschen. Ich will diese Notiz löschen. -note.delete.success: Gelöscht - -note.edit.name: Name -note.edit.text: Notiz -note.edit.pad: Block -note.edit.nopad: -------- - -note.view.successful: Gespeichert -note.view.edited: Zuletzt am {0} bearbeitet. -note.view.edit: Bearbeiten -note.view.delete: Löschen - -pad.create.title: Neuer Block -pad.create.name: Name - -pad.delete.sure: Sie sind gerade dabei den Block {0} zu löschen. -pad.delete.delete: Ja, löschen. Ich will diesen Block löschen. -pad.delete.success: Gelöscht - -pad.edit.name: Name -pad.edit.success: Gespeichert -pad.edit.delete: Block löschen - -pad.view.created: Der Block wurde erfoglreich angelegt. -pad.view.empty: Erstellen Sie Ihre erste Notiz. -pad.view.title:{0} ({1} Notizen) -pad.view.allNotes: Alle Notizen ({0}) -pad.view.note: Notiz -pad.view.pad: Block -pad.view.modified: letzte Änderung -pad.view.noPad: Kein Block -pad.view.newNote: Neue Notiz -pad.view.settings: Blockeinstellungen - -save: Speichern -cancel: Abbrechen -dateFormat: dd. MMM yyyy 'um' HH:mm 'Uhr' - -NotEmpty.user.email: Bitte geben Sie Ihre Emailadresse ein. -NotEmpty.user.password: Bitte wählen Sie ein Passwort. -Size.user.email: Bitte verwenden Sie eine Emailadresse welche kleiner als {1} Zeichen ist. -Size.user.password: Das Passwort muss zwischen {2} und {1} Zeichen lang sein. -EqualProperties.user.password: Sie haben sich beim Passwort vertippt. - -NotEmpty.account.currentPassword: Bitte geben Sie ihr aktuelles Passwort ein. -NotEmpty.account.newPassword: Bitte geben Sie ein neues Passwort ein. -Size.account.newPassword: Das Passwort muss zwischen {2} und {1} Zeichen lang sein. -EqualProperties.account.password: Sie haben sich beim neuen Passwort vertippt. - -NotEmpty.note.name: Bitte geben Sie Ihrer Notiz einen Namen. -Size.note.name: Der Name darf höchstens {1} Zeichen haben. -NotEmpty.note.text: Bitte hinterlassen Sie eine Notiz. - -NotEmpty.pad.name: Bitte geben Sie Ihrem Block einen Namen. -Size.pad.name: Der Name darf höchstens {1} Zeichen haben. - -Email: Die Emailadresse ist nicht gültig. -UniqueEmail: Die Emailadresse ist bereits vergeben. -CurrentPassword: Das aktuelles Passwort ist nicht korrekt. diff --git a/spring/src/main/resources/messages_en.properties b/spring/src/main/resources/messages_en.properties deleted file mode 100644 index bfd905407..000000000 --- a/spring/src/main/resources/messages_en.properties +++ /dev/null @@ -1,122 +0,0 @@ -bootstrap.locale: en - -error.title: Error - -footer.application: application -footer.createdBy: created by - -layout.pads: My pads -layout.noPads: No pads -layout.newPad: New pad - -menu.signin: Sign in -menu.signup: Sign up -menu.signout: Sign out -menu.account: Account settings - -account.title: Account Settings -account.success: You've successfully changed your password. -account.currentPassword: Current password -account.newPassword: New password -account.repeatedPassword: Confirm new password - -forgot.title: Forgot password? -forgot.success: Check your email to proceed. -forgot.email: Email -forgot.generate: Generate password -forgot.reveal: Your new password is: {0} -forgot.mail.subject: Notejam: Password recovery -forgot.mail.message: To receive your new password,\n\ - please follow that URI:\n\ - \n\ - <{0}>\n\ - \n\ - Regards\n\ - Notejam team - -signup.title: Sign up -signup.Email: Email -signup.Password: Password -signup.Password2: Confirm password -signup.Signup: Sign up -signup.or: or -signup.Signin: Sign in - -login.title: Sign In -login.email: Email -login.password: Password -login.error: Login failed. -login.logout: You're now logged out. -login.signedup: You've been signed up. You can now log in. -login.signin: Sign In -login.or: or -login.signup: Sign up -login.forgot: Forgot password? - -note.create.title: New note -note.create.name: Name -note.create.text: Note -note.create.pad: Select Pad -note.create.nopad: -------- - -note.delete.sure: Are you sure you want to delete {0}? -note.delete.delete: Yes, delete I want to delete this note -note.delete.success: Deleted - -note.edit.name: Name -note.edit.text: Note -note.edit.pad: Select Pad -note.edit.nopad: -------- - -note.view.successful: Saved -note.view.edited: Last edited at {0} -note.view.edit: Edit -note.view.delete: Delete it - -pad.create.title: New pad -pad.create.name: Name - -pad.delete.sure: Are you sure you want to delete {0}? -pad.delete.delete: Yes, delete I want to delete this pad -pad.delete.success: Deleted - -pad.edit.name: Name -pad.edit.success: Saved -pad.edit.delete: Delete pad - -pad.view.created: The pad was created successfully. -pad.view.empty: Create your first note. -pad.view.title: {0} ({1} notes) -pad.view.allNotes: All notes ({0}) -pad.view.note: Note -pad.view.pad: Pad -pad.view.modified: Last modified -pad.view.noPad: No pad -pad.view.newNote: New note -pad.view.settings: Pad settings - -save: Save -cancel: Cancel -dateFormat: dd/MMM/yyyy HH:mm - -NotEmpty.user.email: Please enter your email address. -NotEmpty.user.password: Please choose a password. -Size.user.email: Please use an address which has less than {1} characters. -Size.user.password: Please use a password which has between {2} and {1} characters. -EqualProperties.user.password: You've mistyped the password. - -NotEmpty.account.currentPassword: Please enter your current password. -NotEmpty.account.newPassword: Please enter the new password. -Size.account.newPassword: Please use a password which has between {2} and {1} characters. -EqualProperties.account.password: You've mistyped the password. - -NotEmpty.note.name: Please enter a name. -Size.note.name: The name must have less than {1} characters. -NotEmpty.note.text: Please leave a note. - -NotEmpty.pad.name: Please enter a name. -Size.pad.name: The name must have less than {1} characters. - -Email: The address is not valid. -UniqueEmail: The mail address is already registered for another user. -CurrentPassword: The current password is wrong. diff --git a/spring/src/main/resources/static/css/style.css b/spring/src/main/resources/static/css/style.css deleted file mode 100644 index a1c541c9c..000000000 --- a/spring/src/main/resources/static/css/style.css +++ /dev/null @@ -1,467 +0,0 @@ -/* -* Skeleton V1.0.3 -* Copyright 2011, Dave Gamache -* www.getskeleton.com -* Free to use under the MIT license. -* http://www.opensource.org/licenses/mit-license.php -* 7/17/2011 -*/ - -/* Documentation Styles -================================================== */ -div.container { - padding-top: 40px; -} - -/* Doc nav */ -nav { - width: 160px; -} - -#logo, .bold-header { - margin-bottom: 30px; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - letter-spacing: -1px; - color: #555; - font-weight: bold; -} - -.bold-header span { - font-weight: normal; - font-size: 23px; -} - -.bold-header a.header { - text-decoration: none; - color: inherit; -} - -.bold-header span.jam { - font-size: 46px; - line-height: 50px; -} - -nav ul { - float: left; -} - -nav ul li { - display: block; - margin-bottom: 10px; -} - -nav ul li a, nav ul li a:visited, nav ul li a:active { - font-size: 14px; - color: #555; - text-decoration: none; - font-weight: bold; -} - -nav ul li a:hover, nav ul li a:focus { - color: #222; -} - -header h1 { - font-size: 52px; - line-height: 61px; - letter-spacing: -1px; - font-weight: normal; - font-family: "Georgia", "Times New Roman", Helvetica, Arial, sans-serif; -} - -hr.large { - border: none; - height: 8px; - background: #ebebeb; - margin: 50px 0; -} - -div.doc-section { - margin: 30px 0; -} - -#whatAndWhy .row { - padding: 30px 0 0; -} - -#typography blockquote { - margin-top: 20px; -} - -.hidden-code a { - font-size: 12px; - color: #999; -} - -.hidden-code>div { - display: none; -} - -/* Grid */ -#grid .column, #grid .columns { - background: #ddd; - height: 25px; - line-height: 25px; - margin-bottom: 10px; - text-align: center; - text-transform: uppercase; - color: #555; - font-size: 12px; - font-weight: bold; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - border-radius: 2px; -} - -#grid .column:hover, #grid .columns:hover { - background: #bbb; - color: #333; -} - -#grid .example-grid { - overflow: hidden; -} - -.post-button-note, .post-button-note a { - font-size: 11px; - color: #999; -} - -#examples .four.columns a { - text-decoration: none; -} - -#examples .four.columns a:hover { - text-decoration: underline; -} - -.resize { - position: fixed; - bottom: 0; - right: 0; - height: 80px; - width: 80px; - background: url(images/resize.png); -} - -img { - max-width: 100%; - height: auto; -} - -.gist-meta { - display: none !important; -} - -ul ul ul li { - margin-bottom: 3px; -} - -.twitter-share-button { - margin-bottom: -18px; -} - -/* Table stylesheets */ -table { - width: 100%; - border-collapse: collapse; -} - -table th, table td { - padding: 10px 10px 9px; - font-size: 13px; - line-height: 18px; - text-align: left; -} - -table td { - vertical-align: top; - border-top: solid 1px #ddd; -} - -table th { - padding-top: 9px; - font-weight: bold; - vertical-align: middle; -} - -table.condensed th, table.condensed td { - padding: 5px 5px 4px; -} - -table.bordered { - border-collapse: separate; - border: solid 1px #ddd; - -webkit-border-radius: 2px; - -moz-border-radius: 2px; - border-radius: 2px; -} - -table.bordered th+th, table.bordered th+td, table.bordered td+td { - border-left: solid 1px #ddd; -} - -.zebra-striped tbody tr:nth-child(odd) td, .zebra-striped tbody tr:nth-child(odd) th - { - background: #f5f5f5; -} - -.carbonad, .carbonad-image, .carbonad-text, .carbonad-tag { - background: none !important; - border: none !important; - margin-left: 0 !important; -} - -.carbonad-tag { - margin-top: 6px !important; - padding-top: 0 !important; -} - -.carbonad-text { - height: auto !important; -} - -.carbonad-image { - margin-top: 0 !important; -} - -.hidden-text { - font-size: 12px; - color: #999; -} - -td.date, th.date { - text-align: right; - white-space: nowrap; -} - -td.date { - font-style: italic; -} - -form.note input[type="text"], form.note textarea { - width: 100%; -} - -form hr { - width: 218px; - margin: 10px 0px; -} - -form.note textarea { - height: 250px; -} - -div.content-area { - min-height: 600px; -} - -hr.footer { - margin-bottom: 10px; -} - -div.footer { - margin-bottom: 10px; - text-align: center; - font-size: 12px; -} - -form.sign-in { - margin: 50px 0 0 0; -} - -.sort_arrow { - text-decoration: none; -} - -.sort_arrow:hover { - text-decoration: none; - color: red; -} - -div.sign-in-out-block { - position: absolute; - right: 14px; - top: 8px; - font-size: 12px; -} - -div.sign-in-out-block form { - margin: inherit; -} - -div.sign-in-out-block input[type="submit"] { - background: none; - border: none; - color: inherit; - font: inherit; - text-decoration: underline; - cursor: pointer; - padding: inherit; - margin: inherit; -} - -div.sign-in-out-block a { - /*text-decoration: none;*/ - -} - -a.small-red { - color: red; - font-size: 12px; -} - -table.notes { - margin: 0 0 20px 0; -} - -table.notes th.note { - width: 72%; -} - -table.notes td.pad { - color: grey; - white-space: nowrap; -} - -table.notes td.pad a { - color: grey; - text-decoration: underline; - font-style: normal; - white-space: normal; -} - -table.notes td.pad a:hover { - color: black; -} - -p.empty { - color: grey; - font-style: italic; -} - -a.delete-note { - float: right; - font-size: 12px; - color: red; -} - -.red, input.red { - color: red !important; -} - -ul.errorlist, ul.errors { - margin: -18px 0 0 0; -} - -ul.errorlist li, ul.errors li { - color: red; -} - -.alert-area { - text-align: center; -} - -.alert { - padding: 5px 8px; - margin: 0 0 12px 0; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - border-radius: 2px; -} - -.alert-success { - color: #468847; - background-color: #dff0d8; - border: 1px solid #d6e9c6; -} - -.alert-error { - color: #b94a48; - background-color: #f2dede; - border: 1px solid #eed3d7; -} - -pagination { - text-align: center; -} - -/* Mobile */ -@media only screen and (max-width: 767px) { - header h1 { - font-size: 34px; - line-height: 37px; - } - nav { - position: relative; - } - nav ul, .carbonad { - display: none; - } - #logo { - text-align: left; - } - #examples .four.columns { - padding-top: 30px; - } -} - -/* Mobile Landscape */ -@media only screen and (min-width: 480px) and (max-width: 767px) { - nav ul { - display: none; - } -} - -/* Non 960 */ -@media only screen and (max-width: 959px) { - #logo { - font-size: 21px; - margin-bottom: 15px; - } - nav .button { - padding: 9px 20px 11px; - } -} - -/* iPad Portrait/Browser */ -@media only screen and (min-width: 768px) and (max-width: 959px) { - nav { - width: 124px; - } -} - -/* Mobile/Browser */ -@media only screen and (max-width: 767px) { -} - -/* Mobile Landscape/Browser */ -@media only screen and (min-width: 480px) and (max-width: 767px) { -} - -/* Anything smaller than standard 960 */ -@media only screen and (max-width: 959px) { -} - -/* iPad Portrait Only */ -@media only screen and (min-width: 768px) and (max-width: 959px) and - (max-device-width: 1000px) { -} - -/* Mobile Only */ -@media only screen and (max-width: 767px) and (max-device-width: 1000px) - { -} - -/* Mobile Landscape Only */ -@media only screen and (min-width: 480px) and (max-width: 767px) and - (max-device-width: 1000px) { -} - -/* Anything smaller than standard 960 on a device */ -@media only screen and (max-width: 959px) and (max-device-width: 1000px) - { - .resize { - display: none; - } -} \ No newline at end of file diff --git a/spring/src/main/resources/templates/error.html b/spring/src/main/resources/templates/error.html deleted file mode 100644 index e90facac6..000000000 --- a/spring/src/main/resources/templates/error.html +++ /dev/null @@ -1,16 +0,0 @@ - - - -Notejam: [[#{error.title}]] - - - -

    [[#{error.title}]]

    - -
    -

    -

    - - - \ No newline at end of file diff --git a/spring/src/main/resources/templates/layout.html b/spring/src/main/resources/templates/layout.html deleted file mode 100644 index b1cd04db7..000000000 --- a/spring/src/main/resources/templates/layout.html +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - -Title - - - - - - - - - - - - - - - -
    -
    - - -
    -
    -

    - notejam: Title -

    -
    - -
    - - -
    - -
    - - - -
    - - Fork me on GitHub - - diff --git a/spring/src/main/resources/templates/note/create.html b/spring/src/main/resources/templates/note/create.html deleted file mode 100644 index 4ec1bea1e..000000000 --- a/spring/src/main/resources/templates/note/create.html +++ /dev/null @@ -1,47 +0,0 @@ - - - -Notejam: [[#{note.create.title}]] - - - -

    [[#{note.create.title}]]

    - -
    -
    -
    -
    Note deleted.
    -
    - -
      -
    • -
    - -