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

Add /api/v2/config endpoint #278

Merged
merged 16 commits into from
Feb 19, 2024
Merged

Add /api/v2/config endpoint #278

merged 16 commits into from
Feb 19, 2024

Conversation

BogdanIrimie
Copy link
Contributor

@BogdanIrimie BogdanIrimie commented Feb 9, 2024

The topaz console is moving to the v2 config which contains a list of configs. To support this in topaz we are adding /api/v2/config endpoint which returns a list of configs and a flag that says if the configs are editable or not. In the case of topaz they are never editable that is why we set the readOnly flag to true

Sample output of the new endpoint

{
    "readOnly": true,
    "authenticationEnabled": true,
    "configs": [
        {
            "configType": "auto",
            "name": "Topaz Config",
            "address": "https://localhost:4321/api/v2/config",
            "authorizerServiceUrl": "https://localhost:8383",
            "authorizerApiKey": "",
            "directoryServiceUrl": "https://localhost:9393",
            "directoryApiKey": "",
            "directoryTenantId": "",
            "directoryReaderServiceUrl": "https://localhost:9393",
            "directoryWriterServiceUrl": "https://localhost:9393",
            "directoryImporterServiceUrl": "https://localhost:9393",
            "directoryExporterServiceUrl": "https://localhost:9393",
            "directoryModelServiceUrl": "https://localhost:9393"
        }
    ]
}

Request example:

curl 'https://localhost:8080/api/v2/config' \
  -H 'content-type: application/json' \
  --compressed | jq

The API keys are returned only when the user is authenticated or if anonymous auth is enabled.

closes https://github.com/aserto-dev/workspace/issues/576

Copy link

github-actions bot commented Feb 9, 2024

Pull Request Test Coverage Report for Build 7888525799

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • -73 of 73 (0.0%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.09%) to 37.266%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/app/topaz.go 0 5 0.0%
pkg/app/console.go 0 9 0.0%
pkg/app/handlers/ui.go 0 9 0.0%
pkg/app/handlers/authorizer.go 0 18 0.0%
pkg/app/handlers/config.go 0 32 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/app/topaz.go 1 60.73%
Totals Coverage Status
Change from base Build 7819049478: -0.09%
Covered Lines: 1494
Relevant Lines: 4009

💛 - Coveralls

Comment on lines 10 to 17
AsertoDirectoryURL string `json:"asertoDirectoryUrl"`
AuthorizerServiceURL string `json:"authorizerServiceUrl"`
AuthorizerAPIKey string `json:"authorizerApiKey"`
DirectoryAPIKey string `json:"directoryApiKey"`
DirectoryTenantID string `json:"directoryTenantId"`
AsertoDirectoryReaderURL *string `json:"asertoDirectoryReaderUrl,omitempty"`
AsertoDirectoryWriterURL *string `json:"asertoDirectoryWriterUrl,omitempty"`
AsertoDirectoryModelURL *string `json:"asertoDirectoryModelUrl,omitempty"`
Copy link
Member

@gimmyxd gimmyxd Feb 13, 2024

Choose a reason for hiding this comment

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

@BogdanIrimie could we create some symmetry between authorizer and directory?

Let me know if this looks good and i can do the same in BFF

AuthorizerServiceURL     string  `json:"authorizerServiceUrl"`
AuthorizerAPIKey         string  `json:"authorizerApiKey"`
DirectoryServiceURL       string  `json:"directoryServiceUrl"`
DirectoryAPIKey          string  `json:"directoryApiKey"`
DirectoryTenantID        string  `json:"directoryTenantId"`
DirectoryReaderServiceURL *string `json:"directoryReaderServiceUrl,omitempty"`
DirectoryWriterServiceURL *string `json:"directoryWriterServiceUrl,omitempty"`
DirectoryModelServiceURL  *string `json:"directoryModelServiceUrl,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, the result after the changes is

{
    "readOnly": true,
    "configs": [
        {
            "configType": "auto",
            "name": "Topaz Config",
            "address": "https://localhost:4321/api/v2/config",
            "authorizerServiceUrl": "https://localhost:8383",
            "authorizerApiKey": "",
            "directoryApiKey": "",
            "directoryTenantId": "",
            "directoryReaderServiceUrl": "https://localhost:9393",
            "directoryWriterServiceUrl": "https://localhost:9393",
            "directoryModelServiceUrl": "https://localhost:9393"
        }
    ]
}

@BogdanIrimie
Copy link
Contributor Author

Added the authenticatedUser flag just so we know if the user was authenticated or not when the call was made. This makes it easy to distinguish between not receiving API keys because there are none or because the users was not authenticated.

pkg/app/auth/http.go Outdated Show resolved Hide resolved
pkg/app/auth/http.go Show resolved Hide resolved
pkg/app/auth/http.go Outdated Show resolved Hide resolved
pkg/app/handlers/config.go Outdated Show resolved Hide resolved
pkg/app/handlers/config.go Outdated Show resolved Hide resolved
@BogdanIrimie BogdanIrimie changed the base branch from main to model-v2 February 19, 2024 15:41
pkg/app/auth/http.go Outdated Show resolved Hide resolved
cfgV2 := &TopazCfgV2{
Type: "auto",
Name: "Topaz Config",
Address: "https://localhost:4321/api/v2/config",
Copy link
Member

Choose a reason for hiding this comment

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

This seems to hardcode the Address. I think we need to provide the configured address for the console service here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated so we return the console URL e.g.

{
    "readOnly": true,
    "configs": [
        {
            "configType": "auto",
            "name": "Topaz Config",
            "address": "https://localhost:8080/api/v2/config",
            "authorizerServiceUrl": "https://localhost:8383",
            "authorizerApiKey": "",
            "directoryServiceUrl": "https://localhost:9393",
            "directoryApiKey": "",
            "directoryTenantId": "",
            "directoryReaderServiceUrl": "https://localhost:9393",
            "directoryWriterServiceUrl": "https://localhost:9393",
            "directoryImporterServiceUrl": "https://localhost:9393",
            "directoryExporterServiceUrl": "https://localhost:9393",
            "directoryModelServiceUrl": "https://localhost:9393"
        }
    ]
}

@ronenh ronenh merged commit d5cdff5 into model-v2 Feb 19, 2024
5 checks passed
@ronenh ronenh deleted the add-v2-cfg branch February 19, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants