Skip to content

Commit

Permalink
Merge pull request #34 from moficodes/static
Browse files Browse the repository at this point in the history
add awx build for infra
  • Loading branch information
moficodes authored Oct 10, 2020
2 parents e1f484f + e9ab842 commit fd67501
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 70 deletions.
297 changes: 230 additions & 67 deletions client/src/pages/create/CreateForm.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func main() {
Format: "method=${method}, uri=${uri}, status=${status}, time=${latency_human}\n",
}))

api.POST("/auth/check", server.CheckApiKeyHandler)

api.GET("/clusters/versions", server.VersionEndpointHandler)
api.GET("/clusters/locations", server.LocationEndpointHandler)
api.GET("/clusters/:geo/locations", server.LocationGeoEndpointHandler)
Expand Down Expand Up @@ -102,6 +104,7 @@ func main() {
api.PUT("/notification/email/remove", server.RemoveAdminEmails)
api.DELETE("/notification/email", server.DeleteAdminEmails)

// api.POST("/awx/cluster", server.CreateClusterWithAWX)
api.GET("/awx/workflowjobtemplate", server.GetAWXWorkflowJobTemplates)
api.GET("/awx/jobtemplate", server.GetAWXJobTemplates)
api.POST("/awx/workflowjobtemplate/launch", server.LaunchAWXWorkflowJobTemplate)
Expand Down
2 changes: 1 addition & 1 deletion config/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
run: admin
spec:
containers:
- image: moficodes/ibmcloud-kubernetes-admin:v0.2.19
- image: moficodes/ibmcloud-kubernetes-admin:v0.2.20
imagePullPolicy: Always
name: kubeadmin
env:
Expand Down
31 changes: 31 additions & 0 deletions internals/server/account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package server

import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"

Expand Down Expand Up @@ -36,3 +39,31 @@ func AccountListHandler(c echo.Context) error {
}
return c.JSON(http.StatusOK, accounts)
}

func CheckApiKeyHandler(c echo.Context) error {
session, err := getCloudSessions(c)
if err != nil {
return err
}

var body map[string]interface{}
decoder := json.NewDecoder(c.Request().Body)
err = decoder.Decode(&body)
if err != nil {
return err
}

_apikey, ok := body["apikey"]
if !ok {
return errors.New("no apikey attached to body")
}

apikey := fmt.Sprintf("%v", _apikey)

apikeyDetails, err := session.CheckToken(apikey)
if err != nil {
return err
}

return c.JSON(http.StatusOK, apikeyDetails)
}
5 changes: 4 additions & 1 deletion internals/server/awx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func GetAWXWorkflowJobTemplates(c echo.Context) error {
query := c.QueryParam("labels")
fmt.Println("QUERY: ", query)

var result []awx.ResultsWorkflowTemplate
result := make([]awx.ResultsWorkflowTemplate, 0)
if query == "" {
result = templates.Results
} else {
Expand Down Expand Up @@ -55,11 +55,14 @@ func LaunchAWXWorkflowJobTemplate(c echo.Context) error {
decoder := json.NewDecoder(c.Request().Body)
err := decoder.Decode(&body)
if err != nil {
fmt.Println("1:", err)
return err
}

res, err := awx.LaunchWorkflowJobTemplate(token, body)
if err != nil {
fmt.Println("2:", err)

return err
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/awx/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package awx

import "encoding/json"
import (
"encoding/json"
"fmt"
)

const (
protocol = "https://"
Expand Down Expand Up @@ -38,11 +41,14 @@ func launchWorkflowJobTemplate(token string, body WorkflowJobTeplatesLaunchBody)

b, err := json.Marshal(body)
if err != nil {
fmt.Println(":3", err)
return nil, err
}

err = postBody(endpont, header, nil, b, &res)
if err != nil {
fmt.Println(":4", err)

return nil, err
}
return res, nil
Expand Down
19 changes: 19 additions & 0 deletions pkg/ibmcloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
tagEndpoint = protocol + subdomainTags + api + "/v3/tags"
billingEndpoint = protocol + subdomainBilling + api + "/v4/accounts"
resourceEndoint = protocol + subdomainResourceController + api + "/v1/resource_groups"
apikeyEndpoint = protocol + subdomainIAM + api + "/v1/apikeys"
)

const (
Expand Down Expand Up @@ -120,6 +121,24 @@ func getToken(endpoint string, otp string) (*Token, error) {
return &result, nil
}

func checkToken(token, apikey string) (*ApiKeyDetails, error) {
header := map[string]string{
"Authorization": "Bearer " + token,
"IAM-Apikey": apikey,
}

endpoint := apikeyEndpoint + "/details"

var res ApiKeyDetails
err := fetch(endpoint, header, nil, &res)

if err != nil {
return nil, err
}

return &res, nil
}

func getTokenFromIAM(endpoint string, apikey string) (*Token, error) {
header := map[string]string{
"Authorization": basicAuth,
Expand Down
8 changes: 8 additions & 0 deletions pkg/ibmcloud/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ func bindAccountToToken(refreshToken, accountID string) (*Session, error) {
return &Session{Token: token}, nil
}

func (s *Session) CheckToken(apikey string) (*ApiKeyDetails, error) {
apiKeyDetails, err := checkToken(s.Token.AccessToken, apikey)
if err != nil {
return nil, err
}
return apiKeyDetails, nil
}

// BindAccountToToken upgrades session with account
func (s *Session) BindAccountToToken(accountID string) (*Session, error) {
session, err := bindAccountToToken(s.Token.RefreshToken, accountID)
Expand Down
14 changes: 14 additions & 0 deletions pkg/ibmcloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,17 @@ type ClusterRequest struct {
SkipPermPrecheck bool `json:"skipPermPrecheck"`
WorkerNum int `json:"workerNum"`
}

type ApiKeyDetails struct {
ID string `json:"id"`
EntityTag string `json:"entity_tag"`
Crn string `json:"crn"`
Locked bool `json:"locked"`
CreatedAt string `json:"created_at"`
CreatedBy string `json:"created_by"`
ModifiedAt string `json:"modified_at"`
Name string `json:"name"`
Description string `json:"description"`
IamID string `json:"iam_id"`
AccountID string `json:"account_id"`
}

0 comments on commit fd67501

Please sign in to comment.