Skip to content
forked from moriturus/ktra

Your Little Cargo Registry

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

garyanaplan/ktra

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ktra 🚚 ktra at crates.io

Your Little Cargo Registry.

Ktra is an implementation of the Alternate Registry that is introduced for non-public crates in Rust/Cargo 1.34.

In other words, Ktra is an all-in-one package for the private cargo registry.

Features

Current

From 0.1.0

  • Minimum Alternate Registry implementation.
  • Sled as its internal database.
    • via db-sled feature turned on by default.
  • Almost pure Rust.

From 0.2.0

  • Secure user management.

From 0.4.0

  • Redis support.
    • via db-redis feature.

Planned

And any feature requests are welcome!

Install

$ cargo install ktra

Quick Start

  1. Create the index git repository.
    • Ktra supports both HTTPS protocol and SSH protocol.
  2. Put a file named config.json and commit then push it to remote repository.
$ echo '{"dl":"http://localhost:8000/dl","api":"http://localhost:8000"}' > config.json
$ git add config.json
$ git commit -am "initial commit"
$ git push origin main
  1. Edit your .cargo/config.toml
[registries]
ktra = { index = "https://github.com/moriturus/ktra-index.git" }
  1. Create a configuration file.
    • Note 1: Ktra searches ./ktra.toml as a default configuration file if not specified.
    • Note 2: All configurations are able to set via command arguments. See ktra -h for more details.
# essential configurations are `remote_url` and credential informations.
# if you use HTTPS protocol, please specify `https_username` and `https_password` fields.
# using SSH protocol, `ssh_privkey_path` should be specified.
[index_config]
remote_url = "https://github.com/moriturus/ktra-index.git"
https_username = "moriturus"
https_password = "2mdzctfryqirlqbhys43xsc46rbnr93g" 
# ssh_privkey_path = "/path/to/your/private_key"
# name = "committer/author name"
# email = "robot@example.com"

# below configurations are optional.
# [db_config]
# db_path = "my_db" # sled
# redis_url = "redis://username:password@localhost" # redis

# [crate_files_config]
# dl_dir_path = "./crates"
# dl_path = ["download", "path", "to", "mount"]

# [server_config]
# address = "127.0.0.1"
# port = 8080
  1. Run ktra
$ ktra -c /path/to/config.toml
  1. Create user and login
    • Note 3: From v0.2.0, ktra supports and recommends this authentication way.
    • Note 4: ⚠️ The authentication way that is used in v0.1.0 is not convertible with the new one. ⚠️
$ curl -X POST -H 'Content-Type: application/json' -d '{"password":"PASSWORD"}' http://localhost:8000/ktra/api/v1/new_user/alice
{"token":"0N9mgZb3kzxtgGKECFuMkM2RT5xkYhdY"}
$ cargo login --registry=ktra 0N9mgZb3kzxtgGKECFuMkM2RT5xkYhdY
       Login token for `ktra` saved
  1. Publish your crate.
$ cat Cargo.toml
[package]
name = "my_crate"
version = "0.1.0"
authors = ["moriturus <moriturus@alimensir.com>"]
edition = "2018"
description = "sample crate"

[dependencies]
serde = "1.0"

$ cargo publish --registry=ktra
  1. Use your crate from another crate.
[package]
name = "my_another_crate"
version = "0.1.0"
authors = ["moriturus <moriturus@alimensir.com>"]
edition = "2018"

[dependencies]
my_crate = { version = "0.1", registry = "ktra" }

Ktra Web APIs

Ktra Web APIs are extra web APIs that are not specified in the specification but required to manage users.
Since all APIs send passwords in cleartext, it is highly recommended that you connect the registry from your local network only OR use an HTTPS connection.

Create a new user

  • Specification
Endpoint /ktra/api/v1/new_user/{user_name}
Method POST
Body { "password": "PASSWORD" }
  • Response
{
    "token": "TOKEN"
}

Login

  • Specification
Endpoint /ktra/api/v1/login/{user_name}
Method POST
Body { "password": "PASSWORD" }
  • Response
{
    "token": "NEW TOKEN"
}

Change password

  • Specification
Endpoint /ktra/api/v1/change_password/{user_name}
Method POST
Body { "old_password": "OLD PASSWORD", "new_password": "NEW PASSWORD" }
  • Response
{
    "token": "NEW TOKEN"
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Your Little Cargo Registry

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%