Skip to content

Commit

Permalink
Merge pull request #1840 from habitat-sh/sougata/enable_native_packages
Browse files Browse the repository at this point in the history
Enables native packages by default
  • Loading branch information
rahulgoel1 authored Sep 19, 2024
2 parents 808a9ae + dd9cb42 commit ba40b3d
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 149 deletions.
47 changes: 21 additions & 26 deletions components/builder-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,18 @@ impl Default for S3Cfg {
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct ApiCfg {
pub data_path: PathBuf,
pub log_path: PathBuf,
pub data_path: PathBuf,
pub log_path: PathBuf,
/// Location of Builder encryption keys
pub key_path: KeyCache,
pub targets: Vec<PackageTarget>,
pub build_targets: Vec<PackageTarget>,
pub key_path: KeyCache,
pub targets: Vec<PackageTarget>,
pub build_targets: Vec<PackageTarget>,
#[serde(with = "deserialize_into_vec")]
pub features_enabled: Vec<String>,
pub build_on_upload: bool,
pub private_max_age: usize,
pub saas_bldr_url: String,
pub features_enabled: Vec<String>,
pub build_on_upload: bool,
pub private_max_age: usize,
pub saas_bldr_url: String,
pub suppress_autobuild_origins: Vec<String>,
pub allowed_native_package_origins: Vec<String>,
}

mod deserialize_into_vec {
Expand All @@ -127,19 +126,18 @@ mod deserialize_into_vec {

impl Default for ApiCfg {
fn default() -> Self {
ApiCfg { data_path: PathBuf::from("/hab/svc/builder-api/data"),
log_path: env::temp_dir(),
key_path: KeyCache::new("/hab/svc/builder-api/files"),
targets: vec![target::X86_64_LINUX,
target::X86_64_LINUX_KERNEL2,
target::X86_64_WINDOWS,],
build_targets: vec![target::X86_64_LINUX, target::X86_64_WINDOWS],
features_enabled: vec!["jobsrv".to_string()],
build_on_upload: true,
private_max_age: 300,
saas_bldr_url: "https://bldr.habitat.sh".to_string(),
suppress_autobuild_origins: vec![],
allowed_native_package_origins: vec![], }
ApiCfg { data_path: PathBuf::from("/hab/svc/builder-api/data"),
log_path: env::temp_dir(),
key_path: KeyCache::new("/hab/svc/builder-api/files"),
targets: vec![target::X86_64_LINUX,
target::X86_64_LINUX_KERNEL2,
target::X86_64_WINDOWS,],
build_targets: vec![target::X86_64_LINUX, target::X86_64_WINDOWS],
features_enabled: vec!["jobsrv".to_string()],
build_on_upload: true,
private_max_age: 300,
saas_bldr_url: "https://bldr.habitat.sh".to_string(),
suppress_autobuild_origins: vec![], }
}
}

Expand Down Expand Up @@ -343,7 +341,6 @@ mod tests {
build_on_upload = false
private_max_age = 400
suppress_autobuild_origins = ["origin1", "origin2"]
allowed_native_package_origins = []
[http]
listen = "0:0:0:0:0:0:0:1"
Expand Down Expand Up @@ -433,8 +430,6 @@ mod tests {
assert_eq!(&config.api.suppress_autobuild_origins,
&["origin1".to_string(), "origin2".to_string()]);

assert_eq!(config.api.allowed_native_package_origins.len(), 0);

assert_eq!(&format!("{}", config.jobsrv), "http://1.2.3.4:1234");

assert_eq!(config.http.port, 9636);
Expand Down
8 changes: 3 additions & 5 deletions components/builder-api/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ features! {
const Jobsrv = 0b0000_0010,
const LegacyProject = 0b0000_0011,
const Artifactory = 0b0000_0100,
const BuildDeps = 0b0000_1000,
const NativePackages = 0b0001_0000
const BuildDeps = 0b0000_1000
}
}

Expand Down Expand Up @@ -106,9 +105,8 @@ fn enable_features(config: &Config) {
("JOBSRV", feat::Jobsrv),
("LEGACYPROJECT", feat::LegacyProject),
("ARTIFACTORY", feat::Artifactory),
("BUILDDEPS", feat::BuildDeps),
("NATIVEPACKAGES",
feat::NativePackages),]);
("BUILDDEPS", feat::BuildDeps),]);

for key in &config.api.features_enabled {
if features.contains_key(key.as_str()) {
info!("Enabling feature: {}", key);
Expand Down
34 changes: 0 additions & 34 deletions components/builder-api/src/server/resources/pkgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use crate::{bldr_core::{error::Error::RpcError,
metrics::CounterMetric},
config::Config,
db::models::{channel::{Channel,
ChannelWithPromotion},
origin::*,
Expand Down Expand Up @@ -128,18 +127,6 @@ pub struct OriginScheduleStatus {
limit: String,
}

fn enabled_native_upload() -> bool { feat::is_enabled(feat::NativePackages) }

fn is_origin_allowed(origin: &str, config: &Config) -> bool {
if config.api
.allowed_native_package_origins
.contains(&origin.to_string())
{
return true;
}
false
}

pub struct Packages {}

impl Packages {
Expand Down Expand Up @@ -1126,27 +1113,6 @@ async fn do_upload_package_finish(req: &HttpRequest,
}
};

if package_type == PackageType::Native && !enabled_native_upload() {
debug!("Unsupported package type {}.", package_type);
let body = Bytes::from(
format!("Uploading '{}' package is not supported", package_type).into_bytes(),
);
let body = BoxBody::new(body);
return HttpResponse::with_body(StatusCode::UNPROCESSABLE_ENTITY, body);
};

if package_type == PackageType::Native
&& !is_origin_allowed(&ident.origin, &req_state(req).config)
{
debug!("Native packages not allowed for the origin {:?}",
ident.origin.clone());
let body = Bytes::from(format!("Native Package upload for the origin '{}' is not \
supported",
ident.origin.clone()).into_bytes());
let body = BoxBody::new(body);
return HttpResponse::with_body(StatusCode::UNPROCESSABLE_ENTITY, body);
};

let target_from_artifact = match archive.target() {
Ok(target) => target,
Err(e) => {
Expand Down
22 changes: 11 additions & 11 deletions test/builder-api/src/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,19 +686,19 @@ describe('Channels API', function () {
.end(function (err, res) {
expect(res.body.channel).to.equal('unstable');
expect(res.body.target).to.equal('x86_64-linux');
expect(res.body.data.length).to.equal(12);
expect(res.body.data.length).to.equal(13);
expect(res.body.data[0].origin).to.equal('neurosis');
expect(res.body.data[0].name).to.equal('abracadabra');
expect(res.body.data[0].version).to.equal('3.0');
expect(res.body.data[0].release).to.equal('20190618175235');
expect(res.body.data[10].origin).to.equal('neurosis');
expect(res.body.data[10].name).to.equal('testapp');
expect(res.body.data[10].version).to.equal('0.1.13');
expect(res.body.data[10].release).to.equal('20190511004436');
expect(res.body.data[11].origin).to.equal('neurosis');
expect(res.body.data[11].name).to.equal('testapp2');
expect(res.body.data[11].version).to.equal('v1.2.3-master');
expect(res.body.data[11].release).to.equal('20181018162212');
expect(res.body.data[11].name).to.equal('testapp');
expect(res.body.data[11].version).to.equal('0.1.13');
expect(res.body.data[11].release).to.equal('20190511004436');
expect(res.body.data[12].origin).to.equal('neurosis');
expect(res.body.data[12].name).to.equal('testapp2');
expect(res.body.data[12].version).to.equal('v1.2.3-master');
expect(res.body.data[12].release).to.equal('20181018162212');
done(err);
});
});
Expand Down Expand Up @@ -904,9 +904,9 @@ describe('Channels API', function () {
.expect(200)
.end(function (err, res) {
expect(res.body.range_start).to.equal(0);
expect(res.body.range_end).to.equal(30);
expect(res.body.total_count).to.equal(31);
expect(res.body.data.length).to.equal(31);
expect(res.body.range_end).to.equal(31);
expect(res.body.total_count).to.equal(32);
expect(res.body.data.length).to.equal(32);
done(err);
});
});
Expand Down
Loading

0 comments on commit ba40b3d

Please sign in to comment.