Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from containerscrew/feature/new-pipelines
Browse files Browse the repository at this point in the history
Refactoring pipelines
  • Loading branch information
containerscrew authored Nov 17, 2023
2 parents 7a0f2c0 + f571747 commit f655017
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 97 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Rust Code Coverage 🚦

on:
push:
branches:
- 'main'
tags:
- '**'

jobs:
coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install grcov
run: |
curl -L https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf -
sudo mv grcov /usr/local/bin/
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable

- name: Install llvm-tools
run: rustup component add llvm-tools-preview

- name: Build and Test with Coverage
run: |
export RUSTFLAGS="-Cinstrument-coverage"
cargo build --verbose
LLVM_PROFILE_FILE="aws-sso-auth-%p-%m.profraw" cargo test --verbose
grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info
- name: Upload Code Coverage
uses: codecov/codecov-action@v2
with:
file: lcov.info
17 changes: 17 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Gitleaks 🕷️
on:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *" # run once a month
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 changes: 45 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,62 @@ name: Release 📦

on:
push:
# branches:
# - "*"
tags:
- 'v*.*.*'

jobs:
build:
release:
name: Release - ${{ matrix.platform.release_for }}
strategy:
matrix:
os: [macOS-latest]
rust: [stable]
runs-on: ${{ matrix.os }}
platform:
- release_for: linux-arm64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bin: aws-sso-auth
command: build

- release_for: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: aws-sso-auth
command: build

- release_for: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: aws-sso-auth
command: build

- release_for: macOS-arm64
os: macOS-latest
target: aarch64-apple-darwin
bin: aws-sso-auth
command: build

runs-on: ${{ matrix.platform.os }}
steps:
- name: Setup Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.rust }}
- name: Checkout
uses: actions/checkout@v3

- name: Build for macOS
if: matrix.os == 'macOS-latest'
run: make release_mac
- name: Setup MUSL
if: matrix.platform.os == 'ubuntu-latest'
run: |
sudo apt-get -qq install musl-tools
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: ${{ matrix.platform.command }}
target: ${{ matrix.platform.target }}
args: "--release"
strip: true
- name: Package zip
run: |
make package ARCH=${{ matrix.platform.release_for }} TARGET=${{ matrix.platform.target }}
- name: Release
uses: softprops/action-gh-release@v1
with:
body: '[Changelog](https://github.com/containerscrew/aws-sso-rs/blob/main/CHANGELOG.md)'
files: "*.zip\n*.rpm"
body: '[Changelog](https://github.com/containerscrew/aws-sso-auth/blob/main/CHANGELOG.md)'
files: "*.zip"
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name: Test 🛠️
on:
push:
branches:
- "main"
- '**'
tags:
- '*'
- '**'

env:
CARGO_TERM_COLOR: always

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-byte-order-marker
- id: check-case-conflict
Expand All @@ -15,15 +15,15 @@ repos:
hooks:
- id: doctoc
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.1
rev: v8.18.0
hooks:
- id: gitleaks
- repo: https://github.com/pre-commit/pre-commit
rev: v2.5.1
rev: v3.5.0
hooks:
- id: validate_manifest
- repo: https://github.com/doublify/pre-commit-rust
rev: master
rev: v1.0
hooks:
# - id: fmt
# args: ['--verbose', '--']
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ rust-version = "1.72.0"


[dependencies]
aws-config = "0.56.1"
aws-sdk-sso = "0.32.0"
aws-sdk-ssooidc = "0.32.0"
aws-config = "0.100.0"
aws-sdk-sso = "0.37.0"
aws-sdk-ssooidc = "0.37.0"
clap = { version = "4.4.4", features = ["derive"] }
configparser = "3.0.2"
current_platform = "0.2.0"
Expand Down
15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ SHELL:=/bin/sh
VERSION = $(patsubst "%",%, $(word 3, $(shell grep version Cargo.toml)))
BUILD_TIME = $(shell date +"%Y/%m/%d %H:%M:%S")
GIT_REVISION = $(shell git log -1 --format="%h")
RUST_VERSION = $(word 2, $(shell rustc -V))
LONG_VERSION = "$(VERSION) ( rev: $(GIT_REVISION), rustc: $(RUST_VERSION), build at: $(BUILD_TIME) )"
BIN_NAME = aws-sso-rs

