diff --git a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.html b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.html index 6d320c70d6..07c3a7c620 100644 --- a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.html +++ b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.html @@ -14,9 +14,9 @@ <h1 class="create-endpoint__section-title">{{endpoint.definition.label}} Informa <mat-error *ngIf="registerForm.controls.urlField.errors?.pattern">Invalid API URL</mat-error> <mat-error *ngIf="registerForm.controls.urlField.errors?.appUnique">URL is not unique</mat-error> </mat-form-field> - <mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="overwriteEndpoints" - formControlName="overwriteEndpointsField" (change)="toggleOverwriteEndpoints()" - [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Automatically overwrite user endpoints + <mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createUserEndpoint" + formControlName="createUserEndpointField" (change)="toggleCreateUserEndpoint()" + [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a user endpoint (only visible to you and other admins) </mat-checkbox> <mat-checkbox matInput name="skipSll" formControlName="skipSllField" [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Skip SSL validation for the diff --git a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts index c7c53fd426..5bd40be54b 100644 --- a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts @@ -75,7 +75,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen // Optional Client ID and Client Secret clientIDField: ['', []], clientSecretField: ['', []], - overwriteEndpointsField: [false, []], + createUserEndpointField: [false, []], }); const epType = getIdFromRoute(activatedRoute, 'type'); @@ -98,7 +98,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen this.registerForm.value.clientIDField, this.registerForm.value.clientSecretField, this.registerForm.value.ssoAllowedField, - this.registerForm.value.overwriteEndpointsField, + this.registerForm.value.createUserEndpointField, ).pipe( pairwise(), filter(([oldVal, newVal]) => (oldVal.busy && !newVal.busy)), @@ -149,7 +149,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen this.showAdvancedOptions = !this.showAdvancedOptions; } - toggleOverwriteEndpoints() { + toggleCreateUserEndpoint() { // wait a tick for validators to adjust to new data in the directive setTimeout(() => { this.registerForm.controls.nameField.updateValueAndValidity(); diff --git a/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.html b/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.html index 085697fcbd..21572423a8 100644 --- a/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.html +++ b/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.html @@ -31,9 +31,9 @@ <h3>Select the type of {{gitTypes[epSubType].label}} to register</h3> <mat-error *ngIf="registerForm.controls.urlField.errors?.pattern">Invalid API URL</mat-error> <mat-error *ngIf="registerForm.controls.urlField.errors?.appUnique">URL is not unique</mat-error> </mat-form-field> - <mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="overwriteEndpoints" - formControlName="overwriteEndpointsField" (change)="toggleOverwriteEndpoints()" - [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Automatically overwrite user endpoints + <mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createUserEndpoint" + formControlName="createUserEndpointField" (change)="toggleCreateUserEndpoint()" + [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a user endpoint (only visible to you and other admins) </mat-checkbox> <mat-checkbox matInput name="skipSll" formControlName="skipSllField" [ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Skip SSL validation for the diff --git a/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.ts b/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.ts index 27d1243780..bfdbf8c956 100644 --- a/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.ts +++ b/src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.ts @@ -159,7 +159,7 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl nameField: ['', [Validators.required]], urlField: ['', [Validators.required]], skipSllField: [false, []], - overwriteEndpointsField: [false, []], + createUserEndpointField: [false, []], }); this.updateType(); @@ -201,10 +201,10 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl const skipSSL = this.registerForm.controls.nameField.value && this.registerForm.controls.urlField.value ? this.registerForm.controls.skipSllField.value : false; - const overwriteEndpoints = this.registerForm.controls.overwriteEndpointsField.value; + const createUserEndpoint = this.registerForm.controls.createUserEndpointField.value; return stratosEntityCatalog.endpoint.api.register<ActionState>(GIT_ENDPOINT_TYPE, - this.epSubType, name, url, skipSSL, '', '', false, overwriteEndpoints) + this.epSubType, name, url, skipSSL, '', '', false, createUserEndpoint) .pipe( pairwise(), filter(([oldVal, newVal]) => (oldVal.busy && !newVal.busy)), @@ -240,7 +240,7 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl return ready + '/' + defn.urlSuffix; } - toggleOverwriteEndpoints() { + toggleCreateUserEndpoint() { // wait a tick for validators to adjust to new data in the directive setTimeout(() => { this.registerForm.controls.nameField.updateValueAndValidity(); diff --git a/src/frontend/packages/store/src/actions/endpoint.actions.ts b/src/frontend/packages/store/src/actions/endpoint.actions.ts index 26b11a231a..2d93409c39 100644 --- a/src/frontend/packages/store/src/actions/endpoint.actions.ts +++ b/src/frontend/packages/store/src/actions/endpoint.actions.ts @@ -215,7 +215,7 @@ export class RegisterEndpoint extends SingleBaseEndpointAction { public clientID = '', public clientSecret = '', public ssoAllowed: boolean, - public overwriteEndpoints: boolean, + public createUserEndpoint: boolean, ) { super( REGISTER_ENDPOINTS, diff --git a/src/frontend/packages/store/src/effects/endpoint.effects.ts b/src/frontend/packages/store/src/effects/endpoint.effects.ts index 426bf173fb..e51ef30fa2 100644 --- a/src/frontend/packages/store/src/effects/endpoint.effects.ts +++ b/src/frontend/packages/store/src/effects/endpoint.effects.ts @@ -195,7 +195,7 @@ export class EndpointsEffect { cnsi_client_id: action.clientID, cnsi_client_secret: action.clientSecret, sso_allowed: action.ssoAllowed ? 'true' : 'false', - overwrite_endpoints: action.overwriteEndpoints ? 'true' : 'false' + create_user_endpoint: action.createUserEndpoint ? 'true' : 'false' }; // Do not include sub_type in HttpParams if it doesn't exist (falsies get stringified and sent) if (action.endpointSubType) { diff --git a/src/frontend/packages/store/src/stratos-action-builders.ts b/src/frontend/packages/store/src/stratos-action-builders.ts index d2c869fe1f..57d2dfe19b 100644 --- a/src/frontend/packages/store/src/stratos-action-builders.ts +++ b/src/frontend/packages/store/src/stratos-action-builders.ts @@ -60,7 +60,7 @@ export interface EndpointActionBuilder extends OrchestratedActionBuilders { clientID?: string, clientSecret?: string, ssoAllowed?: boolean, - overwriteEndpointsField?: boolean, + createUserEndpointField?: boolean, ) => RegisterEndpoint; update: ( guid: string, @@ -105,7 +105,7 @@ export const endpointActionBuilder: EndpointActionBuilder = { clientID?: string, clientSecret?: string, ssoAllowed?: boolean, - overwriteEndpoints?: boolean, + createUserEndpoint?: boolean, ) => new RegisterEndpoint( endpointType, endpointSubType, @@ -115,7 +115,7 @@ export const endpointActionBuilder: EndpointActionBuilder = { clientID, clientSecret, ssoAllowed, - overwriteEndpoints, + createUserEndpoint, ), update: ( guid: string, diff --git a/src/jetstream/cnsi.go b/src/jetstream/cnsi.go index 9c89551ff7..ac6159ca67 100644 --- a/src/jetstream/cnsi.go +++ b/src/jetstream/cnsi.go @@ -63,10 +63,10 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info cnsiClientSecret := params.CNSIClientSecret subType := params.SubType - overwriteEndpoints, err := strconv.ParseBool(params.OverwriteEndpoints) + createUserEndpoint, err := strconv.ParseBool(params.CreateUserEndpoint) if err != nil { // default to false - overwriteEndpoints = false + createUserEndpoint = false } if cnsiClientId == "" { @@ -82,7 +82,7 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info "Failed to get session user: %v", err) } - newCNSI, err := p.DoRegisterEndpoint(params.CNSIName, params.APIEndpoint, skipSSLValidation, cnsiClientId, cnsiClientSecret, userID, ssoAllowed, subType, overwriteEndpoints, fetchInfo) + newCNSI, err := p.DoRegisterEndpoint(params.CNSIName, params.APIEndpoint, skipSSLValidation, cnsiClientId, cnsiClientSecret, userID, ssoAllowed, subType, createUserEndpoint, fetchInfo) if err != nil { return err } @@ -91,7 +91,7 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info return nil } -func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, overwriteEndpoints bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) { +func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createUserEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) { log.Debug("DoRegisterEndpoint") if len(cnsiName) == 0 || len(apiEndpoint) == 0 { @@ -170,19 +170,19 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk } /* - if isAdmin && overwriteEndpoints { - for _, duplicate := range duplicateEndpoints { - log.Infof("An administrator is registering an endpoint with the same API URL ('%+v') as an endpoint administrator's. The existing duplicate endpoint ('%+v') will be removed", apiEndpoint, duplicate.GUID) - err := p.doUnregisterCluster(duplicate.GUID) - if err != nil { - return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError( - http.StatusInternalServerError, - "Failed to unregister cluster", - "Failed to unregister cluster: %v", - err) + if isAdmin && overwriteEndpoints { + for _, duplicate := range duplicateEndpoints { + log.Infof("An administrator is registering an endpoint with the same API URL ('%+v') as an endpoint administrator's. The existing duplicate endpoint ('%+v') will be removed", apiEndpoint, duplicate.GUID) + err := p.doUnregisterCluster(duplicate.GUID) + if err != nil { + return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError( + http.StatusInternalServerError, + "Failed to unregister cluster", + "Failed to unregister cluster: %v", + err) + } } } - } */ } @@ -315,7 +315,7 @@ func (p *portalProxy) buildCNSIList(c echo.Context) ([]*interfaces.CNSIRecord, e for i := 0; i < len(filteredList); i++ { if filteredList[i].APIEndpoint.String() == endpoint.APIEndpoint.String() { - duplicateSystemEndpoint = len(filteredList[i].Creator) != 0 + duplicateSystemEndpoint = len(filteredList[i].Creator) == 0 duplicateEndpointIndex = i } } diff --git a/src/jetstream/mock_server_test.go b/src/jetstream/mock_server_test.go index 58d1dfeec8..ec4c9e2cf6 100644 --- a/src/jetstream/mock_server_test.go +++ b/src/jetstream/mock_server_test.go @@ -272,7 +272,7 @@ func setupMockUser(guid string, admin bool, scopes []string) MockUser { } // mockV2Info needs to be closed -func setupMockEndpointRegisterRequest(t *testing.T, user *interfaces.ConnectedUser, mockV2Info *httptest.Server, endpointName string, overwriteEndpoints bool) MockEndpointRequest { +func setupMockEndpointRegisterRequest(t *testing.T, user *interfaces.ConnectedUser, mockV2Info *httptest.Server, endpointName string, createUserEndpoint bool) MockEndpointRequest { // create a request for each endpoint req := setupMockReq("POST", "", map[string]string{ @@ -281,7 +281,7 @@ func setupMockEndpointRegisterRequest(t *testing.T, user *interfaces.ConnectedUs "skip_ssl_validation": "true", "cnsi_client_id": mockClientId, "cnsi_client_secret": mockClientSecret, - "overwrite_endpoints": strconv.FormatBool(overwriteEndpoints), + "create_user_endpoint": strconv.FormatBool(createUserEndpoint), }) res := httptest.NewRecorder() diff --git a/src/jetstream/repository/interfaces/portal_proxy.go b/src/jetstream/repository/interfaces/portal_proxy.go index c31e21bd26..8b84ced2fc 100644 --- a/src/jetstream/repository/interfaces/portal_proxy.go +++ b/src/jetstream/repository/interfaces/portal_proxy.go @@ -14,7 +14,7 @@ type PortalProxy interface { GetHttpClient(skipSSLValidation bool) http.Client GetHttpClientForRequest(req *http.Request, skipSSLValidation bool) http.Client RegisterEndpoint(c echo.Context, fetchInfo InfoFunc) error - DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, overwriteEndpoints bool, fetchInfo InfoFunc) (CNSIRecord, error) + DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createUserEndpoint bool, fetchInfo InfoFunc) (CNSIRecord, error) GetEndpointTypeSpec(typeName string) (EndpointPlugin, error) // Auth diff --git a/src/jetstream/repository/interfaces/structs.go b/src/jetstream/repository/interfaces/structs.go index 8ecf6fafd2..fccdc53ebc 100644 --- a/src/jetstream/repository/interfaces/structs.go +++ b/src/jetstream/repository/interfaces/structs.go @@ -433,7 +433,7 @@ type RegisterEndpointParams struct { CNSIClientID string `json:"cnsi_client_id" form:"cnsi_client_id" query:"cnsi_client_id"` CNSIClientSecret string `json:"cnsi_client_secret" form:"cnsi_client_secret" query:"cnsi_client_secret"` SubType string `json:"sub_type" form:"sub_type" query:"sub_type"` - OverwriteEndpoints string `json:"overwrite_endpoints" form:"overwrite_endpoints" query:"overwrite_endpoints"` + CreateUserEndpoint string `json:"create_user_endpoint" form:"create_user_endpoint" query:"create_user_endpoint"` } type UpdateEndpointParams struct {