welcome: call api to create account
diff --git a/charts/welcome/templates/install.yaml b/charts/welcome/templates/install.yaml
index 5b285f3..418fdbb 100644
--- a/charts/welcome/templates/install.yaml
+++ b/charts/welcome/templates/install.yaml
@@ -109,6 +109,7 @@
- --repo-addr={{ .Values.repoAddr }}
- --ssh-key=/pcloud/ssh-key/private
- --port=8080
+ - --create-account-addr={{ .Values.createAccountAddr }}
volumeMounts:
- name: ssh-key
readOnly: true
diff --git a/charts/welcome/values.yaml b/charts/welcome/values.yaml
index 5b71b61..0e7a7ae 100644
--- a/charts/welcome/values.yaml
+++ b/charts/welcome/values.yaml
@@ -4,6 +4,7 @@
pullPolicy: Always
repoAddr: 192.168.0.11
sshPrivateKey: key
+createAccountAddr: http://api.core-auth.svc.cluster.local/identities
ingress:
className: pcloud-ingress-public
domain: welcome.example.com
diff --git a/core/installer/cmd/welcome.go b/core/installer/cmd/welcome.go
index 68f3c36..41d27f7 100644
--- a/core/installer/cmd/welcome.go
+++ b/core/installer/cmd/welcome.go
@@ -12,9 +12,10 @@
)
var welcomeFlags struct {
- repo string
- sshKey string
- port int
+ repo string
+ sshKey string
+ port int
+ createAccountAddr string
}
func welcomeCmd() *cobra.Command {
@@ -40,6 +41,12 @@
8080,
"",
)
+ cmd.Flags().StringVar(
+ &welcomeFlags.createAccountAddr,
+ "create-account-addr",
+ "",
+ "",
+ )
return cmd
}
@@ -68,6 +75,7 @@
welcomeFlags.port,
installer.NewRepoIO(repo, signer),
nsCreator,
+ welcomeFlags.createAccountAddr,
)
s.Start()
return nil
diff --git a/core/installer/values-tmpl/welcome.yaml b/core/installer/values-tmpl/welcome.yaml
index 145a735..d871c90 100644
--- a/core/installer/values-tmpl/welcome.yaml
+++ b/core/installer/values-tmpl/welcome.yaml
@@ -15,6 +15,7 @@
values:
repoAddr: {{ .Values.RepoAddr }}
sshPrivateKey: {{ .Values.SSHPrivateKey | b64enc }}
+ createAccountAddr: http://api.{{ .Global.NamespacePrefix}}core-auth.svc.cluster.local/identities
ingress:
className: {{ .Global.PCloudEnvName }}-ingress-public
domain: welcome.{{ .Global.Domain }}
diff --git a/core/installer/welcome/welcome.go b/core/installer/welcome/welcome.go
index 0b93848..0f3fa98 100644
--- a/core/installer/welcome/welcome.go
+++ b/core/installer/welcome/welcome.go
@@ -1,9 +1,11 @@
package welcome
import (
+ "bytes"
"embed"
"encoding/json"
"fmt"
+ "io"
"log"
"net/http"
"net/url"
@@ -20,16 +22,23 @@
var staticAssets embed.FS
type Server struct {
- port int
- repo installer.RepoIO
- nsCreator installer.NamespaceCreator
+ port int
+ repo installer.RepoIO
+ nsCreator installer.NamespaceCreator
+ createAccountAddr string
}
-func NewServer(port int, repo installer.RepoIO, nsCreator installer.NamespaceCreator) *Server {
+func NewServer(
+ port int,
+ repo installer.RepoIO,
+ nsCreator installer.NamespaceCreator,
+ createAccountAddr string,
+) *Server {
return &Server{
port,
repo,
nsCreator,
+ createAccountAddr,
}
}
@@ -51,10 +60,15 @@
type createAccountReq struct {
Username string `json:"username,omitempty"`
- Password string `json:"password,omitempty"` // TODO(giolekva): actually use this
+ Password string `json:"password,omitempty"`
SecretToken string `json:"secretToken,omitempty"`
}
+type apiCreateAccountReq struct {
+ Username string `json:"username,omitempty"`
+ Password string `json:"password,omitempty"`
+}
+
func getFormValue(v url.Values, name string) (string, error) {
items, ok := v[name]
if !ok || len(items) != 1 {
@@ -94,7 +108,26 @@
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- // TODO(giolekva): accounts-ui create user req
+ {
+ var buf bytes.Buffer
+ cr := apiCreateAccountReq{req.Username, req.Password}
+ if err := json.NewEncoder(&buf).Encode(cr); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ resp, err := http.Post(s.createAccountAddr, "application/json", &buf)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ // TODO(gio): better handle status code and error message
+ if resp.StatusCode != http.StatusOK {
+ var e bytes.Buffer
+ io.Copy(&e, resp.Body)
+ http.Error(w, e.String(), http.StatusInternalServerError)
+ return
+ }
+ }
{
config, err := s.repo.ReadConfig()
if err != nil {