Skip to content

Commit

Permalink
tls: Create separate pkg to create keypair
Browse files Browse the repository at this point in the history
It is going to used for all the provider so better to extract it and
have different subpackage.
  • Loading branch information
praveenkumar committed Sep 15, 2023
1 parent e22267b commit 8956f81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 2 additions & 7 deletions pkg/provider/aws/create-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
providerAPI "github.com/crc/crc-cloud/pkg/manager/provider/api"
"github.com/crc/crc-cloud/pkg/provider/aws/sg"
"github.com/crc/crc-cloud/pkg/util"
crctls "github.com/crc/crc-cloud/pkg/util/tls"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi-tls/sdk/v4/go/tls"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
Expand Down Expand Up @@ -118,13 +119,7 @@ func securityGroupsIds(ctx *pulumi.Context) (pulumi.StringArrayInput, error) {
}

func createKey(ctx *pulumi.Context) (*tls.PrivateKey, *ec2.KeyPair, error) {
pk, err := tls.NewPrivateKey(
ctx,
"OpenshiftLocal-OCP",
&tls.PrivateKeyArgs{
Algorithm: pulumi.String("RSA"),
RsaBits: pulumi.Int(4096),
})
pk, err := crctls.CreateKey(ctx)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/gcp/create-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
providerAPI "github.com/crc/crc-cloud/pkg/manager/provider/api"
"github.com/crc/crc-cloud/pkg/provider/constants"
"github.com/crc/crc-cloud/pkg/util"
crctls "github.com/crc/crc-cloud/pkg/util/tls"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
"github.com/pulumi/pulumi-tls/sdk/v4/go/tls"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
Expand Down Expand Up @@ -50,7 +51,7 @@ func fillCreateRequest(projectName, bootingPrivateKeyFilePath, ocpPullSecretFile
}

func (r createRequest) runFunc(ctx *pulumi.Context) error {
privateKey, err := createKey(ctx)
privateKey, err := crctls.CreateKey(ctx)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/util/tls/tls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tls

import (
"github.com/pulumi/pulumi-tls/sdk/v4/go/tls"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func CreateKey(ctx *pulumi.Context) (*tls.PrivateKey, error) {
pk, err := tls.NewPrivateKey(
ctx,
"OpenshiftLocal-OCP",
&tls.PrivateKeyArgs{
Algorithm: pulumi.String("RSA"),
RsaBits: pulumi.Int(4096),
})
if err != nil {
return nil, err
}
return pk, nil
}

0 comments on commit 8956f81

Please sign in to comment.