Skip to content

Commit

Permalink
Merge pull request #107 from allcloud-jonathan/master
Browse files Browse the repository at this point in the history
[PR] Code Coverage
  • Loading branch information
Jonathan committed Feb 12, 2021
2 parents 6760a9b + 6b1f801 commit 727ebd0
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 58 deletions.
41 changes: 0 additions & 41 deletions .circleci/config.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.go text eol=lf
26 changes: 26 additions & 0 deletions .github/workflow/upload_assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
release:
types: [created]

name: Upload release assets after release is created
jobs:
build:
name: build binaries
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.15.x
- name: Checkout code
uses: actions/checkout@v2
- name: build
run: |
echo "GO111MODULE=on" >> $GITHUB_ENV
make zip
- name: Upload release assets
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: './assets/*'
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: run tests
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Checkout code
uses: actions/checkout@v2
- name: Run linters
uses: golangci/golangci-lint-action@v2
with:
version: v1.29

test:
strategy:
matrix:
go: [1.15]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v2
- run: go test -v -coverprofile=profile ./...

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile
flag-name: Platform-${{ matrix.platform }}
parallel: true
# notifies that all test jobs are finished.
finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Clisso: CLI Single Sign-On

[![Coverage Status](https://coveralls.io/repos/github/allcloud-io/clisso/badge.svg)](https://coveralls.io/github/allcloud-io/clisso)

Clisso (pronounced `/ˈklIsoʊ/`) allows you to retrieve temporary credentials for cloud platforms
by authenticating with an identity provider (IdP).

Expand Down
20 changes: 16 additions & 4 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ func WriteToFile(c *Credentials, filename string, section string) error {
return err
}
cfg.DeleteSection(section)
cfg.Section(section).NewKey("aws_access_key_id", c.AccessKeyID)
cfg.Section(section).NewKey("aws_secret_access_key", c.SecretAccessKey)
cfg.Section(section).NewKey("aws_session_token", c.SessionToken)
cfg.Section(section).NewKey(expireKey, c.Expiration.UTC().Format(time.RFC3339))
_, err = cfg.Section(section).NewKey("aws_access_key_id", c.AccessKeyID)
if err != nil {
return err
}
_, err = cfg.Section(section).NewKey("aws_secret_access_key", c.SecretAccessKey)
if err != nil {
return err
}
_, err = cfg.Section(section).NewKey("aws_session_token", c.SessionToken)
if err != nil {
return err
}
_, err = cfg.Section(section).NewKey(expireKey, c.Expiration.UTC().Format(time.RFC3339))
if err != nil {
return err
}

// Remove expired credentials.
for _, s := range cfg.Sections() {
Expand Down
10 changes: 5 additions & 5 deletions cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ var duration int
// OneLogin
var appID string

// Okta
// URL holds the Okta URL
var URL string

func init() {
// OneLogin
cmdAppsCreateOneLogin.Flags().StringVar(&appID, "app-id", "", "OneLogin app ID")
cmdAppsCreateOneLogin.Flags().StringVar(&provider, "provider", "", "Name of the Clisso provider")
cmdAppsCreateOneLogin.Flags().IntVar(&duration, "duration", 0, "(Optional) Session duration in seconds")
cmdAppsCreateOneLogin.MarkFlagRequired("app-id")
cmdAppsCreateOneLogin.MarkFlagRequired("provider")
mandatoryFlag(cmdAppsCreateOneLogin, "app-id")
mandatoryFlag(cmdAppsCreateOneLogin, "provider")

// Okta
cmdAppsCreateOkta.Flags().StringVar(&provider, "provider", "", "Name of the Clisso provider")
cmdAppsCreateOkta.Flags().StringVar(&URL, "url", "", "Okta app URL")
cmdAppsCreateOkta.Flags().IntVar(&duration, "duration", 0, "(Optional) Session duration in seconds")
cmdAppsCreateOkta.MarkFlagRequired("provider")
cmdAppsCreateOkta.MarkFlagRequired("url")
mandatoryFlag(cmdAppsCreateOkta, "provider")
mandatoryFlag(cmdAppsCreateOkta, "url")

// Build command tree
RootCmd.AddCommand(cmdApps)
Expand Down
5 changes: 4 additions & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func init() {
&writeToFile, "write-to-file", "w", "",
"Write credentials to this file instead of the default ($HOME/.aws/credentials)",
)
viper.BindPFlag("global.credentials-path", cmdGet.Flags().Lookup("write-to-file"))
err := viper.BindPFlag("global.credentials-path", cmdGet.Flags().Lookup("write-to-file"))
if err != nil {
log.Fatalf(color.RedString("Error binding flag global.credentials-path: %v"), err)
}
}

// processCredentials prints the given Credentials to a file and/or to the shell.
Expand Down
15 changes: 15 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"log"

"github.com/fatih/color"
"github.com/spf13/cobra"
)

func mandatoryFlag(cmd *cobra.Command, name string) {
err := cmd.MarkFlagRequired(name)
if err != nil {
log.Fatalf(color.RedString("Error marking flag %s as required: %v"), name, err)
}
}
8 changes: 4 additions & 4 deletions cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ func init() {
"Region in which the OneLogin API lives")
cmdProvidersCreateOneLogin.Flags().IntVar(&providerDuration, "duration", 0, "(Optional) Default session duration in seconds")

cmdProvidersCreateOneLogin.MarkFlagRequired("client-id")
cmdProvidersCreateOneLogin.MarkFlagRequired("client-secret")
cmdProvidersCreateOneLogin.MarkFlagRequired("subdomain")
mandatoryFlag(cmdProvidersCreateOneLogin, "client-id")
mandatoryFlag(cmdProvidersCreateOneLogin, "client-secret")
mandatoryFlag(cmdProvidersCreateOneLogin, "subdomain")

// Okta
cmdProvidersCreateOkta.Flags().StringVar(&baseURL, "base-url", "", "Okta base URL")
cmdProvidersCreateOkta.Flags().StringVar(&username, "username", "",
"Don't ask for a username and use this instead")
cmdProvidersCreateOkta.Flags().IntVar(&providerDuration, "duration", 0, "(Optional) Default session duration in seconds")

cmdProvidersCreateOkta.MarkFlagRequired("base-url")
mandatoryFlag(cmdProvidersCreateOkta, "base-url")

// Build command tree
RootCmd.AddCommand(cmdProviders)
Expand Down
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func init() {

func Execute(version string) {
VERSION = version
RootCmd.Execute()
err := RootCmd.Execute()
if err != nil {
log.Fatalf("Failed to execute: %v", err)
}
}

func initConfig() {
Expand Down
11 changes: 9 additions & 2 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func init() {
&readFromFile, "read-from-file", "r", "",
"Read credentials from this file instead of the default ($HOME/.aws/credentials)",
)
viper.BindPFlag("global.credentials-path", cmdStatus.Flags().Lookup("read-from-file"))
err := viper.BindPFlag("global.credentials-path", cmdStatus.Flags().Lookup("read-from-file"))
if err != nil {
log.Fatalf(color.RedString("Error binding flag global.credentials-path: %v"), err)
}
}

var cmdStatus = &cobra.Command{
Expand All @@ -36,6 +39,10 @@ var cmdStatus = &cobra.Command{

func printStatus() {
configfile, err := homedir.Expand(viper.GetString("global.credentials-path"))
if err != nil {
log.Fatalf(color.RedString("Failed to expand home: %s"), err)
}

profiles, err := aws.GetValidCredentials(configfile)
if err != nil {
log.Fatalf(color.RedString("Failed to retrieve non-expired credentials: %s"), err)
Expand All @@ -51,7 +58,7 @@ func printStatus() {

log.Print("The following apps currently have valid credentials:")
for _, p := range profiles {
table.Append([]string{p.Name, fmt.Sprintf("%d", p.ExpireAtUnix), fmt.Sprintf("%s", p.LifetimeLeft.Round(time.Second))})
table.Append([]string{p.Name, fmt.Sprintf("%d", p.ExpireAtUnix), p.LifetimeLeft.Round(time.Second).String()})
}

table.Render()
Expand Down

0 comments on commit 727ebd0

Please sign in to comment.