Skip to content

how to get the response body from GPGKeys.Create()? #1058

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

Open
evilensky opened this issue Feb 12, 2025 · 0 comments
Open

how to get the response body from GPGKeys.Create()? #1058

evilensky opened this issue Feb 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@evilensky
Copy link
Contributor

go-tfe version

v1.75.0

Description

When I call GPGKeys.Create() and Terraform Cloud returns an error, I am unable to print the response itself?

Testing plan

		// Add key to provider
		options := tfe.GPGKeyCreateOptions{
			AsciiArmor: keyData,
			Type:       "gpg-keys",
			Namespace:  org,
		}

		key, err := client.GPGKeys.Create(cmd.Context(), tfe.PrivateRegistry, options)
		if err != nil {
			log.Printf("Error adding key: %s", err)
			return
		}

		fmt.Printf("Key added successfully: %s\n", key.KeyID)

Expected Behavior

the curl response is:

❯ curl --header "Authorization: Bearer $TFC_TOKEN" --header "Content-Type: application/vnd.api+json" --request POST --data @gpg-output.json https://app.terraform.io/api/registry/private/v2/gpg-keys

{"errors":["could not create GPG key: GPG key REDACTED already exists for namespace REDACTED"]}%  

Actual Behavior

			log.Printf("Error adding key: %s", err)

prints:

2025/02/12 08:18:29 Error adding key: 400 Bad Request

Additional Context

@evilensky evilensky added the bug Something isn't working label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant