Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ coverage: test _coverage
test-pwd +args="":
#!/usr/bin/env bash
set -e
export RUST_BACKTRACE=0 RUST_LOG="graph-builder=trace,cincinnati=trace,dkregistry=trace"
export RUST_BACKTRACE=1 RUST_LOG="graph-builder=trace,cincinnati=trace,dkregistry=trace"
pushd {{invocation_directory()}}
cargo test {{args}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub mod plugin;

pub use plugin::{
GithubOpenshiftSecondaryMetadataScraperPlugin, GithubOpenshiftSecondaryMetadataScraperSettings,
GITHUB_SCRAPER_TOKEN_PATH_ENV,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub static DEFAULT_OUTPUT_WHITELIST: &[&str] = &[
"raw/metadata.json",
];

/// Environment variable name for the Oauth token path
pub static GITHUB_SCRAPER_TOKEN_PATH_ENV: &str = "CINCINNATI_GITHUB_SCRAPER_OAUTH_TOKEN_PATH";

static USER_AGENT: &str = "openshift/cincinnati";

/// Plugin settings.
Expand All @@ -28,6 +31,7 @@ pub struct GithubOpenshiftSecondaryMetadataScraperSettings {
/// An empty vector is regarded as a configuration error.
#[default(DEFAULT_OUTPUT_WHITELIST.iter().map(|s| (*s).to_string()).collect())]
output_whitelist: Vec<String>,
oauth_token_path: Option<PathBuf>,
}

impl GithubOpenshiftSecondaryMetadataScraperSettings {
Expand Down Expand Up @@ -61,6 +65,9 @@ pub struct GithubOpenshiftSecondaryMetadataScraperPlugin {

#[default(FuturesMutex::new(Default::default()))]
state: FuturesMutex<State>,
oauth_token: Option<String>,

client: reqwest::Client,
}

impl GithubOpenshiftSecondaryMetadataScraperPlugin {
Expand All @@ -81,9 +88,25 @@ impl GithubOpenshiftSecondaryMetadataScraperPlugin {
)
.context("Parsing output whitelist strings as regex")?;

let oauth_token = (&settings.oauth_token_path)
.clone()
.map(|path| {
std::fs::read_to_string(&path)
.context(format!("Reading Oauth token from {:?}", &path))
})
.transpose()?
.map(|token| {
token
.lines()
.next()
.map(|first_line| first_line.trim().to_owned())
})
.flatten();

Ok(Self {
settings,
output_whitelist,
oauth_token,

..Default::default()
})
Expand All @@ -94,10 +117,21 @@ impl GithubOpenshiftSecondaryMetadataScraperPlugin {
let url = github_v3::branches_url(&self.settings.github_org, &self.settings.github_repo);

trace!("Getting branches from {}", &url);
let bytes = reqwest::Client::new()
.get(&url)
.header(reqwest::header::USER_AGENT, USER_AGENT)
.header(reqwest::header::ACCEPT, "application/vnd.github.v3+json")

let request = {
let request = self
.client
.get(&url)
.header(reqwest::header::USER_AGENT, USER_AGENT)
.header(reqwest::header::ACCEPT, "application/vnd.github.v3+json");
if let Some(token) = &self.oauth_token {
request.header(reqwest::header::AUTHORIZATION, format!("token {}", token))
} else {
request
}
};

let bytes = request
.send()
.await
.context(format!("Getting branches from {}", &url))?
Expand Down Expand Up @@ -310,6 +344,8 @@ mod network_tests {

let tmpdir = tempfile::tempdir()?;

let oauth_token_path = std::env::var(GITHUB_SCRAPER_TOKEN_PATH_ENV)?;

let settings =
toml::from_str::<GithubOpenshiftSecondaryMetadataScraperSettings>(&format!(
r#"
Expand All @@ -318,13 +354,15 @@ mod network_tests {
branch = "master"
output_whitelist = [ {} ]
output_directory = {:?}
oauth_token_path = {:?}
"#,
DEFAULT_OUTPUT_WHITELIST
.iter()
.map(|s| format!(r#"{:?}"#, s))
.collect::<Vec<_>>()
.join(", "),
&tmpdir.path(),
oauth_token_path,
))?;

debug!("Settings: {:#?}", &settings);
Expand Down
10 changes: 10 additions & 0 deletions dist/openshift/cincinnati.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ objects:
configMapKeyRef:
key: gb.rust_backtrace
name: cincinnati
envFrom:
- configMapRef:
name: environment-secrets
command:
- ${GB_BINARY}
args: [
Expand Down Expand Up @@ -198,6 +201,11 @@ objects:
pe.log.verbosity: ${{PE_LOG_VERBOSITY}}
pe.mandatory_client_parameters: "channel"
pe.rust_backtrace: "${RUST_BACKTRACE}"
- apiVersion: v1
kind: ConfigMap
metadata:
name: environment-secrets
data: ${{ENVIRONMENT_SECRETS}}
- apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -323,3 +331,5 @@ parameters:
displayName: Set RUST_BACKTRACE env var
- name: GB_CONFIG_PATH
value: "/etc/configs/gb.toml"
- name: ENVIRONMENT_SECRETS
value: '{ "CINCINNATI_GITHUB_SCRAPER_OAUTH_TOKEN_PATH": "/etc/secrets/github_token.key" }'
1 change: 1 addition & 0 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ oc new-app -f dist/openshift/cincinnati.yaml \
[[plugin_settings]]
name = "edge-add-remove"
' \
-p ENVIRONMENT_SECRETS="{}" \
;

# Wait for dc to rollout
Expand Down