Skip to content

Commit 396f839

Browse files
authored
Merge pull request #44 from indigo-dc/fix_oidc-agent3
Adapt to work with oidc agent>=3.0.0
2 parents 6538492 + 93a2944 commit 396f839

File tree

5 files changed

+46
-121
lines changed

5 files changed

+46
-121
lines changed

glide.lock

+7-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import:
33
- package: github.com/dghubble/sling
44
version: 1.1.0
55
- package: gopkg.in/alecthomas/kingpin.v2
6-
- package: github.com/zpatrick/go-config
6+
- package: github.com/zpatrick/go-config
7+
- package: github.com/zachmann/liboidcagent-go/liboidcagent

orchent.go

+31-63
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import (
66
"crypto/x509"
77
"encoding/json"
88
"fmt"
9-
"github.com/dghubble/sling"
10-
"github.com/zpatrick/go-config"
11-
"gopkg.in/alecthomas/kingpin.v2"
12-
"net"
139
"net/http"
1410
"net/url"
1511
"os"
1612
"os/user"
1713
"strconv"
1814
"strings"
15+
16+
"github.com/dghubble/sling"
17+
"github.com/zachmann/liboidcagent-go/liboidcagent"
18+
"github.com/zpatrick/go-config"
19+
"gopkg.in/alecthomas/kingpin.v2"
1920
)
2021

21-
const OrchentVersion string = "1.2.2"
22+
const OrchentVersion string = "1.2.3"
2223

