-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,620 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,91 @@ | ||
name: "Build Binary for MacOS, Linux, and Windows" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
concurrency: | ||
group: environment-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
get-version: | ||
name: "Get Spark Version" | ||
runs-on: "ubuntu-latest" | ||
env: | ||
SPARK_CLIENT_ID: "ClientId" | ||
SPARK_POOL_ID: "PoolId" | ||
SPARK_POOL_REGION: "us-east-1" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.4' | ||
|
||
- name: Build Spark CLI | ||
run: go build -o spark | ||
|
||
- name: Get Spark Version | ||
run: echo "SPARK_VERSION=$(./spark --version)" > spark-version.txt | ||
|
||
- name: Upload Spark Version Information | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: spark-version | ||
path: spark-version.txt | ||
build: | ||
name: "Build Spark Binaries" | ||
runs-on: "ubuntu-latest" | ||
env: | ||
SPARK_CLIENT_ID: "ClientId" | ||
SPARK_POOL_ID: "PoolId" | ||
SPARK_POOL_REGION: "us-east-1" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
strategy: | ||
matrix: | ||
os: [darwin, linux, windows] | ||
arch: [arm, amd64] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20.4' | ||
|
||
- name: Build Spark CLI | ||
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build | ||
|
||
- name: Download Spark Version Information | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: spark-version | ||
|
||
- name: Get Spark Version Information | ||
id: get-spark-version | ||
run: cat spark-version/spark-version.txt >> "$GITHUB_OUTPUT" | ||
|
||
- name: Publish Binary to Releases | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
file: spark-${{ matrix.os }}-${{ matrix.arch }} | ||
asset_name: spark-${{ matrix.os }}-${{ matrix.arch }} | ||
tag: ${{ steps.get-spark-version.outputs.SPARK_VERSION }} |
This file contains 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,2 @@ | ||
spark | ||
.git/ |
This file contains 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,38 @@ | ||
make SPARK_CLIENT_ID = "${SPARK_CLIENT_ID}" | ||
make SPARK_POOL_ID = "${SPARK_POOL_ID}" | ||
make SPARK_POOL_REGION = "${SPARK_POOL_REGION}" | ||
make GOOS = "${GOOS}" | ||
make GOARCH = "${GOARCH}" | ||
|
||
PKG = "gtech.dev/spark" | ||
|
||
ifndef SPARK_CLIENT_ID | ||
$(error SPARK_CLIENT_ID is not set) | ||
endif | ||
|
||
ifndef SPARK_POOL_ID | ||
$(error SPARK_POOL_ID is not set) | ||
endif | ||
|
||
ifndef SPARK_POOL_REGION | ||
$(error SPARK_POOL_REGION is not set) | ||
endif | ||
|
||
ifndef GOOS | ||
GOOS = "darwin" | ||
endif | ||
|
||
ifndef GOARCH | ||
GOARCH = "arm" | ||
endif | ||
|
||
ClientIdLdFlag = "${PKG}/cognito.ClientId=${SPARK_CLIENT_ID}" | ||
PoolIdLdFlag = "${PKG}/cognito.PoolId=${SPARK_POOL_ID}" | ||
PoolRegionFlag = "${PKG}/cognito.PoolRegion=${SPARK_POOL_REGION}" | ||
|
||
|
||
build: | ||
@GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags="-X ${ClientIdLdFlag} -X ${PoolIdLdFlag} ${PoolRegionFlag} -o spark-${GOOS}-${GOARCH}" | ||
|
||
run: | ||
@GOOS=${GOOS} GOARCH=${GOARCH} go run main.go -ldflags="-X ${ClientIdLdFlag} -X ${PoolIdLdFlag} ${PoolRegionFlag}" |
This file contains 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,37 @@ | ||
# SparkCli | ||
## Description | ||
The Spark CLI is used to perform some operations in AWS Cognito, such as password change, forgot password, performing first sign in, and registering a TOTP device. This CLI will compliment future CLIs such as Haze and Maroon which will utilize this CLI's data to perform their own operations. More information on those will be available when they are ready for release. | ||
|
||
This repository should be forked and the GitHub secrets and workflows updated to match the correct Cognito pool ID, pool region, and client ID! Failure to do this will cause it to not run. | ||
|
||
## Installation | ||
1. Navigate to the [releases page](https://github.com/hunoz/SparkCli/releases) and download the binary for your operating system. If you do not see your operating system, please submit an issue with your OS and ARCH so that it can be added. | ||
2. Place the binary in a location in your PATH (e.g. /usr/local/bin/spark) | ||
|
||
## Usage | ||
If you have not signed into the Cognito pool, please navigate to the `First Sign In` section. | ||
|
||
### First Sign In | ||
First Sign In is used if you have been added or created in a Cognito pool but have not performed a first sign in to verify your email and change your password. | ||
1. Run `spark first-sign-in` | ||
2. Follow the prompts as necessary | ||
|
||
### Auth | ||
Auth performs an auth to your Cognito pool and stores the token information for use with other tools that call Cognito-backed endpoints | ||
1. Run `spark auth`. If you want to force a refresh of your tokens, also add `--force` | ||
2. Follow the prompts to authenticate to the pool | ||
|
||
### Change Password | ||
Change Password will allow you to change your password. This operation uses the Cognito default password requirements. | ||
1. Run `spark change-password` | ||
2. Follow the prompts to change your password | ||
|
||
### Register TOTP | ||
Register TOTP will register a TOTP device to you. This does not currently support SMS, but may in the future. | ||
1. Run `spark register-totp` | ||
2. Follow the prompts to register a TOTP device | ||
|
||
### Reset Password | ||
Reset Password is for if you do not know your current password but have previously performed an initial sign in. | ||
1. Run `spark reset-password` | ||
2. Follow the prompts to reset your password |
This file contains 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,46 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/manifoldco/promptui" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"gtech.dev/spark/cognito" | ||
) | ||
|
||
var AuthCmd = &cobra.Command{ | ||
Use: "auth", | ||
Short: "Authenticate to Cognito and cache credentials", | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
viper.BindPFlag(FlagKey.Force, cmd.Flags().Lookup(FlagKey.Force)) | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
passwordValidator := cognito.CheckIfValidPassword | ||
usernamePrompt := promptui.Prompt{ | ||
Label: "Username", | ||
} | ||
username, err := usernamePrompt.Run() | ||
if err != nil { | ||
fmt.Printf("Error: %s\n", err) | ||
} | ||
|
||
passwordPrompt := promptui.Prompt{ | ||
Label: "Password", | ||
Mask: '*', | ||
Validate: passwordValidator, | ||
} | ||
password, err := passwordPrompt.Run() | ||
if err != nil { | ||
fmt.Printf("Error: %s\n", err) | ||
} | ||
|
||
cognitoClient := cognito.New() | ||
|
||
cognitoClient.InitiateAuth(username, password, viper.GetBool(FlagKey.Force)) | ||
}, | ||
} | ||
|
||
func init() { | ||
AuthCmd.Flags().Bool(FlagKey.Force, false, "Force update session, even if expiration time is > 6 hours") | ||
} |
This file contains 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,7 @@ | ||
package auth | ||
|
||
var FlagKey = struct { | ||
Force string | ||
}{ | ||
Force: "force", | ||
} |
This file contains 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,16 @@ | ||
package changepassword | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"gtech.dev/spark/cognito" | ||
) | ||
|
||
var ChangePasswordCmd = &cobra.Command{ | ||
Use: "change-password", | ||
Short: "Change your password. Do not use if needing to reset password", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cognitoClient := cognito.New() | ||
|
||
cognitoClient.ChangePassword() | ||
}, | ||
} |
This file contains 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,16 @@ | ||
package firstsignin | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"gtech.dev/spark/cognito" | ||
) | ||
|
||
var FirstSignInCmd = &cobra.Command{ | ||
Use: "first-sign-in", | ||
Short: "Performs a first sign in", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cognitoClient := cognito.New() | ||
|
||
cognitoClient.PerformFirstSignIn() | ||
}, | ||
} |
This file contains 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,16 @@ | ||
package registertotp | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"gtech.dev/spark/cognito" | ||
) | ||
|
||
var RegisterTotpCmd = &cobra.Command{ | ||
Use: "register-totp", | ||
Short: "Register TOTP device", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cognitoClient := cognito.New() | ||
|
||
cognitoClient.RegisterMfaDevice() | ||
}, | ||
} |
This file contains 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,16 @@ | ||
package resetpassword | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"gtech.dev/spark/cognito" | ||
) | ||
|
||
var ResetPasswordCmd = &cobra.Command{ | ||
Use: "reset-password", | ||
Short: "Reset your password", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cognitoClient := cognito.New() | ||
|
||
cognitoClient.ResetPassword() | ||
}, | ||
} |
This file contains 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,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"gtech.dev/spark/cmd/auth" | ||
changepassword "gtech.dev/spark/cmd/change-password" | ||
firstsignin "gtech.dev/spark/cmd/first-sign-in" | ||
registertotp "gtech.dev/spark/cmd/register-totp" | ||
resetpassword "gtech.dev/spark/cmd/reset-password" | ||
) | ||
|
||
var cmdVersion = "1.0.0" | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "spark", | ||
Short: "Utilities for interacting with Cognito", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
version, err := cmd.Flags().GetBool("version") | ||
if err != nil { | ||
return | ||
} | ||
|
||
if version { | ||
fmt.Println(cmdVersion) | ||
} else { | ||
cmd.Help() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.Flags().Bool("version", false, "Current version of Spark") | ||
RootCmd.AddCommand(auth.AuthCmd) | ||
RootCmd.AddCommand(changepassword.ChangePasswordCmd) | ||
RootCmd.AddCommand(registertotp.RegisterTotpCmd) | ||
RootCmd.AddCommand(resetpassword.ResetPasswordCmd) | ||
RootCmd.AddCommand(firstsignin.FirstSignInCmd) | ||
} |
Oops, something went wrong.