Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Configuration] Provide a way to configure TimeMates using kotlin script #142

Open
y9vad9 opened this issue Jun 4, 2023 · 0 comments · May be fixed by #143
Open

[Configuration] Provide a way to configure TimeMates using kotlin script #142

y9vad9 opened this issue Jun 4, 2023 · 0 comments · May be fixed by #143
Assignees
Labels
feature New feature or request

Comments

@y9vad9
Copy link
Member

y9vad9 commented Jun 4, 2023

TimeMates Backend Server Setup (Future Feature)

The TimeMates backend server is actively developing a new feature that will provide a future way to configure and set up your server using a Kotlin script with the .tmc file extension. This feature aims to offer a more flexible and customizable approach to server configuration.

Please note that at the time of writing this documentation, the feature is not yet available. However, we are excited to provide you with an overview of how this future configuration method will work.

Structure

Getting Started (Future Implementation)

Once the TimeMates backend server configuration feature is released, you can follow these steps to set up your server using the Kotlin script with the .tmc file extension:

  1. Create a new Kotlin script file with the .tmc extension (e.g., config.tmc).
  2. Start configuring your backend server by directly accessing the TimeMatesConfigurationScope functions from the root of the script:
// config.tmc

// Configure the mailer (Example)
mailer {
    // Specify the implementation and customize the mailer settings
    mailerSend {
        apiKey = "YOUR_API_KEY"
        sender = "[email protected]"
        confirmationTemplateId = "CONFIRMATION_TEMPLATE_ID"
        supportEmail = "[email protected]"
    }


    // or (only one implementation can be used)
    smtp {
        host = "smtp.example.com"
        port = 587
        user = "smtp-user"
        password = "smtp-password"
        confirmationSender = "[email protected]"
   }
}

// Configure the database (Example)
database {
    // Specify the implementation and customize the database settings
    postgresql {
        url = "jdbc:postgresql://localhost:5432/mydatabase"
        user = "myuser"
        password = "mypassword"
    }

    // or (only one implementation can be used)
    inMemory() // it will use h2 implementation that stores everything in memory
}

// Configure the files (Example)
files {
    // Specify the file system settings
    localFiles {
        imagesPath("path/to/images")
    }
}

// Configure the settings (Example)
settings {
    // Specify the server settings
    users {
        canRegister = true
    }

    overwriteEnvironment = true // telling server not to use env variables if available
}

Configuration Interceptors (Future Proposal)

In the future configuration system, you will have the ability to define interceptors that can be applied to various parts of the server configuration. Interceptors provide a way to add custom logic, such as authorization or verification, before executing certain configuration blocks.

For example, you might want to create an interceptor that verifies the identity of individuals who want to host TimeMates and restricts access to certain configuration options. This can help ensure that only authorized individuals can make changes to the server configuration.

interceptors {
    authorization { data -> // AuthorizationRequestScope
        if(someApi.hasUser(data.email))
            abort(message = "This user cannot be registered")
        else /* ... */
    }
}

Limitation Settings

Another proposal for the future configuration system is the inclusion of limitation settings. These settings allow you to restrict or customize certain aspects of the server behavior.

For example, you might want to limit the maximum number of concurrent connections, the rate of API requests, or the maximum file size that can be uploaded. These limitation settings help you fine-tune and manage the server resources based on your specific requirements.

settings {
    // Configure limitation settings
    limitations {
        files {
            perHour(count = 10, size = 100.mb)
        }
        timers {
            perMinute(count = 3)
        }
        
        // ...
    }
}

In the example above, the settings section includes a limitations block where you can set various limitations for the server.

Database Connection Pool Configuration (Future Proposal)

The future configuration system of the TimeMates backend server aims to include a feature for customizing the database connection pool settings. This allows you to optimize the handling of database connections and enhance the server's performance.

Database Connection Pool Settings

The following configuration options will be available for the database connection pool:

  • maxConnections: Specifies the maximum number of connections allowed in the pool.
  • minConnections: Defines the minimum number of connections to keep in the pool, even when idle.
  • connectionTimeout: Sets the maximum time in milliseconds for a connection to be allocated from the pool.
  • idleTimeout: Specifies the maximum time in milliseconds that a connection can remain idle in the pool before being evicted.

Example Configuration

To configure the database connection pool, use the database block within the Kotlin script:

// server-setup.tmc

database {
    // Configure the connection pool settings
    postgresql {
        // ...
        config {
            maxConnections = 100
            minConnections = 10
            connectionTimeout = 5000
            idleTimeout = 600000
         }
    }
@y9vad9 y9vad9 added the feature New feature or request label Jun 4, 2023
@y9vad9 y9vad9 self-assigned this Jun 4, 2023
@y9vad9 y9vad9 moved this to ⛔️ Stop progress in 🗂️ TimeMates Server Jun 4, 2023
@y9vad9 y9vad9 linked a pull request Jun 4, 2023 that will close this issue
@y9vad9 y9vad9 pinned this issue Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: ⛔️ Stop progress
Development

Successfully merging a pull request may close this issue.

1 participant