Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

APIGOV-27284 - share strings for sonar warnings #79

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pkg/webmethods/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

const HealthCheckEndpoint = "health"
const searchURL = "%s/rest/apigateway/search"
const getApplicationURL = "%s/rest/apigateway/applications/%s"

// Page describes the page query parameter
type Page struct {
Expand Down Expand Up @@ -148,7 +150,7 @@ func (c *WebMethodClient) ListAPIs() ([]ListApiResponse, error) {

func (c *WebMethodClient) SearchAPIs() (*Apis, error) {
//webmethodsApis := make([]WebmethodsApi, 0)
url := fmt.Sprintf("%s/rest/apigateway/search", c.url)
url := fmt.Sprintf(searchURL, c.url)
requestStr := `{
"types": [
"api"
Expand Down Expand Up @@ -278,7 +280,7 @@ func (c *WebMethodClient) FindApplicationByName(applicationName string) (*Search
scope.AttributeName = "name"
scope.Keyword = applicationName
searchRequest.Scope = []Scope{scope}
url := fmt.Sprintf("%s/rest/apigateway/search", c.url)
url := fmt.Sprintf(searchURL, c.url)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand Down Expand Up @@ -307,7 +309,7 @@ func (c *WebMethodClient) FindApplicationByName(applicationName string) (*Search

func (c *WebMethodClient) GetApplication(applicationId string) (*ApplicationResponse, error) {
applicationResponse := &ApplicationResponse{}
url := fmt.Sprintf("%s/rest/apigateway/applications/%s", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL, c.url, applicationId)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Accept": "application/json",
Expand Down Expand Up @@ -358,7 +360,7 @@ func (c *WebMethodClient) CreateApplication(application *Application) (*Applicat

func (c *WebMethodClient) UpdateApplication(application *Application) (*Application, error) {
responseApplication := &Application{}
url := fmt.Sprintf("%s/rest/apigateway/applications/%s", c.url, application.Id)
url := fmt.Sprintf(getApplicationURL, c.url, application.Id)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand Down Expand Up @@ -440,7 +442,7 @@ func (c *WebMethodClient) GetStrategy(strategyId string) (*StrategyResponse, err
}

func (c *WebMethodClient) SubscribeApplication(applicationId string, ApplicationApiSubscription *ApplicationApiSubscription) error {
url := fmt.Sprintf("%s/rest/apigateway/applications/%s/apis", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL+"/apis", c.url, applicationId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you have + signs on some of these

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, otherwise you will need separate fmt template for each applicationURL, applicationURL/apis, applicationURL/accessTokens

headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand All @@ -467,7 +469,7 @@ func (c *WebMethodClient) SubscribeApplication(applicationId string, Application
}

func (c *WebMethodClient) RotateApplicationApikey(applicationId string) error {
url := fmt.Sprintf("%s/rest/apigateway/applications/%s/accessTokens", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL+"/accessTokens", c.url, applicationId)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand Down Expand Up @@ -539,7 +541,7 @@ func (c *WebMethodClient) RefereshOauth2Credential(strategyId string) (*Strategy
}

func (c *WebMethodClient) DeleteApplication(applicationId string) error {
url := fmt.Sprintf("%s/rest/apigateway/applications/%s", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL, c.url, applicationId)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand All @@ -561,7 +563,7 @@ func (c *WebMethodClient) DeleteApplication(applicationId string) error {
}

func (c *WebMethodClient) DeleteApplicationAccessTokens(applicationId string) error {
url := fmt.Sprintf("%s/rest/apigateway/applications/%s/accessTokens", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL+"/accessTokens", c.url, applicationId)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand All @@ -585,7 +587,7 @@ func (c *WebMethodClient) DeleteApplicationAccessTokens(applicationId string) er
}

func (c *WebMethodClient) UnsubscribeApplication(applicationId string, apiId string) error {
url := fmt.Sprintf("%s/rest/apigateway/applications/%s/apis", c.url, applicationId)
url := fmt.Sprintf(getApplicationURL+"/apis", c.url, applicationId)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand Down Expand Up @@ -633,7 +635,7 @@ func (c *WebMethodClient) ListOauth2Servers() (*OauthServers, error) {
"sortByField": "name"
}`
oauthServers := &OauthServers{}
url := fmt.Sprintf("%s/rest/apigateway/search", c.url)
url := fmt.Sprintf(searchURL, c.url)
headers := map[string]string{
"Authorization": c.createAuthToken(),
"Content-Type": "application/json",
Expand Down