Skip to content

Commit

Permalink
Merge pull request #25 from duplocloud/release/0.5.5
Browse files Browse the repository at this point in the history
Release v0.5.5
  • Loading branch information
joek-duplo authored Jan 3, 2024
2 parents 5dcc532 + c8d8e9d commit 2bfae75
Show file tree
Hide file tree
Showing 18 changed files with 477 additions and 551 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/dev-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.21
-
name: Run linting
uses: golangci/golangci-lint-action@v3
Expand All @@ -29,12 +29,12 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.21
-
name: Run formatting
run: gofmt -s -w duplocloud cmd/duplo-aws-credential-process
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dev-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.21
-
name: Run tests
run: make test
4 changes: 2 additions & 2 deletions .github/workflows/finish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: master # Always finish releases from the "merged to" master
fetch-depth: 0
Expand All @@ -39,7 +39,7 @@ jobs:
- finish-release
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.21
-
name: Run tests
run: make test
-
name: Build and draft the release
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --parallelism 2 --rm-dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/start-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: develop # Always release from develop
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ changelog:
announce:
slack:
enabled: true
channel: '#duplo-devs'
channel: '#engineering'
release:
draft: false
brews:
Expand Down
124 changes: 124 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "AWS Admin",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"aws",
"--admin",
"--host",
"https://test20.duplocloud.net",
"--interactive"
],
},
{
"name": "AWS Tenant Name",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"aws",
"--tenant",
"non-prod",
"--host",
"https://test20.duplocloud.net",
"--interactive"
],
},
{
"name": "AWS Tenant ID",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"aws",
"--tenant",
"e5f31c01-64b0-4f42-a29d-78d437c9c132",
"--host",
"https://test20.duplocloud.net",
"--interactive"
],
},
{
"name": "AWS Duplo Ops",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"aws",
"--duplo-ops",
"--host",
"https://test20.duplocloud.net",
"--interactive"
],
},
{
"name": "Duplo",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"duplo",
"--host",
"https://test20.duplocloud.net",
"--interactive"
],
},
{
"name": "K8s Plan",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"k8s",
"--plan",
"nonprod",
"--host",
"https://test20.duplocloud.net/",
"--interactive"
],
},
{
"name": "K8s Tenant Name",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"k8s",
"--tenant",
"nonprod",
"--host",
"https://test20.duplocloud.net/",
"--interactive"
],
},
{
"name": "K8s Tenant ID",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/duplo-jit/main.go",
"args": [
"k8s",
"--tenant",
"e5f31c01-64b0-4f42-a29d-78d437c9c132",
"--host",
"https://test20.duplocloud.net/",
"--interactive"
],
}
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.5.4
VERSION=0.5.5

default: all

Expand Down
4 changes: 2 additions & 2 deletions cmd/duplo-aws-credential-process/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {
// Otherwise, get the credentials from Duplo.
if creds == nil {
client := mustDuploClient(*host, *token, *interactive, true)
result, err := client.AdminGetJITAwsCredentials()
result, err := client.AdminGetJitAwsCredentials()
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func main() {
}

// Tenant: Get the JIT AWS credentials
result, err := client.TenantGetJITAwsCredentials(*tenantID)
result, err := client.TenantGetJitAwsCredentials(*tenantID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down
78 changes: 46 additions & 32 deletions cmd/duplo-jit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func main() {
// Otherwise, get the credentials from Duplo.
if creds == nil {
client, _ := internal.MustDuploClient(*host, *token, *interactive, true)
result, err := client.AdminGetJITAwsCredentials()
result, err := client.AdminGetJitAwsCredentials()
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand Down Expand Up @@ -134,29 +134,21 @@ func main() {

} else {

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

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

// Try to find credentials from the cache.
creds = internal.CacheGetAwsConfigOutput(cacheKey)

// Otherwise, get the credentials from Duplo.
if creds == nil {
client, _ := internal.MustDuploClient(*host, *token, *interactive, false)

// If it doesn't look like a UUID, get the tenant ID from the name.
if len(*tenantID) < 32 {
var err error
tenant, err := client.GetTenantByNameForUser(*tenantID)
if tenant == nil || err != nil {
internal.Fatal(fmt.Sprintf("%s: tenant missing or not allowed", *tenantID), err)
} else {
tenantID = &tenant.TenantID
}
}

// Tenant: Get the JIT AWS credentials
result, err := client.TenantGetJITAwsCredentials(*tenantID)
result, err := client.TenantGetJitAwsCredentials(*tenantID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertAwsCreds(result)
}
Expand All @@ -178,7 +170,7 @@ func main() {
cacheKey = strings.Join([]string{strings.TrimPrefix(*host, "https://"), "plan", *planID}, ",")

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

// Otherwise, get the credentials from Duplo.
if creds == nil {
Expand All @@ -195,36 +187,58 @@ func main() {

} else {

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

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

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

// Otherwise, get the credentials from Duplo.
if creds == nil {
client, _ := internal.MustDuploClient(*host, *token, *interactive, false)

// If it doesn't look like a UUID, get the tenant ID from the name.
if len(*tenantID) < 32 {
var err error
tenant, err := client.GetTenantByNameForUser(*tenantID)
if tenant == nil || err != nil {
internal.Fatal(fmt.Sprintf("%s: tenant missing or not allowed", *tenantID), err)
} else {
tenantID = &tenant.TenantID
}
}

// Tenant: Get the JIT AWS credentials
result, err := client.TenantGetK8sJitAccess(*tenantID)
internal.DieIf(err, "failed to get credentials")
creds = internal.ConvertK8sCreds(result)
}

}

// Finally, we can output credentials.
internal.OutputK8sCreds(creds, cacheKey)

}
}

func GetTenantIdAndName(tenantIDorName string, client *duplocloud.Client) (string, string) {
var tenantID string
var tenantName string

// If it doesn't look like a UUID, assume it is a name and get the tenant ID using its name.
if len(tenantIDorName) < 32 {
var err error
tenantName = tenantIDorName
tenant, err := client.GetTenantByNameForUser(tenantName)
if tenant == nil || err != nil {
internal.Fatal(fmt.Sprintf("%s: tenant missing or not allowed", tenantName), err)
} else {
tenantID = tenant.TenantID
}
} else {
// It looks like a UUID, assume it is one and get the tenant name using its ID.
var err error
tenantID = tenantIDorName
tenant, err := client.GetTenantForUser(tenantIDorName)
if tenant == nil || err != nil {
internal.Fatal(fmt.Sprintf("%s: tenant missing or not allowed", tenantID), err)
} else {
tenantName = tenant.AccountName
}
}

return tenantID, tenantName
}
Loading

0 comments on commit 2bfae75

Please sign in to comment.