Skip to content

Commit

Permalink
Merge pull request #22 from Jyny/dev
Browse files Browse the repository at this point in the history
use outliner's own ssh key
  • Loading branch information
Jyny authored Sep 5, 2019
2 parents 7e653d6 + c5169e4 commit eea3d80
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WINDOWS=$(EXECUTABLE)_windows.exe
LINUX=$(EXECUTABLE)_linux
DARWIN=$(EXECUTABLE)_darwin
VERSION=$(shell cat VERSION)
XPKG="github.com/jyny/outliner/pkg/cmd"
XPKG="github.com/jyny/outliner/command"

all : build shell_completion
cp ./build/outliner_$(shell go env GOOS) ./outliner
Expand All @@ -19,7 +19,7 @@ build : mod embedded fmt
env GOOS=windows GOARCH=amd64 go build -o ./build/$(WINDOWS) -ldflags="-X $(XPKG).version=$(VERSION)" .

embedded :
@pushd pkg/agent > /dev/null && \
@pushd pkg/deployer/ssh > /dev/null && \
go run gen/gen.go \
&& popd > /dev/null

Expand Down
33 changes: 9 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ Flags:
Use "outliner [command] --help" for more information about a command.
```

---

## Contents
- [Install or Download](#install-or-download)
- [Mac OSX](#mac-osx)
- [Download binary from latest release](#download-binary-from-latest-release)
- [Download release from GitHub](#download-release-from-github)
- [Setup](#setup)
- [1. Get `API_TOKEN`](#1-get-api_token)
- [2. Make a `.env` config file](#2-make-a-env-config-file)
- [3. Generate ssh key](#3-generate-ssh-key)
- [4. Ready to go](#4-ready-to-go)
- [3. Ready to go](#3-ready-to-go)
- [Configurations](#configurations)
- [config by `.env` file](#config-by-env-file)
- [config by Environment Variables](#config-by-environment-variables)
Expand All @@ -43,8 +43,6 @@ Use "outliner [command] --help" for more information about a command.
- [Support Cloud(IaaS)](#support-cloudiaas)
- [Development and Build](#development-and-build)

---

## Install or Download
### Mac OSX
```
Expand All @@ -61,8 +59,8 @@ $ brew install jyny/tap/outliner
# apt isntall outliner
```

### Download binary from latest release
[https://github.com/Jyny/outliner/releases/latest](https://github.com/Jyny/outliner/releases/latest)
### Download release from GitHub
Visit the [latest releases page](https://github.com/Jyny/outliner/releases/latest)

## Setup
#### 1. Get `API_TOKEN`
Expand All @@ -77,26 +75,15 @@ TOKEN_NAME_2 = TOKEN_VALUE_2
...
```

#### 3. Generate SSH key
outliner will generate ssh key, if Not found `id_rsa` and `id_rsa.pub` in `$HOME/.ssh/`.
run any command in outliner will do this after asking.
```
$ outliner help
Continue to Generate New ssh key? (y/n) [y]:
```
To generate key by yourself, see [Generating a new SSH key and adding it to the ssh-agent](https://help.github.com/en/enterprise/2.16/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)

#### 4. Ready to go
##### * install by package manager like `homeberw` `pacman` `apt` etc.
#### 3. Ready to go
* install by package manager like `homeberw` `pacman` `apt` etc.
1. `$ outliner`

##### * install by download
* install by download
1. open terminal, go directory whrere you download outliner
2. maybe should add execute permission to binary (linux or mac)
3. `$ ./outliner_{OS}`

---

## Configurations
### config by `.env` file
* `~/.outliner/.env`
Expand All @@ -120,6 +107,7 @@ $ {TOKEN_NAME_1}={TOKEN_VALUE_1} outliner [command]
| Digitalocean | |
| Vultr | |


find full list in `pkg/cloud/{ProviderNmae}/activator.go` as below
```
var tokenNames = []string{
Expand All @@ -131,7 +119,6 @@ var tokenNames = []string{

### Support configuration source
outliner Support the following configuration source (list by Precedence order)

1. with flag `-F, --file {FILE_PATH}`
2. Environment variables
3. `.env` file at `~/.outliner/`
Expand All @@ -144,8 +131,6 @@ outliner Support the following configuration source (list by Precedence order)
* Vultr (WIP)
...

---

## Development and Build
#### 1. install package and build binary
```
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/create.go → command/create.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/spf13/cobra"
Expand All @@ -18,7 +18,7 @@ func init() {
viper.BindPFlag("spec", createCmd.Flags().Lookup("spec"))
viper.BindPFlag("region", createCmd.Flags().Lookup("region"))
viper.BindPFlag("provider", createCmd.Flags().Lookup("provider"))
rootCmd.AddCommand(createCmd)
RootCmd.AddCommand(createCmd)
}

var createCmd = &cobra.Command{
Expand Down Expand Up @@ -49,7 +49,7 @@ var createCmd = &cobra.Command{
}
util.PrintCreateInstanceDone()
util.PrintInstancesTable([]ol.Instance{inst})
viper.Set("ip", inst.IPv4)
viper.Set("deploy_ip", inst.IPv4)
},
PostRun: func(cmd *cobra.Command, args []string) {
if util.ContinueInteractive() {
Expand Down
16 changes: 7 additions & 9 deletions pkg/cmd/deploy.go → command/deploy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/spf13/cobra"
Expand All @@ -10,8 +10,8 @@ import (
func init() {
deployCmd.Flags().StringP("ip", "i", "", "IP address of Server (required)")
deployCmd.MarkFlagRequired("ip")
viper.BindPFlag("ip", deployCmd.Flags().Lookup("ip"))
rootCmd.AddCommand(deployCmd)
viper.BindPFlag("deploy_ip", deployCmd.Flags().Lookup("ip"))
RootCmd.AddCommand(deployCmd)
}

var deployCmd = &cobra.Command{
Expand All @@ -22,7 +22,7 @@ var deployCmd = &cobra.Command{
util.PrintDeployInstanceStart()
},
Run: func(cmd *cobra.Command, args []string) {
ip := viper.GetString("ip")
ip := viper.GetString("deploy_ip")
err := deployer.DeployService(ip)
if err != nil {
panic(err)
Expand All @@ -33,13 +33,11 @@ var deployCmd = &cobra.Command{
panic(err)
}
util.PrintDeployInstanceDone()
inst, err := cloud.GetInstanceIDbyIP(ip)
if err != nil {
panic(err)
}
viper.Set("id", inst.ID)
viper.Set("inspect_ip", ip)

},
PostRun: func(cmd *cobra.Command, args []string) {
inspectCmd.PreRun(inspectCmd, []string{})
inspectCmd.Run(inspectCmd, []string{})
},
}
4 changes: 2 additions & 2 deletions pkg/cmd/destroy.go → command/destroy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/spf13/cobra"
Expand All @@ -12,7 +12,7 @@ func init() {
destroyCmd.Flags().StringP("id", "i", "", "ID of Server (required)")
destroyCmd.MarkFlagRequired("id")
viper.BindPFlag("destroy_id", destroyCmd.Flags().Lookup("id"))
rootCmd.AddCommand(destroyCmd)
RootCmd.AddCommand(destroyCmd)
}

var destroyCmd = &cobra.Command{
Expand Down
38 changes: 38 additions & 0 deletions command/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package command

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

ol "github.com/jyny/outliner/pkg/outliner"
"github.com/jyny/outliner/pkg/util"
)

func init() {
inspectCmd.Flags().StringP("ip", "i", "", "IP address of Server (required)")
inspectCmd.MarkFlagRequired("ip")
viper.BindPFlag("inspect_ip", inspectCmd.Flags().Lookup("ip"))
RootCmd.AddCommand(inspectCmd)
}

var inspectCmd = &cobra.Command{
Use: "inspect",
Short: "inspect Server",
Long: `inspect Server`,
PreRun: func(cmd *cobra.Command, args []string) {
ip := viper.GetString("inspect_ip")
inst, err := cloud.InspectInstanceByIP(ip)
if err == nil {
util.PrintInstancesTable([]ol.Instance{inst})
}
},
Run: func(cmd *cobra.Command, args []string) {
ip := viper.GetString("inspect_ip")
apicert, err := deployer.GetServiceCert(ip)
if err != nil {
panic(err)
}
util.PrintAPICertTable(apicert)
util.PrintAPICertJSON(apicert)
},
}
4 changes: 2 additions & 2 deletions pkg/cmd/list.go → command/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/spf13/cobra"
Expand All @@ -12,7 +12,7 @@ func init() {
listCmd.AddCommand(specCmd)
listCmd.AddCommand(regineCmd)
listCmd.AddCommand(providerCmd)
rootCmd.AddCommand(listCmd)
RootCmd.AddCommand(listCmd)
}

var listCmd = &cobra.Command{
Expand Down
25 changes: 15 additions & 10 deletions pkg/cmd/root.go → command/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"os/user"
Expand All @@ -7,13 +7,16 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/jyny/outliner/pkg/agent"
ol "github.com/jyny/outliner/pkg/outliner"
"github.com/jyny/outliner/pkg/util"

//"github.com/jyny/outliner/pkg/cloud/digitalocean"
// deployer agnet
"github.com/jyny/outliner/pkg/deployer/ssh"

// cloud provider
"github.com/jyny/outliner/pkg/cloud/linode"
//"github.com/jyny/outliner/pkg/cloud/vultr"
//"github.com/jyny/outliner/pkg/cloud/digitalocean"
)

// Persistent Flags
Expand All @@ -24,23 +27,23 @@ var version = ""
var cloud = ol.NewCloud()
var deployer = ol.NewDeployer()

var rootCmd = &cobra.Command{
// RootCmd commands
var RootCmd = &cobra.Command{
Use: "outliner",
Short: "Auto setup & deploy tool for outline VPN server",
Long: "Auto setup & deploy tool for outline VPN server",
}
var RootCmd = rootCmd

// Execute entry of commandline
func Execute() {
if err := rootCmd.Execute(); err != nil {
if err := RootCmd.Execute(); err != nil {
panic(err)
}
}

func init() {
cobra.OnInitialize(initOutliner)
rootCmd.PersistentFlags().StringVarP(&cfgFile, "file", "F", "", "config file (default is $HOME/.outliner/.env)")
RootCmd.PersistentFlags().StringVarP(&cfgFile, "file", "F", "", "config file (default is $HOME/.outliner/.env)")

u, err := user.Current()
if err != nil {
Expand Down Expand Up @@ -69,15 +72,17 @@ func init() {
}

func initOutliner() {
// add new agent to deployer
deployer.Init(agent.New())
// register deployer agent
deployer.RegisterAgent(
ssh.NewAgent(),
)

// Activate & register cloud providers
err := cloud.RegisterProvider(
util.Validater,
//digitalocean.Activator{},
linode.Activator{},
//vultr.Activator{},
//digitalocean.Activator{},
)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/version.go → command/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package command

import (
"github.com/spf13/cobra"
Expand All @@ -7,7 +7,7 @@ import (
)

func init() {
rootCmd.AddCommand(versionCmd)
RootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions completion/gen.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import (
"github.com/jyny/outliner/pkg/cmd"
"github.com/jyny/outliner/command"
)

func main() {
err := cmd.RootCmd.GenBashCompletionFile("build/outliner_bash_completion")
err := command.RootCmd.GenBashCompletionFile("build/outliner_bash_completion")
if err != nil {
panic(err)
}
err = cmd.RootCmd.GenZshCompletionFile("build/outliner_zsh_completion")
err = command.RootCmd.GenZshCompletionFile("build/outliner_zsh_completion")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/jyny/outliner/pkg/cmd"
"github.com/jyny/outliner/command"
"log"
)

Expand All @@ -12,5 +12,5 @@ func main() {
}
}()

cmd.Execute()
command.Execute()
}
Loading

0 comments on commit eea3d80

Please sign in to comment.