forked from cisco/lal-build-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
starts of a GithubBackend #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clux
wants to merge
1
commit into
master
Choose a base branch
from
github-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| #![allow(missing_docs)] | ||
| #![allow(unused_variables)] | ||
| #![allow(unused_imports)] | ||
| use std::vec::Vec; | ||
|
|
||
| use std::fs::File; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
|
|
||
| use hyper::Client; | ||
| use hyper::net::HttpsConnector; | ||
| use hyper_native_tls::NativeTlsClient; | ||
| use hubcaps::{Credentials, Github}; | ||
|
|
||
| use hubcaps::releases::{Release, Releases, ReleaseOptions, ReleaseOptionsBuilder}; | ||
|
|
||
| use core::{CliError, LalResult}; | ||
|
|
||
|
|
||
| /// Github credentials | ||
| #[derive(Serialize, Deserialize, Clone)] | ||
| pub struct GithubCredentials { | ||
| /// Personal access token with upload access | ||
| pub token: String, | ||
| } | ||
|
|
||
| /// Static Github locations | ||
| #[derive(Serialize, Deserialize, Clone, Default)] | ||
| pub struct GithubConfig { | ||
| /// Github organisation | ||
| pub organisation: String, | ||
| /// Optional upload credentials | ||
| pub credentials: Option<GithubCredentials>, | ||
| } | ||
|
|
||
| use super::{Backend, Component}; | ||
|
|
||
| /// Everything we need for Github to implement the Backend trait | ||
| pub struct GithubBackend { | ||
| /// Github config and credentials | ||
| pub config: GithubConfig, | ||
| /// Cache directory | ||
| pub cache: String, | ||
| /// Github client with a tls configured hyper client | ||
| pub client: Github, | ||
| } | ||
|
|
||
| impl GithubBackend { | ||
| pub fn new(cfg: &GithubConfig, cache: &str) -> Self { | ||
| let creds = if let Some(c) = cfg.credentials.clone() { | ||
| Credentials::Token(c.token) | ||
| } else { | ||
| Credentials::default() | ||
| }; | ||
| let github = Github::new( | ||
| format!("lal/{}", env!("CARGO_PKG_VERSION")), | ||
| Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap())), | ||
| creds | ||
| ); | ||
|
|
||
| GithubBackend { | ||
| config: cfg.clone(), | ||
| client: github, | ||
| cache: cache.into(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /// Artifact backend trait for `GithubBackend` | ||
| /// | ||
| /// This is intended to be used by the caching trait `CachedBackend`, but for | ||
| /// specific low-level use cases, these methods can be used directly. | ||
| impl Backend for GithubBackend { | ||
| fn get_versions(&self, name: &str, loc: &str) -> LalResult<Vec<u32>> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn get_latest_version(&self, name: &str, loc: &str) -> LalResult<u32> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn get_component_info( | ||
| &self, | ||
| name: &str, | ||
| version: Option<u32>, | ||
| loc: &str, | ||
| ) -> LalResult<Component> { | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn publish_artifact(&self, name: &str, version: u32, env: &str) -> LalResult<()> { | ||
| // this fn basically assumes all the sanity checks have been performed | ||
| // files must exist and lockfile must be sensible | ||
| let artdir = Path::new("./ARTIFACT"); | ||
| let tarball = artdir.join(format!("{}.tar.gz", name)); | ||
| let lockfile = artdir.join("lockfile.json"); | ||
|
|
||
|
|
||
| // 1. create a release | ||
| // TODO: needs sha from lockfile? | ||
| let res = Releases::new(&self.client, self.config.organisation.clone(), name); | ||
| let opts = ReleaseOptionsBuilder::new(version.to_string()).build(); | ||
| let release : Release = res.create(&opts)?; | ||
|
|
||
| // 2. create an asset on this release | ||
| // TODO: this part of the api is missing from hubcaps | ||
|
|
||
| // uri prefix if specific env upload | ||
| //let prefix = format!("env/{}/", env); | ||
| //let tar_uri = format!("{}{}/{}/{}.tar.gz", prefix, name, version, name); | ||
| //let mut tarf = File::open(tarball)?; | ||
| //upload_artifact(&self.config, &tar_uri, &mut tarf)?; | ||
|
|
||
| //let mut lockf = File::open(lockfile)?; | ||
| //let lf_uri = format!("{}{}/{}/lockfile.json", prefix, name, version); | ||
| //upload_artifact(&self.config, &lf_uri, &mut lockf)?; | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| fn get_cache_dir(&self) -> String { self.cache.clone() } | ||
|
|
||
| fn raw_fetch(&self, url: &str, dest: &PathBuf) -> LalResult<()> { | ||
| unimplemented!(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document how to get hold of one of these.