export LONG_VERSION

BINARY_NAME = aws-sso-auth


help: ## this help
@awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n make \033[36m<target> \033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
Expand All @@ -19,9 +18,5 @@ doctoc: ## Create table of contents with doctoc
pre-commit: ## Run pre-commit
pre-commit run -a

release_mac: ## Start release for Mac OSX
cargo build --release --target=x86_64-apple-darwin
zip -j ${BIN_NAME}-v${VERSION}-x86_64-mac.zip target/x86_64-apple-darwin/release/${BIN_NAME}

run: ## Cargo run --release
cargo run --release
package: ## Package binary with zip
zip -j ${BINARY_NAME}-v${VERSION}-$(ARCH).zip target/$(TARGET)/release/${BINARY_NAME}
67 changes: 17 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
<p align="center" >
<img src="assets/rust-logo.svg" alt="logo" width="250"/>
<h3 align="center">aws-sso-rs (BETA)</h3>
<p align="center">Get your AWS credentials using SSO</p>
<h3 align="center">aws-sso-auth</h3>
<p align="center">Fetch your local ~/.aws/credentials using AWS SSO</p>
<p align="center">Build with ❤ in Rust</p>
</p>

<p align="center" >
<img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/containerscrew/aws-sso-auth">
[![License](https://img.shields.io/github/license/containerscrew/aws-sso-auth)](/LICENSE)
[![codecov](https://codecov.io/gh/containerscrew/aws-sso-auth/branch/main/graph/badge.svg)](https://codecov.io/gh/containerscrew/aws-sso-auth)
[![Release](https://img.shields.io/github/release/containerscrew/aws-sso-rs)](https://github.com/containerscrew/aws-sso-rs/releases/latest)
[![GitHub Releases Stats](https://img.shields.io/github/downloads/containerscrew/aws-sso-auth/total.svg?logo=github)](https://somsubhra.github.io/github-release-stats/?username=containerscrew&repository=aws-sso-auth)
</p>


<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Badges](#badges)
- [Disclaimer](#disclaimer)
- [Pipelines](#pipelines)
- [Introduction](#introduction)
- [Installation](#installation)
- [Pre-commit](#pre-commit)
- [Usage](#usage)
- [Switching accounts](#switching-accounts)
- [Fish shell](#fish-shell)
- [TO DO](#to-do)
- [Developing](#developing)
- [Requirements](#requirements)
- [Clone](#clone)
- [Cargo run](#cargo-run)
- [Build](#build)
- [TO DO (not implemented yet)](#to-do-not-implemented-yet)
- [Contribution](#contribution)
- [LICENSE](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Badges
# Pipelines
![Test Status](https://github.com/containerscrew/aws-sso-rs/actions/workflows/test.yml/badge.svg)
![Release Status](https://github.com/containerscrew/aws-sso-rs/actions/workflows/release.yml/badge.svg)
[![License](https://img.shields.io/github/license/containerscrew/aws-sso-rs)](/LICENSE)
[![Release](https://img.shields.io/github/release/containerscrew/aws-sso-rs)](https://github.com/containerscrew/aws-sso-rs/releases/latest)

# Disclaimer

> I don't have any experience with Rust. I'm not a professional software developer. But, I enjoy trying to create things.
I have some experience in python and Golang. I've only been programming in Rust for 2 weeks and trying to understand the language well. Rust is a new language which I find very interesting and I have fallen in love with it from the first moment, that is why I decided to make this tool in Rust.
Probably this tool is more easy to do in Go or Python, but simple things are boring :)
![Git Leaks Status](https://github.com/containerscrew/aws-sso-auth/actions/workflows/gitleaks.yml/badge.svg)
![Coverage](https://github.com/containerscrew/aws-sso-auth/actions/workflows/coverage.yml/badge.svg)

# Introduction

This tools is just in **BETA** mode. It's working fine and you can download all credentials in your `$HOME/.aws/credentials`. In fact, `this README`is still in progress.
....blablbla

# Installation

TO DO: provide automated pipelines to generate binaries with ARM&AMD binaries to `github releases`. Provide formula for brew mac users, and more!
...TO DO


By the moment, take a look to the **Developing** section below to use this tool locally using **cargo**.

## Pre-commit
[pre-commit](./docs/pre-commit.md)
Expand Down Expand Up @@ -94,41 +91,11 @@ Type `aws-profile` in your terminal, and you will see all the accounts you have
# TO DO

* Logging with env_logger (aws_config it's printing some unnecessary info)
> https://docs.aws.amazon.com/sdk-for-rust/latest/dg/logging.html
> https://github.com/awslabs/aws-sdk-rust/discussions/771
* Code refactoring
* Github actions pipeline to create binary and push to `releases`
* Testing
* Imagine you have 600 accounts with access in your AWS SSO portal, but you only want to fetch 100. How you can limit that?

* Speed credentials download with `async` + `tokio:spawn` threading. The current code is not as fast as I would like.
Avoid this problem: limit number of threads
> thread 'tokio-runtime-worker' panicked at 'Can't get account credentials: TooManyRequestsException(TooManyRequestsException { message: Some("HTTP 429 Unknown Code")
# Developing

## Requirements

* Rust
* Cargo
* Rustup

Take a look to the [official documentation](https://www.rust-lang.org/tools/install)

## Clone

```bash
git clone https://github.com/containerscrew/aws-sso-rs.git
cd aws-sso-rs
```

## Cargo run

```bash
cargo run --start-url https://XXXXXX.awsapps.com/start --region eu-west-1
```

## Build

```bash
Expand Down
8 changes: 3 additions & 5 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::utils::extend_path;
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{BufRead, Write};
use std::fs::{OpenOptions};
use std::io::{Write};
use std::process::exit;
use std::{fs, io};
use tracing::{error, info};

// The name of the file and directory for the configuration will not be custom by the moment
use tracing::{error, info};
pub const CONFIG_FILE_PATH: &str = "~/.aws/aws-sso-auth.json";
pub const CREDENTIALS_FILE_PATH: &str = "~/.aws/credentials";

Expand Down
5 changes: 4 additions & 1 deletion src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ pub async fn async_start(
let account_list = get_account_list(&sso_client, &token).await?;

// Provide info about all account that should be downloaded
info!("{} accounts to fetch. Each account can have multiple roles", account_list.len());
info!(
"{} accounts to fetch. Each account can have multiple roles",
account_list.len()
);

let mut all_credentials: Vec<AccountCredentials> = vec![];

Expand Down
9 changes: 4 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fs::{File, OpenOptions};
use crate::commands::config::{CONFIG_FILE_PATH, CREDENTIALS_FILE_PATH};
use crate::commands::config::{CREDENTIALS_FILE_PATH};
use aws_sso_auth::AccountCredentials;
use colored::Colorize;
use configparser::ini::Ini;
use log::{error, info};

use std::io;
use std::io::{Read, Write};
use std::process::exit;
use std::io::{Write};


pub fn print_banner() {
let banner = r#"
Expand Down Expand Up @@ -80,7 +80,6 @@ pub fn write_configuration(all_credentials: Vec<AccountCredentials>, region_name
info!("Configuration file saved!")
}


// pub fn config_file_exists(path: &str) {
// // This function checks if config file ~/.aws/aws-sso-auth.json exists
// // If not, will try to create a new one
Expand Down

0 comments on commit f655017

Please sign in to comment.