Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example Go App for Conjur Demos of authn-k8s
package main
import (
"database/sql"
"fmt"
"log"
"os"
"github.com/cyberark/conjur-api-go/conjurapi"
_ "github.com/go-sql-driver/mysql"
)
type Tag struct {
name string `json:"name"`
breed string `json:"breed"`
}
func main() {
variableIdentifier := os.Getenv("CONJUR_PASS_OBJECT")
variableuserIdentifier := os.Getenv("CONJUR_USER_OBJECT")
config, err := conjurapi.LoadConfig()
if err != nil {
panic(err)
}
conjur, err := conjurapi.NewClientFromTokenFile(config, os.Getenv("CONJUR_AUTHN_TOKEN_FILE"))
if err != nil {
panic(err)
}
secretValue, err := conjur.RetrieveSecret(variableIdentifier)
if err != nil {
panic(err)
}
secretValueUser, err := conjur.RetrieveSecret(variableuserIdentifier)
if err != nil {
panic(err)
}
mySQLInfo := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", secretValueUser, secretValue, os.Getenv("MYSQL_HOST"), os.Getenv("MYSQL_PORT"), os.Getenv("MYSQL_DBNAME"))
db, err := sql.Open("mysql", mySQLInfo)
if err != nil {
panic(err)
}
defer db.Close()
results, err := db.Query("select name, breed from pet")
if err != nil {
panic(err)
}
for results.Next() {
var tag Tag
err = results.Scan(&tag.name, &tag.breed)
if err != nil {
panic(err)
}
log.Printf(tag.name)
}
log.Printf("%s:%s", "The Secret Used: ", secretValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.