Merge pull request #582 from AleoHQ/leo-add-no-logout

[CLI, CI] Leo add does not require login
This commit is contained in:
Collin Chin 2021-01-30 14:16:04 -05:00 committed by GitHub
commit 66c736b3d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 10 deletions

View File

@ -34,13 +34,9 @@ jobs:
command: install command: install
args: --path . args: --path .
- name: 'leo login & add' - name: 'leo add (w/o login) & remove'
env:
USER: ${{ secrets.ALEO_PM_USERNAME }}
PASS: ${{ secrets.ALEO_PM_PASSWORD }}
run: | run: |
cd .. && leo new my-app && cd my-app cd .. && leo new my-app && cd my-app
leo login -u "$USER" -p "$PASS"
leo add argus4130/xnor leo add argus4130/xnor
leo remove xnor leo remove xnor
leo clean leo clean

48
.github/workflows/leo-login-logout.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: leo-login-logout
on:
pull_request:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- 'documentation/**'
env:
RUST_BACKTRACE: 1
jobs:
add:
name: Add Package ('leo add')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- name: Install Leo
uses: actions-rs/cargo@v1
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
with:
command: install
args: --path .
- name: 'leo login & logout'
env:
USER: ${{ secrets.ALEO_PM_USERNAME }}
PASS: ${{ secrets.ALEO_PM_PASSWORD }}
run: |
cd .. && leo new my-app && cd my-app
leo login -u "$USER" -p "$PASS"
leo add argus4130/xnor
leo remove xnor
leo clean
leo logout

View File

@ -115,10 +115,6 @@ impl CLI for AddCommand {
// Begin "Adding" context for console logging // Begin "Adding" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Adding"); let span = tracing::span!(tracing::Level::INFO, "Adding");
let _enter = span.enter(); let _enter = span.enter();
// token can only be there if user has signed into Aleo PM
// so we need to verify that token exists before doing anything else
let token = read_token().map_err(|_| -> CLIError { NotAuthorized.into() })?;
let path = current_dir()?; let path = current_dir()?;
// Enforce that the current directory is a leo package // Enforce that the current directory is a leo package
@ -137,7 +133,17 @@ impl CLI for AddCommand {
json.insert("version", version); json.insert("version", version);
} }
match client.post(&url).bearer_auth(token).json(&json).send() { let result = match read_token() {
Ok(token) => {
tracing::info!("Logged in, using token to authorize");
client.post(&url).bearer_auth(token)
}
Err(_) => client.post(&url),
}
.json(&json)
.send();
match result {
Ok(response) => (response, package_name), Ok(response) => (response, package_name),
//Cannot connect to the server //Cannot connect to the server
Err(_error) => { Err(_error) => {