2324
var (
2425
app = kingpin.New("orchent", "The orchestrator client. \n \nPlease either store your access token in 'ORCHENT_TOKEN' or set the account to use with oidc-agent in the 'ORCHENT_AGENT_ACCOUNT' and the socket of the oidc-agent in the 'OIDC_SOCK' environment variable: \n export ORCHENT_TOKEN=<your access token> \n OR \n export OIDC_SOCK=<path to the oidc-agent socket> (usually this is already exported) \n export ORCHENT_AGENT_ACCOUNT=<account to use> \nIf you need to specify the file containing the trusted root CAs use the 'ORCHENT_CAFILE' environment variable: \n export ORCHENT_CAFILE=<path to file containing trusted CAs>\n \n").Version(OrchentVersion)
@@ -32,20 +33,20 @@ var (
3233
showDep = app.Command("depshow", "show a specific deployment")
3334
showDepUuid = showDep.Arg("uuid", "the uuid of the deployment to display").Required().String()
3435

35-
createDep = app.Command("depcreate", "create a new deployment")
36-
createDepCallback = createDep.Flag("callback", "the callback url").Default("").String()
37-
createDepMaxProvidersRetry = createDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8()
38-
createDepKeepLastAttempt = createDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false")
39-
createDepTemplate = createDep.Arg("template", "the tosca template file").Required().File()
40-
createDepParameter = createDep.Arg("parameter", "the parameter to set (json object)").Required().String()
41-
42-
updateDep = app.Command("depupdate", "update the given deployment")
43-
updateDepCallback = updateDep.Flag("callback", "the callback url").Default("").String()
44-
updateDepMaxProvidersRetry = updateDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8()
45-
updateDepKeepLastAttempt = updateDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false")
46-
updateDepUuid = updateDep.Arg("uuid", "the uuid of the deployment to update").Required().String()
47-
updateDepTemplate = updateDep.Arg("template", "the tosca template file").Required().File()
48-
updateDepParameter = updateDep.Arg("parameter", "the parameter to set (json object)").Required().String()
36+
createDep = app.Command("depcreate", "create a new deployment")
37+
createDepCallback = createDep.Flag("callback", "the callback url").Default("").String()
38+
createDepMaxProvidersRetry = createDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8()
39+
createDepKeepLastAttempt = createDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false")
40+
createDepTemplate = createDep.Arg("template", "the tosca template file").Required().File()
41+
createDepParameter = createDep.Arg("parameter", "the parameter to set (json object)").Required().String()
42+
43+
updateDep = app.Command("depupdate", "update the given deployment")
44+
updateDepCallback = updateDep.Flag("callback", "the callback url").Default("").String()
45+
updateDepMaxProvidersRetry = updateDep.Flag("maxProvidersRetry", "Maximum number of cloud providers to be used in case of failure (Default: UNBOUNDED).").Uint8()
46+
updateDepKeepLastAttempt = updateDep.Flag("keepLastAttempt", "In case of failure, keep the resources allocated in the last try (Default: true).").Default("true").Enum("true", "false")
47+
updateDepUuid = updateDep.Arg("uuid", "the uuid of the deployment to update").Required().String()
48+
updateDepTemplate = updateDep.Arg("template", "the tosca template file").Required().File()
49+
updateDepParameter = updateDep.Arg("parameter", "the parameter to set (json object)").Required().String()
4950

5051
depTemplate = app.Command("deptemplate", "show the template of the given deployment")
5152
templateDepUuid = depTemplate.Arg("uuid", "the uuid of the deployment to get the template").Required().String()
@@ -378,7 +379,7 @@ func receive_and_print_deploymentlist(complete *sling.Sling, before int, after i
378379
}
379380

380381
func deployment_create_update(templateFile *os.File, parameter string, callback string, maxProvidersRetry uint8, keepLastAttempt string, depUuid *string, base *sling.Sling) {
381-
382+
382383
var parameterMap map[string]interface{}
383384
paramErr := json.Unmarshal([]byte(parameter), &parameterMap)
384385
if paramErr != nil {
@@ -400,11 +401,11 @@ func deployment_create_update(templateFile *os.File, parameter string, callback
400401
}
401402
template := string(data[:count])
402403
body := &OrchentCreateRequest{
403-
Template: template,
404-
Parameters: parameterMap,
405-
Callback: callback,
404+
Template: template,
405+
Parameters: parameterMap,
406+
Callback: callback,
406407
MaxProvidersRetry: maxProvidersRetry,
407-
KeepLastAttempt: keepLastAttempt,
408+
KeepLastAttempt: keepLastAttempt,
408409
}
409410
deployment := new(OrchentDeployment)
410411
orchentError := new(OrchentError)
@@ -427,7 +428,7 @@ func deployment_create_update(templateFile *os.File, parameter string, callback
427428
if depUuid == nil {
428429
fmt.Printf("%s\n", deployment)
429430
} else {
430-
fmt.Println("update of deployment %s successfully triggered\n", depUuid)
431+
fmt.Printf("update of deployment %s successfully triggered\n", *depUuid)
431432
}
432433
}
433434
}
@@ -597,49 +598,16 @@ func get_account() (issuerSet bool, agentIssuer string) {
597598
}
598599

599600
func user_info(format string, a ...interface{}) {
600-
fmt.Printf(format, a)
601+
fmt.Printf(format, a...)
601602
}
602603

603604
func try_agent_token(account string) (tokenSet bool, tokenValue string) {
604-
socketValue, socketSet := os.LookupEnv("OIDC_SOCK")
605-
tokenSet = false
606-
tokenValue = ""
607-
if !socketSet {
608-
return tokenSet, tokenValue
609-
}
610-
611-
c, err := net.Dial("unixpacket", socketValue)
605+
token, err := liboidcagent.GetAccessToken(account, 120, "", "wattson")
612606
if err != nil {
613-
user_info("could not connect to socket %s: %s\n", socketValue, err.Error())
614-
return tokenSet, tokenValue
607+
fmt.Println("*** ERROR: Could not get token from oidc-agent and $ORCHENT_TOKEN not set ***")
608+
return false, tokenValue
615609
}
616-
defer c.Close()
617-
618-
ipcReq := fmt.Sprintf(`{"request":"access_token","account":"%s","min_valid_period":120}`, account)
619-
_, err = c.Write([]byte(ipcReq))
620-
if err != nil {
621-
user_info("could not write to socket %s: %s\n", socketValue, err.Error())
622-
return tokenSet, tokenValue
623-
}
624-
var response = [4096]byte{}
625-
length, err := c.Read(response[0:4095])
626-
if err != nil {
627-
user_info("could not read from socket %s: %s\n", socketValue, err.Error())
628-
return tokenSet, tokenValue
629-
}
630-
631-
response[length] = 0
632-
oidcToken := make(map[string]interface{})
633-
jsonErr := json.Unmarshal(response[0:length], &oidcToken)
634-
if jsonErr != nil {
635-
user_info("error parsing the oidc response: %s\n", jsonErr)
636-
return tokenSet, tokenValue
637-
}
638-
tokenValue, tokenSet = oidcToken["access_token"].(string)
639-
if tokenSet {
640-
user_info("received token from oidc-agent\n")
641-
}
642-
return tokenSet, tokenValue
610+
return true, token
643611
}
644612

645613
func try_token(accountSet bool, account string) (tokenSet bool, token string) {

utils/build_docker.sh

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ echo "done"
4646
echo -n " go-config ... "
4747
go get github.com/zpatrick/go-config
4848
echo "done"
49+
echo -n " liboidcagent ... "
50+
go get github.com/zachmann/liboidcagent-go/liboidcagent
51+
echo "done"
4952
echo -n "building orchent ... "
5053
CGO_ENABLED=0 GOOS=linux go build -a -v -o $ORCHENT ${GOPATH}/orchent.go
5154
echo "done"

utils/compile.sh

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ echo "done"
3131
echo -n " go-config ... "
3232
go get github.com/zpatrick/go-config
3333
echo "done"
34+
echo -n " liboidcagent ... "
35+
go get github.com/zachmann/liboidcagent-go/liboidcagent
36+
echo "done"
3437
echo -n "building orchent ... "
3538
go build -o orchent ${GOPATH}/orchent.go
3639
echo "done"

0 commit comments

Comments
 (0)