Skip to content

Commit

Permalink
Add files for local dev POC
Browse files Browse the repository at this point in the history
  • Loading branch information
duplodavid committed May 15, 2024
1 parent c9de9bd commit f33fc17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"args": [
"duplo",
"--host",
"https://test20.duplocloud.net",
"https://qa-govcloud.duplocloud.net",
"--interactive"
],
},
Expand All @@ -86,7 +86,7 @@
"--plan",
"nonprod",
"--host",
"https://test20.duplocloud.net/",
"https://localhost:4200/",
"--interactive"
],
},
Expand All @@ -99,9 +99,9 @@
"args": [
"k8s",
"--tenant",
"nonprod",
"dev01",
"--host",
"https://test20.duplocloud.net/",
"http://localhost:4200/",
"--interactive"
],
},
Expand All @@ -114,9 +114,9 @@
"args": [
"k8s",
"--tenant",
"e5f31c01-64b0-4f42-a29d-78d437c9c132",
"1e2a96b9-c745-4c14-a037-6e25c3f42813",
"--host",
"https://test20.duplocloud.net/",
"http://localhost:4200/",
"--interactive"
],
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/duplo-jit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func main() {
// Refuse to call APIs over anything but https://
// Trim a trailing slash.
if host == nil || !strings.HasPrefix(*host, "https://") {

Check failure on line 80 in cmd/duplo-jit/main.go

View workflow job for this annotation

GitHub Actions / lint

SA4017: HasPrefix doesn't have side effects and its return value is ignored (staticcheck)
log.Fatalf("%s: %s", os.Args[0], "--host must be present and start with https://")
//log.Fatalf("%s: %s", os.Args[0], "--host must be present and start with https://")
}
*host = strings.TrimSuffix(*host, "/")

Expand All @@ -98,7 +98,7 @@ func main() {
if *admin {

// Build the cache key
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "admin"}, ",")
cacheKey = strings.Join([]string{strings.TrimPrefix(strings.TrimPrefix(*host, "http://"), "https://"), "admin"}, ",")

// Try to find credentials from the cache.
creds = internal.CacheGetAwsConfigOutput(cacheKey)
Expand All @@ -114,7 +114,7 @@ func main() {
} else if *duploOps {

// Build the cache key
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "duplo-ops"}, ",")
cacheKey = strings.Join([]string{strings.TrimPrefix(strings.TrimPrefix(*host, "http://"), "https://"), "duplo-ops"}, ",")

// Try to find credentials from the cache.
creds = internal.CacheGetAwsConfigOutput(cacheKey)
Expand All @@ -140,7 +140,7 @@ func main() {
*tenantID, tenantName = GetTenantIdAndName(*tenantID, client)

// Build the cache key.
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "tenant", tenantName}, ",")
cacheKey = strings.Join([]string{strings.TrimPrefix(strings.TrimPrefix(*host, "http://"), "https://"), "tenant", tenantName}, ",")

// Try to find credentials from the cache.
creds = internal.CacheGetAwsConfigOutput(cacheKey)
Expand All @@ -158,7 +158,7 @@ func main() {
internal.OutputAwsCreds(creds, cacheKey)

case "duplo":
_, creds := internal.MustDuploClient(*host, *token, *interactive, true)
_, creds := internal.MustDuploClient("http://localhost", *token, *interactive, true)
internal.OutputDuploCreds(creds)

case "k8s":
Expand All @@ -167,14 +167,14 @@ func main() {
if planID != nil && *planID != "" {

// Build the cache key
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "plan", *planID}, ",")
cacheKey = strings.Join([]string{strings.TrimPrefix(strings.TrimPrefix(*host, "http://"), "https://"), "plan", *planID}, ",")

// Try to find credentials from the cache.
creds = internal.CacheGetK8sConfigOutput(cacheKey, "")

// Otherwise, get the credentials from Duplo.
if creds == nil {
client, _ := internal.MustDuploClient(*host, *token, *interactive, true)
client, _ := internal.MustDuploClient("http://localhost", *token, *interactive, true)
result, err := client.AdminGetK8sJitAccess(*planID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertK8sCreds(result)
Expand All @@ -189,11 +189,11 @@ func main() {

// Identify the tenant name to use for the cache key.
var tenantName string
client, _ := internal.MustDuploClient(*host, *token, *interactive, false)
client, _ := internal.MustDuploClient("http://localhost", *token, *interactive, false)
*tenantID, tenantName = GetTenantIdAndName(*tenantID, client)

// Build the cache key.
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "tenant", tenantName}, ",")
cacheKey = strings.Join([]string{strings.TrimPrefix(strings.TrimPrefix(*host, "http://"), "https://"), "tenant", tenantName}, ",")

// Try to find credentials from the cache.
creds = internal.CacheGetK8sConfigOutput(cacheKey, tenantName)
Expand Down
8 changes: 4 additions & 4 deletions internal/duplo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func duploClientAndOtpFlag(host, token, otp string, admin bool) (*duplocloud.Cli
// MustDuploClient retrieves a duplo client (and credentials) or panics.
func MustDuploClient(host, token string, interactive, admin bool) (client *duplocloud.Client, creds *DuploCredsOutput) {
needsOtp := false
cacheKey := strings.TrimPrefix(host, "https://")
cacheKey := strings.TrimPrefix(strings.TrimPrefix(host, "http://"), "https://")

// Try non-interactive auth first.
if token != "" {
Expand All @@ -64,7 +64,7 @@ func MustDuploClient(host, token string, interactive, admin bool) (client *duplo

// The client is not usable, so we have an error.
} else {
log.Fatalf("%s: authentication failure: failed to collect system features", os.Args[0])
log.Fatalf("%s: authentication failure: failed to collect system features(1)", os.Args[0])
}
}

Expand All @@ -91,15 +91,15 @@ func MustDuploClient(host, token string, interactive, admin bool) (client *duplo
}

// Get the token, or fail.
tokenResult := MustTokenInteractive(host, admin, "duplo-jit")
tokenResult := MustTokenInteractive("http://localhost:4200", admin, "duplo-jit")
if tokenResult.Token == "" {
log.Fatalf("%s: authentication failure: failed to get token interactively", os.Args[0])
}

// Get the client, or fail.
client, _ = duploClientAndOtpFlag(host, tokenResult.Token, tokenResult.OTP, admin)
if client == nil {
log.Fatalf("%s: authentication failure: failed to collect system features", os.Args[0])
log.Fatalf("%s: authentication failure: failed to collect system features(2)", os.Args[0])
}

// Build credentials.
Expand Down

0 comments on commit f33fc17

Please sign in to comment.