Skip to content

Commit

Permalink
Update the endpoint to the fully qualified api path
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Dec 9, 2021
1 parent 54c2af9 commit c1a924b
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion harness/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewClient() *Client {
HTTPClient: httpClient,
}),
NGClient: nextgen.NewAPIClient(&nextgen.Configuration{
BasePath: helpers.EnvVars.NGEndpoint.GetWithDefault(DefaultNGApiUrl),
BasePath: helpers.EnvVars.NGEndpoint.GetWithDefault(utils.DefaultNGApiUrl),
DefaultHeader: map[string]string{
helpers.EnvVars.NGApiKey.String(): helpers.EnvVars.NGApiKey.Get(),
},
Expand Down
6 changes: 0 additions & 6 deletions harness/api/consts.go

This file was deleted.

8 changes: 4 additions & 4 deletions harness/cd/cac.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func FindConfigAsCodeItemByUUID(rootItem *cac.ConfigAsCodeItem, uuid string) *ca
}

func (c *ConfigAsCodeClient) GetDirectoryItemContent(restName string, uuid string, applicationId string) (*cac.ConfigAsCodeItem, error) {
path := fmt.Sprintf("/gateway/api/setup-as-code/yaml/%s/%s", restName, uuid)
path := fmt.Sprintf("/setup-as-code/yaml/%s/%s", restName, uuid)
log.Printf("[DEBUG] CAC: Getting directory item content at %s", path)

req, err := c.ApiClient.NewAuthorizedGetRequest(path)
Expand All @@ -83,7 +83,7 @@ func (c *ConfigAsCodeClient) GetDirectoryItemContent(restName string, uuid strin
}

func (c *ConfigAsCodeClient) GetDirectoryTree(applicationId string) (*cac.ConfigAsCodeItem, error) {
path := "/gateway/api/setup-as-code/yaml/directory"
path := "/setup-as-code/yaml/directory"
log.Printf("[DEBUG] CAC: Getting directory tree for app '%s'", applicationId)

req, err := c.ApiClient.NewAuthorizedGetRequest(path)
Expand Down Expand Up @@ -139,7 +139,7 @@ func (c *ConfigAsCodeClient) UpsertRawYaml(filePath cac.YamlPath, yaml []byte) (

log.Printf("[TRACE] CAC: HTTP Request Body %s", string(yaml))

req, err := c.ApiClient.NewAuthorizedPostRequest("/gateway/api/setup-as-code/yaml/upsert-entity", &b)
req, err := c.ApiClient.NewAuthorizedPostRequest("/setup-as-code/yaml/upsert-entity", &b)

// Set proper content header
req.Header.Set(helpers.HTTPHeaders.ContentType.String(), w.FormDataContentType())
Expand Down Expand Up @@ -227,7 +227,7 @@ type ConfigAsCodeClient struct {

func (c *ConfigAsCodeClient) DeleteEntity(filePath cac.YamlPath) error {
log.Printf("[DEBUG] CAC: Deleting entity at %s", filePath)
req, err := c.ApiClient.NewAuthorizedDeleteRequest("/gateway/api/setup-as-code/yaml/delete-entities")
req, err := c.ApiClient.NewAuthorizedDeleteRequest("/setup-as-code/yaml/delete-entities")

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/encrypted_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *SecretClient) GetEncryptedTextById(id string) (*graphql.EncryptedText,

// WARNING: This method requires the use of a bearer token which isn't supported in most scenarios.
func (c *SecretClient) ListEncryptedTextSecrets(limit int, offset int) ([]*unpublished.EncryptedText, *graphql.PageInfo, error) {
req, err := c.ApiClient.NewAuthorizedGetRequest("/gateway/api/secrets/list-secrets-page")
req, err := c.ApiClient.NewAuthorizedGetRequest("/secrets/list-secrets-page")
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/go-retryablehttp"
)

const DefaultGraphQLApiUrl = "/gateway/api/graphql"
const DefaultGraphQLApiUrl = "/graphql"

func (m *GraphQLResponseMessage) ToError() error {
return fmt.Errorf("%s %s: %s", m.Level, m.Code, m.Message)
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNewGraphQLRequest(t *testing.T) {
// Validate
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("accountId=%s", client.Configuration.AccountId), req.URL.RawQuery)
require.Equal(t, client.Configuration.Endpoint, fmt.Sprintf("%s://%s", req.URL.Scheme, req.Host))
require.Equal(t, client.Configuration.Endpoint, fmt.Sprintf("%s://%s/gateway/api", req.URL.Scheme, req.Host))
require.Equal(t, client.Configuration.APIKey, req.Header.Get(helpers.HTTPHeaders.ApiKey.String()))
require.Equal(t, helpers.HTTPHeaders.ApplicationJson.String(), req.Header.Get(helpers.HTTPHeaders.ContentType.String()))
require.Equal(t, helpers.HTTPHeaders.ApplicationJson.String(), req.Header.Get(helpers.HTTPHeaders.Accept.String()))
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/secret_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (ac *SecretClient) GetSecretManagerByName(name string) (*graphql.SecretMana

// WARNING: This method requires the use of a bearer token which isn't supported in most scenarios.
func (c *SecretClient) ListSecretManagers() ([]*unpublished.SecretManager, error) {
req, err := c.ApiClient.NewAuthorizedGetRequest("/gateway/api/secrets/list-configs")
req, err := c.ApiClient.NewAuthorizedGetRequest("/secrets/list-configs")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/ssh_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (c *SecretClient) GetSSHCredentialByName(name string) (*graphql.SSHCredenti

// WARNING: This method requires the use of a bearer token which isn't supported in most scenarios.
func (c *SecretClient) ListSSHCredentials() ([]*unpublished.Credential, error) {
req, err := c.ApiClient.NewAuthorizedGetRequest("/gateway/api/secrets/list-values")
req, err := c.ApiClient.NewAuthorizedGetRequest("/secrets/list-values")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion harness/cd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type APIVersionResponse struct {

// Returns the version of Harness that we're connecting to
func (client *ApiClient) GetAPIVersion() (*APIVersionResponse, error) {
req, err := client.NewAuthorizedGetRequest("/api/version")
req, err := client.NewAuthorizedGetRequest("/version")

if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions harness/cd/winrm_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func getWinRMCredentialFields() string {
}

func (c *SecretClient) ListWinRMCredentials() ([]*unpublished.Credential, error) {
req, err := c.ApiClient.NewAuthorizedGetRequest("gateway/api/secrets/list-values")
req, err := c.ApiClient.NewAuthorizedGetRequest("/secrets/list-values")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -103,5 +103,3 @@ func (c *SecretClient) ListWinRMCredentials() ([]*unpublished.Credential, error)

return winrmCreds, nil
}

// https://app.harness.io/gateway/api/secrets/list-values?accountId=UKh5Yts7THSMAbccG3HrLA
4 changes: 3 additions & 1 deletion harness/utils/const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package utils

const (
DefaultApiUrl = "https://app.harness.io"
DefaultApiUrl = "https://app.harness.io/gateway/api"
DefaultNGApiUrl = "https://app.harness.io/gateway/ng/api"
GraphQLInvalidTokenErrorCode = "INVALID_TOKEN"
)

0 comments on commit c1a924b

Please sign in to comment.