Compare commits
19 Commits
Author | SHA1 | Date |
---|---|---|
Frank Denis | 91e3109831 | |
Aaron Gember-Jacobson | bdee525553 | |
Frank Denis | debdd9b9cc | |
xtr3me | 63fa457bae | |
Frank Denis | a2fa341679 | |
Frank Denis | 2efc655a6f | |
Frank Denis | 2d712d777d | |
dependabot-preview[bot] | f90d59f7a7 | |
Frank Denis | 007b76fdbd | |
bstrie | e3829405a7 | |
Frank Denis | dd08639f15 | |
Aloïs Micard | b5ea7d8fdd | |
Frank Denis | 16f4fd52cf | |
Frank Denis | 4512fa69a7 | |
Frank Denis | f344cf97c2 | |
Frank Denis | d8949d508c | |
Frank Denis | 85deb50eab | |
Frank Denis | 47d3f560e3 | |
Frank Denis | 5a6d3d0b02 |
|
@ -0,0 +1,8 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: cargo
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
open-pull-requests-limit: 10
|
|
@ -0,0 +1,22 @@
|
|||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
69
.travis.yml
69
.travis.yml
|
@ -1,69 +0,0 @@
|
|||
language: rust
|
||||
cache: cargo
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- fakeroot
|
||||
|
||||
env:
|
||||
global:
|
||||
- PROJECT_NAME=iptoasn-webservice
|
||||
- MAKE_DEB=yes
|
||||
- DEB_MAINTAINER="Frank Denis <github@pureftpd.org>"
|
||||
- DEB_DESCRIPTION="Webservice for the iptoasn.com database"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
rust: nightly
|
||||
env: TARGET=x86_64-unknown-linux-gnu
|
||||
|
||||
- os: linux
|
||||
rust: stable
|
||||
env: TARGET=x86_64-unknown-linux-gnu
|
||||
|
||||
allow_failures:
|
||||
# TODO You might need to allow failures for some target on some channel for some reason. Below
|
||||
# there's one (commented out) example of how to do that. Just change the OS, channel and TARGET
|
||||
# as needed.
|
||||
# - os: linux
|
||||
# rust: nightly
|
||||
# env: TARGET=x86_64-unknown-linux-gnu
|
||||
|
||||
before_install:
|
||||
- export PATH="$PATH:$HOME/.cargo/bin"
|
||||
|
||||
install:
|
||||
- bash ci/install.sh
|
||||
|
||||
script:
|
||||
- bash ci/script.sh
|
||||
|
||||
before_deploy:
|
||||
- bash ci/before_deploy.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: 0Y8ZXOJaNJJ5/0IRcXyNIOJK4EICQDRtaB/E+pboNUchJn9fThGMQc2QtZaGddBNrnuHsftBFM7mWXJvZ2H9YGgbBl1N6Z2y33vawSPgzTnfz0CZRJfX1Gl6IdtDH9zvlblHI1aE4eJ6lAu0q8VQ874CBPxoIlzU9jArOTdvyPT+8t64Y0K240trfqrm0NHloUbZtm+HeRJqoK1RKE4kdrpESIVMyyq67fM9T0VqLg+x3OHeQ/itFnZpjqtVtj9WhZeKM6iTNLQT+vLpRAvq8w6sv1WeCMYAqdXUL7jQnVaI+MiepC9z8OoF0ZAYes0I+3aaNsgMHiuwkW+nDUcQp5XLDW3oCq/uST4pN2ki/AJPy4UUUx++xb8SgtKE4wzBGbT0u5yO9JkIPxJZRLy+E0IvTlqVEZL/tvnI09JQQmzgDdP1hCcxpxBBm4xLi/2qSHIJIMUbb92DRwOrTii34+C0oa1UZKh2P/ceCtLNOlOCmFAcWE9uAxjEGP903mmgbixj8xBbyuROedHIMxag0Jr9Tdoi0hsVdhOEss4JjNKf7ayjepRIw5lNFjxk+jgB+Om0J3vQ+i83LxX1a0b9YV+KJUtWz/CV43mwYhF+jh2GAMe0/cvNCbFT4au0SW2FKDvV/00AJ5tPGimVXNe0e+AUqjbJ2sRpylIQw1Mfl6Y=
|
||||
file_glob: true
|
||||
file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.*
|
||||
# don't delete the artifacts from previous phases
|
||||
skip_cleanup: true
|
||||
# deploy when a new tag is pushed
|
||||
on:
|
||||
condition: $TRAVIS_RUST_VERSION = nightly
|
||||
tags: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
# Pushes and PR to the master branch
|
||||
- master
|
||||
# IMPORTANT Ruby regex to match tags. Required, or travis won't trigger deploys when a new tag
|
||||
# is pushed. This regex matches semantic versions like v1.2.3-rc4+2016.02.22
|
||||
- /^\d+\.\d+\.\d+.*$/
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "iptoasn-webservice"
|
||||
description = "API server for iptoasn.com"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
homepage = "https://iptoasn.com"
|
||||
repository = "https://github.com/jedisct1/iptoasn-webservice"
|
||||
keywords = ["ip", "asn", "bgp"]
|
||||
|
@ -10,7 +10,7 @@ authors = ["Frank Denis <github@pureftpd.org>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
clap = "2"
|
||||
clap = { version = "3.0.0", features = ["std", "cargo", "wrap_help"] }
|
||||
flate2 = "1"
|
||||
horrorshow = "0.8"
|
||||
hyper = "0.10"
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2016-2019, Frank Denis
|
||||
Copyright (c) 2016-2021, Frank Denis
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[![Build Status](https://travis-ci.org/jedisct1/iptoasn-webservice.svg?branch=master)](https://travis-ci.org/jedisct1/iptoasn-webservice)
|
||||
![Build Status](https://github.com/jedisct1/iptoasn-webservice/workflows/Rust/badge.svg)
|
||||
|
||||
# iptoasn-webservice
|
||||
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
# `before_deploy` phase: here we package the build artifacts
|
||||
|
||||
set -ex
|
||||
|
||||
. $(dirname $0)/utils.sh
|
||||
|
||||
# Generate artifacts for release
|
||||
mk_artifacts() {
|
||||
cargo build --target $TARGET --release
|
||||
}
|
||||
|
||||
mk_tarball() {
|
||||
# create a "staging" directory
|
||||
local td=$(mktempd)
|
||||
local out_dir=$(pwd)
|
||||
|
||||
# TODO update this part to copy the artifacts that make sense for your project
|
||||
# NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}'
|
||||
cp target/$TARGET/release/iptoasn-webservice $td
|
||||
dostrip $td/iptoasn-webservice
|
||||
|
||||
pushd $td
|
||||
|
||||
# release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz'
|
||||
tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz *
|
||||
|
||||
popd
|
||||
rm -r $td
|
||||
}
|
||||
|
||||
# Package your artifacts in a .deb file
|
||||
# NOTE right now you can only package binaries using the `dobin` command. Simply call
|
||||
# `dobin [file..]` to include one or more binaries in your .deb package. I'll add more commands to
|
||||
# install other things like manpages (`doman`) as the needs arise.
|
||||
# XXX This .deb packaging is minimal -- just to make your app installable via `dpkg` -- and doesn't
|
||||
# fully conform to Debian packaging guideliens (`lintian` raises a few warnings/errors)
|
||||
mk_deb() {
|
||||
# TODO update this part to package the artifacts that make sense for your project
|
||||
dobin target/$TARGET/release/iptoasn-webservice
|
||||
}
|
||||
|
||||
main() {
|
||||
mk_artifacts
|
||||
mk_tarball
|
||||
|
||||
if [ $TRAVIS_OS_NAME = linux ]; then
|
||||
if [ ! -z $MAKE_DEB ]; then
|
||||
dtd=$(mktempd)
|
||||
mkdir -p $dtd/debian/usr/bin
|
||||
|
||||
mk_deb
|
||||
|
||||
mkdir -p $dtd/debian/DEBIAN
|
||||
cat >$dtd/debian/DEBIAN/control <<EOF
|
||||
Package: $PROJECT_NAME
|
||||
Version: ${TRAVIS_TAG#v}
|
||||
Architecture: $(architecture $TARGET)
|
||||
Maintainer: $DEB_MAINTAINER
|
||||
Description: $DEB_DESCRIPTION
|
||||
EOF
|
||||
|
||||
fakeroot dpkg-deb --build $dtd/debian
|
||||
mv $dtd/debian.deb $PROJECT_NAME-$TRAVIS_TAG-$TARGET.deb
|
||||
rm -r $dtd
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
|
@ -1,57 +0,0 @@
|
|||
# `install` phase: install stuff needed for the `script` phase
|
||||
|
||||
set -ex
|
||||
|
||||
. $(dirname $0)/utils.sh
|
||||
|
||||
install_c_toolchain() {
|
||||
case $TARGET in
|
||||
aarch64-unknown-linux-gnu)
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
gcc-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross
|
||||
;;
|
||||
*)
|
||||
# For other targets, this is handled by addons.apt.packages in .travis.yml
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_rustup() {
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION
|
||||
|
||||
rustc -V
|
||||
cargo -V
|
||||
}
|
||||
|
||||
install_standard_crates() {
|
||||
if [ $(host) != "$TARGET" ]; then
|
||||
rustup target add $TARGET
|
||||
fi
|
||||
}
|
||||
|
||||
configure_cargo() {
|
||||
local prefix=$(gcc_prefix)
|
||||
|
||||
if [ ! -z $prefix ]; then
|
||||
# information about the cross compiler
|
||||
${prefix}gcc -v
|
||||
|
||||
# tell cargo which linker to use for cross compilation
|
||||
mkdir -p .cargo
|
||||
cat >>.cargo/config <<EOF
|
||||
[target.$TARGET]
|
||||
linker = "${prefix}gcc"
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
install_c_toolchain
|
||||
install_rustup
|
||||
install_standard_crates
|
||||
configure_cargo
|
||||
|
||||
# TODO if you need to install extra stuff add it here
|
||||
}
|
||||
|
||||
main
|
40
ci/script.sh
40
ci/script.sh
|
@ -1,40 +0,0 @@
|
|||
# `script` phase: you usually build, test and generate docs in this phase
|
||||
|
||||
set -ex
|
||||
|
||||
. $(dirname $0)/utils.sh
|
||||
|
||||
# TODO modify this function as you see fit
|
||||
# PROTIP Always pass `--target $TARGET` to cargo commands, this makes cargo output build artifacts
|
||||
# to target/$TARGET/{debug,release} which can reduce the number of needed conditionals in the
|
||||
# `before_deploy`/packaging phase
|
||||
run_test_suite() {
|
||||
case $TARGET in
|
||||
# configure emulation for transparent execution of foreign binaries
|
||||
aarch64-unknown-linux-gnu)
|
||||
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
|
||||
;;
|
||||
arm*-unknown-linux-gnueabihf)
|
||||
export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ! -z "$QEMU_LD_PREFIX" ]; then
|
||||
# Run tests on a single thread when using QEMU user emulation
|
||||
export RUST_TEST_THREADS=1
|
||||
fi
|
||||
|
||||
cargo build --target $TARGET --verbose
|
||||
cargo test --target $TARGET
|
||||
|
||||
# sanity check the file type
|
||||
file target/$TARGET/debug/iptoasn-webservice
|
||||
}
|
||||
|
||||
main() {
|
||||
run_test_suite
|
||||
}
|
||||
|
||||
main
|
71
ci/utils.sh
71
ci/utils.sh
|
@ -1,71 +0,0 @@
|
|||
mktempd() {
|
||||
echo $(mktemp -d 2>/dev/null || mktemp -d -t tmp)
|
||||
}
|
||||
|
||||
host() {
|
||||
case "$TRAVIS_OS_NAME" in
|
||||
linux)
|
||||
echo x86_64-unknown-linux-gnu
|
||||
;;
|
||||
osx)
|
||||
echo x86_64-apple-darwin
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
gcc_prefix() {
|
||||
case "$TARGET" in
|
||||
aarch64-unknown-linux-gnu)
|
||||
echo aarch64-linux-gnu-
|
||||
;;
|
||||
arm*-gnueabihf)
|
||||
echo arm-linux-gnueabihf-
|
||||
;;
|
||||
*-musl)
|
||||
echo musl-
|
||||
;;
|
||||
*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
dostrip() {
|
||||
local stu=strip prefix=$(gcc_prefix)
|
||||
if which ${prefix}strip > /dev/null; then
|
||||
stu=${prefix}strip
|
||||
fi
|
||||
if strip --version 2>/dev/null | fgrep GNU >/dev/null ; then
|
||||
$stu -s $1
|
||||
else
|
||||
$stu $1
|
||||
fi
|
||||
}
|
||||
|
||||
dobin() {
|
||||
[ -z $MAKE_DEB ] && die 'dobin: $MAKE_DEB not set'
|
||||
[ $# -lt 1 ] && die "dobin: at least one argument needed"
|
||||
|
||||
local f prefix=$(gcc_prefix)
|
||||
for f in "$@"; do
|
||||
install -m0755 $f $dtd/debian/usr/bin/
|
||||
dostrip $dtd/debian/usr/bin/$(basename $f)
|
||||
done
|
||||
}
|
||||
|
||||
architecture() {
|
||||
case $1 in
|
||||
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl)
|
||||
echo amd64
|
||||
;;
|
||||
i686-unknown-linux-gnu|i686-unknown-linux-musl)
|
||||
echo i386
|
||||
;;
|
||||
arm*-unknown-linux-gnueabihf)
|
||||
echo armhf
|
||||
;;
|
||||
*)
|
||||
die "architecture: unexpected target $TARGET"
|
||||
;;
|
||||
esac
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
FROM alpine:3.7
|
||||
FROM alpine:3.17.7
|
||||
|
||||
COPY Cargo.* /tmp/iptoasn/
|
||||
COPY src /tmp/iptoasn/src
|
||||
|
|
|
@ -4,9 +4,9 @@ use hyper::{self, Client};
|
|||
use hyper_native_tls::NativeTlsClient;
|
||||
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::Bound::{Included, Unbounded};
|
||||
use std::io::prelude::*;
|
||||
use std::net::IpAddr;
|
||||
use std::ops::Bound::{Included, Unbounded};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -1,17 +1,18 @@
|
|||
#[macro_use]
|
||||
extern crate horrorshow;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate router;
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
|
||||
mod asns;
|
||||
mod webservice;
|
||||
|
||||
use crate::asns::*;
|
||||
use crate::webservice::*;
|
||||
use clap::{App, Arg};
|
||||
use clap::Arg;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
@ -35,13 +36,10 @@ fn update_asns(asns_arc: &Arc<RwLock<Arc<ASNs>>>, db_url: &str) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("iptoasn webservice")
|
||||
.version("0.2.0")
|
||||
.author("Frank Denis")
|
||||
.about("Webservice for https://iptoasn.com")
|
||||
let matches = app_from_crate!()
|
||||
.arg(
|
||||
Arg::with_name("listen_addr")
|
||||
.short("l")
|
||||
Arg::new("listen_addr")
|
||||
.short('l')
|
||||
.long("listen")
|
||||
.value_name("ip:port")
|
||||
.help("Webservice IP and port")
|
||||
|
@ -49,8 +47,8 @@ fn main() {
|
|||
.default_value("0.0.0.0:53661"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("db_url")
|
||||
.short("u")
|
||||
Arg::new("db_url")
|
||||
.short('u')
|
||||
.long("dburl")
|
||||
.value_name("url")
|
||||
.help("URL of the gzipped database")
|
||||
|
|
|
@ -7,7 +7,7 @@ use iron::prelude::*;
|
|||
use iron::status;
|
||||
use iron::{typemap, BeforeMiddleware};
|
||||
use router::Router;
|
||||
use serde_json;
|
||||
|
||||
use std::net::IpAddr;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
|
Loading…
Reference in New Issue