Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/azure cert deploy #1132

Merged
merged 12 commits into from
Jul 3, 2024
22 changes: 12 additions & 10 deletions atrium/vestibulum/trcdb/trccertmgmtbase/trccertmgmtbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/apimanagement/armapimanagement/v2"
"github.com/trimble-oss/tierceron/buildopts/memonly"
"github.com/trimble-oss/tierceron/buildopts/memprotectopts"
eUtils "github.com/trimble-oss/tierceron/pkg/utils"
"github.com/trimble-oss/tierceron/pkg/vaulthelper/kv"
)
Expand All @@ -23,10 +21,6 @@ func CommonMain(certPathPtr *string, driverConfig *eUtils.DriverConfig, mod *kv.
return errors.New("certPath flag is empty, expected path to cert")
}

if memonly.IsMemonly() {
memprotectopts.MemProtectInit(nil)
}

certBytes, err := os.ReadFile(*certPathPtr)
if err != nil {
return err
Expand Down Expand Up @@ -61,11 +55,19 @@ func CommonMain(certPathPtr *string, driverConfig *eUtils.DriverConfig, mod *kv.
return err
}

resourceGroupName := apimConfigMap["RESOURCE_GROUP_NAME"]
serviceName := apimConfigMap["SERVICE_NAME"]
resourceGroupName, exists := apimConfigMap["RESOURCE_GROUP_NAME"]
isaac-boaz-trimble marked this conversation as resolved.
Show resolved Hide resolved
if !exists {
return errors.New("RESOURCE_GROUP_NAME is not populated in apimConfigMap")
}

serviceName, exists := apimConfigMap["SERVICE_NAME"]
isaac-boaz-trimble marked this conversation as resolved.
Show resolved Hide resolved
if !exists {
return errors.New("SERVICE_NAME is not populated in apimConfigMap")
}

certificateId := time.Now().UTC().Format(strings.ReplaceAll(time.RFC3339, ":", "-"))

etag := "*" //Wildcard match on eTag, otherwise it doesn't match from command above.
etag := "*"

_, err = clientFactory.NewCertificateClient().CreateOrUpdate(ctx, resourceGroupName, serviceName, certificateId, armapimanagement.CertificateCreateOrUpdateParameters{
Properties: &armapimanagement.CertificateCreateOrUpdateProperties{
Expand All @@ -79,6 +81,6 @@ func CommonMain(certPathPtr *string, driverConfig *eUtils.DriverConfig, mod *kv.
return err
}

fmt.Println("Success!")
fmt.Printf("Certificate %v successfully deployed\n", certificateId)
return nil
}