Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
CodeDriveRepeatPublic

About

Linter for csv files, ensure that the types and values are what you expect.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

csvLinter

The csvLinter is a .NET Core Web API project designed to validate CSV files against a specified schema. This tool ensures that CSV files conform to expected formats and data types. You can add your own datatypes as needed, via the schemas folder in JSON format. This contains a few simple examples.

Features

  • Validate CSV files for correct number of columns and specific data types.
  • Dynamic schema definitions using a Json to map column names, types and values.
  • RFC 4180-compliant CSV parsing (via CsvHelper), so quoted fields containing commas, embedded newlines, and escaped quotes are handled correctly.
  • JWT-authenticated API, backed by a local SQLite user store.
  • Easy integration into other systems or as a standalone service.

Prerequisites

Before you begin, ensure you have the following installed:

Build and run

  1. Clone the repository Clone this repository to your local machine using Git:
   git clone https://github.com/tomblanchard312/csvLinter.git
   cd csvLinter
  1. Restore dependencies
dotnet restore csvLinter.Api.csproj
  1. Build the API
dotnet build csvLinter.Api.csproj
  1. Run the API from the repository root (the project file is at the root):
dotnet run --project csvLinter.Api.csproj

By default (dotnet run with no --launch-profile) this uses the http profile from Properties/launchSettings.json, which listens on http://localhost:5289. To run over HTTPS on port 7014 instead, use the https profile:

dotnet run --project csvLinter.Api.csproj --launch-profile https

which listens on https://localhost:7014 (and still on http://localhost:5289).

On startup the app automatically applies any pending Entity Framework Core migrations, creating a local csvLinter.db SQLite file for the user store. You can access the API endpoints using a browser or tools like Postman, or via the Swagger UI at /swagger.

Authentication

The CSV linting endpoint requires a JWT bearer token. Create an account and obtain a token via the auth endpoints below, then pass the token on subsequent requests.

Configuration

JWT signing is configured under the Jwt section of appsettings.json:

"Jwt": {
  "Issuer": "csvLinter",
  "Audience": "csvLinter-clients"
}

Jwt:Key (the signing key) is intentionally not committed to appsettings.json. A placeholder development-only key is set in appsettings.Development.json. For any non-development environment, supply Jwt:Key via an environment variable, user-secrets, or a secrets manager, for example:

dotnet user-secrets set "Jwt:Key" "your-own-strong-signing-key"

Register

curl -X POST http://localhost:5289/api/Auth/register \
  -H "Content-Type: application/json" \
  -d "{\"username\":\"myuser\",\"password\":\"MyStrongP@ssw0rd\"}"

Log in

curl -X POST http://localhost:5289/api/Auth/login \
  -H "Content-Type: application/json" \
  -d "{\"username\":\"myuser\",\"password\":\"MyStrongP@ssw0rd\"}"

This returns a JSON body containing a token and its expiresAtUtc. Use the token as a bearer token on the linting endpoint below.

Using the API

Endpoint: /api/CsvLint Method: POST Auth: Authorization: Bearer <token> (see Authentication) Query: schemaType (matches a schema file name under schemas/) Body: multipart/form-data with the file upload (csvFile)

Example using cURL:

curl -X POST "http://localhost:5289/api/CsvLint?schemaType=EmployeeDetails" \
  -H "Authorization: Bearer <token>" \
  -F "csvFile=@path_to_your_file.csv"

Tests

Sample CSV files are under samplecsvs/. Files ending in _good.csv should validate; bad_[reason].csv files illustrate invalid input.

Run the automated tests with:

dotnet test csvLinter.Api.csproj

Contributing

Contributions to the csvLinter are welcome. Please fork the repository and submit pull requests to contribute.

License

This project is licensed under the Apache 2.0 License.

View this repository on GitDiagram

About

Linter for csv files, ensure that the types and values are what you expect.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages