-
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.
Merge pull request #1 from gkarthiks/develop
chore: adding functionalities
- Loading branch information
Showing
9 changed files
with
793 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 @@ | ||
.idea/ |
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,6 @@ | ||
FROM golang:alpine3.11 | ||
RUN mkdir -p /usr/local/src | ||
COPY . /usr/local/src | ||
WORKDIR /usr/local/src/ | ||
RUN go build -o vault-initializer cmd/main.go | ||
CMD ./vault-initializer |
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,53 @@ | ||
package main | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"os" | ||
"vault-initializer/utility" | ||
) | ||
|
||
var ( | ||
avail bool | ||
secSharesStr string | ||
secThresholdStr string | ||
err error | ||
) | ||
|
||
func init() { | ||
appMode, avail := os.LookupEnv("APP_MODE") | ||
if !avail { | ||
appMode = "debug" | ||
log.SetFormatter(&log.JSONFormatter{ | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
}) | ||
log.SetLevel(log.DebugLevel) | ||
} else if appMode == "production" { | ||
log.SetFormatter(&log.JSONFormatter{ | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
}) | ||
log.SetLevel(log.InfoLevel) | ||
} else { | ||
log.SetFormatter(&log.JSONFormatter{ | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
}) | ||
log.SetLevel(log.DebugLevel) | ||
} | ||
|
||
vaultInitConfigMap, avail := os.LookupEnv("INIT_CONFIG_MAP") | ||
if !avail { | ||
log.Panic("The initialization config map is not specified") | ||
} else { | ||
log.Debugf("The initialization config map is specified as %s", vaultInitConfigMap) | ||
} | ||
|
||
utility.ParseInitConfigData(vaultInitConfigMap) | ||
|
||
} | ||
|
||
func main() { | ||
doneCh := make(chan bool) | ||
go func() { | ||
utility.StartRoutine() | ||
}() | ||
<-doneCh | ||
} |
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,48 @@ | ||
package common | ||
|
||
import "reflect" | ||
|
||
var ( | ||
//VaultURL string | ||
SecShares int | ||
SecThreshold int | ||
WaitTimeSeconds int | ||
ReadinessProbeInSeconds int | ||
) | ||
|
||
const ( | ||
WaitTime = 3 | ||
ReadinessProbe = 5 | ||
DefaultSecretShares = 5 | ||
DefaultSecretThreshold = 3 | ||
HttpMethodGET = "GET" | ||
HttpMethodPOST = "POST" | ||
HttpMethodPUT = "PUT" | ||
VaultKeysSecretName = "vault-init-keys" | ||
) | ||
|
||
type VaultInitResp struct { | ||
Keys []string `json:"keys"` | ||
KeysBase64 []string `json:"keys_base64"` | ||
RootToken string `json:"root_token"` | ||
} | ||
|
||
type VaultUnsealResp struct { | ||
Type string `json:"type"` | ||
Initialized bool `json:"initialized"` | ||
Sealed bool `json:"sealed"` | ||
T int `json:"t"` | ||
N int `json:"n"` | ||
Progress int `json:"progress"` | ||
Nonce string `json:"nonce"` | ||
Version string `json:"version"` | ||
Migration bool `json:"migration"` | ||
ClusterName string `json:"cluster_name"` | ||
ClusterID string `json:"cluster_id"` | ||
RecoverySeal bool `json:"recovery_seal"` | ||
StorageType string `json:"storage_type"` | ||
} | ||
|
||
func (parsedKeys VaultInitResp) IsEmpty() bool { | ||
return reflect.DeepEqual(parsedKeys, VaultInitResp{}) | ||
} |
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,10 @@ | ||
module vault-initializer | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/gkarthiks/k8s-discovery v0.0.0-20190821062943-753b4c007093 | ||
github.com/sirupsen/logrus v1.4.2 | ||
k8s.io/api v0.0.0-20190819141258-3544db3b9e44 | ||
k8s.io/apimachinery v0.17.3 | ||
) |
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,42 @@ | ||
package utility | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
log "github.com/sirupsen/logrus" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
func parseJSONRespo(respJSON []byte, structType interface{}) { | ||
if respJSON != nil { | ||
json.Unmarshal(respJSON, &structType) | ||
} | ||
return | ||
} | ||
|
||
// FireRequest fires the request based on the parameters to the provided URL | ||
func FireRequest(payloadJSON string, url string, reqHeaders map[string]string, method string) ([]byte, error) { | ||
var req *http.Request | ||
|
||
if len(payloadJSON) > 0 { | ||
req, err = http.NewRequest(method, url, bytes.NewBuffer([]byte(payloadJSON))) | ||
log.Debugf("JSON String getting passed as payload: %s to the URL %s", payloadJSON, url) | ||
req.Header.Set("Content-Type", "application/json") | ||
} else { | ||
log.Debug("No payload to pass") | ||
req, err = http.NewRequest(method, url, nil) | ||
} | ||
for key, val := range reqHeaders { | ||
req.Header.Set(key, val) | ||
} | ||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
body, _ := ioutil.ReadAll(resp.Body) | ||
//log.Debugf("Response body getting returned: %s", string(body)) | ||
return body, nil | ||
} |
Oops, something went wrong.