Skip to content

Commit

Permalink
Rename overwriteEndpoints in createUserEndpoint (#4876)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Quandt <[email protected]>
  • Loading branch information
thquad authored and richard-cox committed Apr 16, 2021
1 parent baa0bfc commit 18add26
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)),
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl
nameField: ['', [Validators.required]],
urlField: ['', [Validators.required]],
skipSllField: [false, []],
overwriteEndpointsField: [false, []],
createUserEndpointField: [false, []],
});
this.updateType();

Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/packages/store/src/stratos-action-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface EndpointActionBuilder extends OrchestratedActionBuilders {
clientID?: string,
clientSecret?: string,
ssoAllowed?: boolean,
overwriteEndpointsField?: boolean,
createUserEndpointField?: boolean,
) => RegisterEndpoint;
update: (
guid: string,
Expand Down Expand Up @@ -105,7 +105,7 @@ export const endpointActionBuilder: EndpointActionBuilder = {
clientID?: string,
clientSecret?: string,
ssoAllowed?: boolean,
overwriteEndpoints?: boolean,
createUserEndpoint?: boolean,
) => new RegisterEndpoint(
endpointType,
endpointSubType,
Expand All @@ -115,7 +115,7 @@ export const endpointActionBuilder: EndpointActionBuilder = {
clientID,
clientSecret,
ssoAllowed,
overwriteEndpoints,
createUserEndpoint,
),
update: (
guid: string,
Expand Down
32 changes: 16 additions & 16 deletions src/jetstream/cnsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}
*/

}
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/jetstream/mock_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/jetstream/repository/interfaces/portal_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/jetstream/repository/interfaces/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 18add26

Please sign in to comment.