Skip to content

GitOps API's Don't Read ApiKey from Client #200

@steve-gray

Description

@steve-gray

Trying to debug some issues with Terraform module for Harness, and found that after trying to use the underlying SDK for Go directly myself that it suffers from the same problem I was seeing: 401 unauthorized.

Looking into the various underlying operations, such as GetClusterList we see the auth code is trying to read from the context:

	if ctx != nil {
		// API Key Authentication
		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
			var key string
			if auth.Prefix != "" {
				key = auth.Prefix + " " + auth.Key
			} else {
				key = auth.Key
			}
			localVarHeaderParams["x-api-key"] = key

		}
	}

However, I'm not sure - but don't these need to also check the c.client.cfg.ApiKey? I'm passing the API key as a setup parameter to the nextgen API client, and it's being propagated into the struct for the clusters APIs etc. If I hack the code to manually set my API key from the structs API key, then it seems to work fine though. It seems like this is a pattern throughout the whole SDK.

Cross reference at: harness/terraform-provider-harness#260

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions