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

Associate project for every organisation fetched #6518

Closed
wants to merge 133 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
45d13b0
Script added for table 'users' (#5722)
sonali523 Sep 16, 2021
5729342
iam added on roles tab
iamazzeez Sep 17, 2021
f0554d2
add fallback and bldr channel env vars to envrc and set back to dev w…
Sep 17, 2021
ae9d1f9
Script added for table 'org_users' (#5738)
sonali523 Sep 16, 2021
4f43167
added edit policy
iamazzeez Sep 17, 2021
5c9a0d1
Storage functions for users table (#5731)
sonali523 Sep 17, 2021
543dc60
Chaitali/add server slider (#5728)
chaitali-mane Sep 17, 2021
c75dfde
environments create, delete policy added
iamazzeez Sep 17, 2021
a73aea5
edit env policy added
iamazzeez Sep 20, 2021
3f047d0
added data bags policy
iamazzeez Sep 20, 2021
4b65226
Chaitali/add server slider (#5728)
chaitali-mane Sep 17, 2021
10adf5f
ui three dots fix
iamazzeez Sep 20, 2021
a7b783c
reverted iam actions
iamazzeez Sep 21, 2021
10b76d2
Add changes for the create server slider (#5755)
vinay033 Sep 20, 2021
19df623
removed roles iam
iamazzeez Sep 21, 2021
c12aff2
environments authz reverted
iamazzeez Sep 21, 2021
d1c56af
databags authz reverted
iamazzeez Sep 21, 2021
0c6f190
Added API to get server users list from backend DB (#5760)
sonali523 Sep 21, 2021
8c95dc8
Added users tab in server details page (#5802)
chaitali-mane Sep 28, 2021
ad97024
Added css change for notification overlap slider. (#5781)
himanshi-chhabra Sep 28, 2021
4d874d1
Command to add the sample automate infra server users (#5786)
sonali523 Sep 29, 2021
817ad59
Renaming the sql files and modifying to incorporate WebUI key
kalroy Nov 25, 2021
45a9573
infra_server_actions tests
iamazzeez Sep 28, 2021
31eb720
infra server list doc update
iamazzeez Sep 28, 2021
d7eee2d
test cases fix
iamazzeez Sep 28, 2021
e007327
lint fixes
iamazzeez Sep 28, 2021
1cdcb71
added infra server get test cases
iamazzeez Sep 28, 2021
a8a3863
create infra server test case
iamazzeez Sep 29, 2021
d9e63e1
added infra server create test case
iamazzeez Sep 29, 2021
981fa9b
updated docs
iamazzeez Sep 29, 2021
46f5b47
infra server put and delete test case added
iamazzeez Sep 29, 2021
fab62d6
wrapped server details into put api
iamazzeez Sep 29, 2021
bb2da83
wrapped delete button into delete action
iamazzeez Sep 29, 2021
340ed6b
error fix
iamazzeez Sep 29, 2021
3e3e399
cypress error fix
iamazzeez Sep 29, 2021
54b3ad0
doc formatted
iamazzeez Oct 1, 2021
32625f5
typo
iamazzeez Oct 6, 2021
0b53c21
Abdul/org actions (#5838)
iamazzeez Oct 5, 2021
8b33942
typo
iamazzeez Oct 6, 2021
7bbbbe2
Abdul/cookbooks actions (#5848)
iamazzeez Oct 7, 2021
5c67d1f
Abdul/roles actions (#5853)
iamazzeez Oct 13, 2021
a187f2a
Abdul/environments actions (#5898)
iamazzeez Oct 18, 2021
675b991
Abdul/databag item actions (#6049)
iamazzeez Nov 2, 2021
4975f79
lint fix
iamazzeez Nov 10, 2021
7291866
policyfiles actions added (#6081)
iamazzeez Nov 10, 2021
a73b310
added policygroups actions (#6123)
iamazzeez Nov 16, 2021
29b090c
infra_server_actions tests
iamazzeez Sep 28, 2021
e40e2ca
infra server list doc update
iamazzeez Sep 28, 2021
8a41273
test cases fix
iamazzeez Sep 28, 2021
229b96e
lint fixes
iamazzeez Sep 28, 2021
4e9f791
added infra server get test cases
iamazzeez Sep 28, 2021
bfe36f4
create infra server test case
iamazzeez Sep 29, 2021
51a7b50
added infra server create test case
iamazzeez Sep 29, 2021
5800319
updated docs
iamazzeez Sep 29, 2021
52ecc57
infra server put and delete test case added
iamazzeez Sep 29, 2021
97c97cf
cypress error fix
iamazzeez Sep 29, 2021
1ed82fb
doc formatted
iamazzeez Oct 1, 2021
a0fe143
typo
iamazzeez Oct 6, 2021
c8009f7
Abdul/cookbooks actions (#5848)
iamazzeez Oct 7, 2021
62521a4
Abdul/roles actions (#5853)
iamazzeez Oct 13, 2021
e8a6975
Abdul/environments actions (#5898)
iamazzeez Oct 18, 2021
144e4b1
rebase error fix
iamazzeez Nov 22, 2021
1c36187
rebase fix
iamazzeez Nov 22, 2021
a147421
rebase error fix
iamazzeez Nov 22, 2021
81c8c7c
iam permission to create, delete, get client (#6227)
iamazzeez Nov 29, 2021
0630a1b
added nodes iam actions (#6275)
iamazzeez Nov 29, 2021
5729bb8
infra_server_actions tests
iamazzeez Sep 28, 2021
7e46415
infra server list doc update
iamazzeez Sep 28, 2021
616b5bc
test cases fix
iamazzeez Sep 28, 2021
7150fed
lint fixes
iamazzeez Sep 28, 2021
59554b4
added infra server get test cases
iamazzeez Sep 28, 2021
3866503
create infra server test case
iamazzeez Sep 29, 2021
8858823
added infra server create test case
iamazzeez Sep 29, 2021
352051a
updated docs
iamazzeez Sep 29, 2021
8097436
infra server put and delete test case added
iamazzeez Sep 29, 2021
d603db4
wrapped delete button into delete action
iamazzeez Sep 29, 2021
fe96a5d
cypress error fix
iamazzeez Sep 29, 2021
8d99022
doc formatted
iamazzeez Oct 1, 2021
b453414
typo
iamazzeez Oct 6, 2021
e10b743
Abdul/cookbooks actions (#5848)
iamazzeez Oct 7, 2021
7b8b458
Abdul/roles actions (#5853)
iamazzeez Oct 13, 2021
f00e936
Abdul/environments actions (#5898)
iamazzeez Oct 18, 2021
0294395
Abdul/databag item actions (#6049)
iamazzeez Nov 2, 2021
2969f54
policyfiles actions added (#6081)
iamazzeez Nov 10, 2021
ef01cc1
added policygroups actions (#6123)
iamazzeez Nov 16, 2021
ec2b063
infra_server_actions tests
iamazzeez Sep 28, 2021
ba49e44
infra server list doc update
iamazzeez Sep 28, 2021
02efeef
test cases fix
iamazzeez Sep 28, 2021
306a603
lint fixes
iamazzeez Sep 28, 2021
7bb4905
added infra server get test cases
iamazzeez Sep 28, 2021
db7b88f
create infra server test case
iamazzeez Sep 29, 2021
83b60d0
added infra server create test case
iamazzeez Sep 29, 2021
ea284b5
updated docs
iamazzeez Sep 29, 2021
1c4e4f1
infra server put and delete test case added
iamazzeez Sep 29, 2021
c6af172
cypress error fix
iamazzeez Sep 29, 2021
2968333
doc formatted
iamazzeez Oct 1, 2021
857412c
typo
iamazzeez Oct 6, 2021
55af127
Abdul/cookbooks actions (#5848)
iamazzeez Oct 7, 2021
1c5754e
Abdul/roles actions (#5853)
iamazzeez Oct 13, 2021
1527f49
Abdul/databag item actions (#6049)
iamazzeez Nov 2, 2021
11e2107
policyfiles actions added (#6081)
iamazzeez Nov 10, 2021
1c10b45
added policygroups actions (#6123)
iamazzeez Nov 16, 2021
9502a8c
rebase fix
iamazzeez Nov 22, 2021
6cc0325
iam permission to create, delete, get client (#6227)
iamazzeez Nov 29, 2021
0c22276
added nodes iam actions (#6275)
iamazzeez Nov 29, 2021
3036b2c
added node test cases
iamazzeez Dec 1, 2021
ae5f068
docs fix
iamazzeez Dec 1, 2021
c6e976d
Added pb files after proto compilation to fix the panic error
sonali523 Dec 3, 2021
51dc1dc
api/external/infra_proxy/infra_proxy.pb.go
sonali523 Dec 8, 2021
43cd23c
added some minor changes
vinay033 Dec 9, 2021
5c51dd2
commented code
chaitali-mane Dec 9, 2021
c4963b9
database scripts added (#6351)
sonali523 Dec 13, 2021
10c05e2
WebUI key into add chef-server slider (#6357)
chaitali-mane Dec 14, 2021
b4cdd16
Create server API - create the chef server using the webui key (#6376)
vinay033 Dec 15, 2021
3efc2ea
API to validate the webui key (#6364)
vinay033 Dec 17, 2021
baed03b
Added Update web ui key slider (#6372)
chaitali-mane Dec 20, 2021
5852e03
UI-API integration for web UI key (#6387)
chaitali-mane Dec 22, 2021
cf2540c
Infra proxy API to get the organisation of chef server (#6363)
sonali523 Dec 22, 2021
2f37b4d
Server details page - UI should have the option to update the WebUI …
vinay033 Dec 24, 2021
f04337f
Show the validation status of the WebUI key on the Chef Server Metada…
vinay033 Dec 27, 2021
5c0993f
API to update the web ui key (#6433)
sonali523 Dec 28, 2021
9445da5
infra_viewer_actions added (#6436)
iamazzeez Dec 28, 2021
964bb41
Abdul/infra editor actions (#6453)
iamazzeez Dec 28, 2021
e2ec1b7
Changes to use web ui key in all the Infra Proxy APIs for Cookbooks, …
sonali523 Dec 29, 2021
eca1a1b
Database script for migration tables (#6500)
sonali523 Jan 5, 2022
4309076
Abdul/infra editor actions (#6508)
iamazzeez Jan 10, 2022
3444624
Abdul/infra project owner (#6512)
iamazzeez Jan 10, 2022
0f5b1ad
Changes from remote
Jan 11, 2022
cea6386
stash changes
Jan 10, 2022
2737de0
Changes for conflict
Jan 10, 2022
2b196f5
Changes for PR
Jan 11, 2022
5074ca2
Merge changes
Jan 11, 2022
1dce96b
Rebase changes
Jan 11, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockComponent } from 'ng2-mock-component';
import { ReactiveFormsModule, FormBuilder, Validators, FormGroup } from '@angular/forms';
import { UpdateWebUIKeySliderComponent } from './update-web-uikey-slider.component';
import { StoreModule, Store } from '@ngrx/store';
import { NgrxStateAtom, ngrxReducers, runtimeChecks } from 'app/ngrx.reducers';
import { HttpClient, HttpHandler } from '@angular/common/http';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { Regex } from 'app/helpers/auth/regex';
import { using } from 'app/testing/spec-helpers';
import { WebUIKey } from 'app/entities/servers/server.model';
import { UpdateWebUIKeyFailure, UpdateWebUIKeySuccess } from 'app/entities/servers/server.actions';
import { HttpStatus } from 'app/types/types';
import { HttpErrorResponse } from '@angular/common/http';

describe('UpdateWebUIKeySliderComponent', () => {
let component: UpdateWebUIKeySliderComponent;
let fixture: ComponentFixture<UpdateWebUIKeySliderComponent>;

let updateKeyForm: FormGroup;
let errors = {};

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
MockComponent({ selector: 'chef-button', inputs: ['disabled'] }),
MockComponent({ selector: 'chef-error' }),
MockComponent({ selector: 'chef-icon' }),
MockComponent({ selector: 'chef-form-field' }),
MockComponent({ selector: 'chef-loading-spinner' }),
UpdateWebUIKeySliderComponent
],
imports: [
ReactiveFormsModule,
StoreModule.forRoot(ngrxReducers, { runtimeChecks })
],
providers: [
HttpClient,
HttpHandler
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(UpdateWebUIKeySliderComponent);
component = fixture.componentInstance;
component.updateWebuiKeyForm = new FormBuilder().group({
webuikey: ['', [Validators.required, Validators.pattern(Regex.patterns.NON_BLANK),
Validators.pattern(Regex.patterns.NO_WILDCARD_ALLOW_HYPHEN)]]
});
updateKeyForm = component.updateWebuiKeyForm;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

describe('form validity', () => {
describe('the form should be invalid', () => {
it('when all inputs are empty', () => {
expect(updateKeyForm.valid).toBeFalsy();
});

it('when webuikey is missing', () => {

errors = updateKeyForm.controls['webuikey'].errors || {};

expect(updateKeyForm.valid).toBeFalsy();
expect(errors['required']).toBeTruthy();
});
});

describe('the form should be valid', () => {
it('when all inputs are filled and valid', () => {
expect(updateKeyForm.valid).toBeFalsy();
updateKeyForm.controls['webuikey'].setValue('WebUIKey');
expect(updateKeyForm.valid).toBeTruthy();
});

using([
['contains numbers range 0-9.', 'WebUIKey123'],
['contains alphabets a-z', 'WebUIKey-test'],
['contains underscore.', 'WebUIKey_test'],
['contains hyphen, minus, or dash.', 'WebUIKey_test-1'],
['has mixed characters', 'WebUIKey-Test_10']
], function (description: string, input: string) {
it(('when the webuikey ' + description), () => {

updateKeyForm.controls['webuikey'].setValue(input);
errors = updateKeyForm.controls['webuikey'].errors || {};

expect(updateKeyForm.valid).toBeTruthy();
expect(errors['pattern']).toBeFalsy();
});
});
});
});

describe('#webuikey', () => {
let store: Store<NgrxStateAtom>;
const webuikey: WebUIKey = {
id: 'test_server',
webui_key: 'test_webuikey'
};

beforeEach(() => {
store = TestBed.inject(Store);
});

it('render the UI Key Slider', () => {
component.slidePanel();
expect(component.isSlideOpen).toBe(true);
});

it('should be invalid when no fields are filled out', () => {
expect(component.updateWebuiKeyForm.valid).toBeFalsy();
});

it('should be valid when all fields are filled out', () => {
component.updateWebuiKeyForm.controls['webuikey'].setValue(webuikey.webui_key);
expect(component.updateWebuiKeyForm.valid).toBeTruthy();
});

it('hide slider after updating webuikey.', () => {
component.updateWebuiKeyForm.controls['webuikey'].setValue(webuikey.webui_key);
component.updateWebUIkey();

store.dispatch(new UpdateWebUIKeySuccess(webuikey));
});

it('on create , slider is closed with failure banner', () => {
component.updateWebuiKeyForm.controls['webuikey'].setValue(webuikey.webui_key);
component.updateWebUIkey();

const error = <HttpErrorResponse>{
status: HttpStatus.INTERNAL_SERVER_ERROR,
ok: false
};
store.dispatch(new UpdateWebUIKeyFailure(error));
expect(component.conflictError).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func serve(cmd *cobra.Command, args []string) {
}
authzClient := authz.NewAuthorizationServiceClient(authzConn)

authzProjectClient := authz.NewProjectsServiceClient(authzConn)

if cfg.SecretsAddress == "" {
fail(errors.New("missing required config secrets_address"))
}
Expand All @@ -97,7 +99,8 @@ func serve(cmd *cobra.Command, args []string) {
// get secrets client
secretsClient := secrets.NewSecretsServiceClient(secretsConn)

service, err := service.Start(l, migrationConfig, connFactory, secretsClient, authzClient)
service, err := service.Start(l, migrationConfig, connFactory, secretsClient, authzClient, authzProjectClient)

if err != nil {
fail(errors.Wrap(err, "could not initialize storage"))
}
Expand Down
4 changes: 3 additions & 1 deletion components/infra-proxy-service/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func ConfigFromViper(configFile string) (*service.Service, error) {
}
authzClient := authz.NewAuthorizationServiceClient(authzConn)

authzProjectClient := authz.NewProjectsServiceClient(authzConn)

if cfg.SecretsAddress == "" {
fail(errors.New("missing required config secrets_address"))
}
Expand All @@ -98,7 +100,7 @@ func ConfigFromViper(configFile string) (*service.Service, error) {
// gets secrets client
secretsClient := secrets.NewSecretsServiceClient(secretsConn)

service, err := service.Start(l, migrationConfig, connFactory, secretsClient, authzClient)
service, err := service.Start(l, migrationConfig, connFactory, secretsClient, authzClient, authzProjectClient)
if err != nil {
fail(errors.Wrap(err, "could not initialize storage"))
}
Expand Down
24 changes: 23 additions & 1 deletion components/infra-proxy-service/server/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/chef/automate/api/external/common/query"
secrets "github.com/chef/automate/api/external/secrets"
"github.com/chef/automate/api/interservice/authz"
"github.com/chef/automate/api/interservice/infra_proxy/request"
"github.com/chef/automate/api/interservice/infra_proxy/response"
"github.com/chef/automate/components/infra-proxy-service/service"
Expand Down Expand Up @@ -240,7 +241,11 @@ func (s *Server) GetInfraServerOrgs(ctx context.Context, req *request.GetInfraSe
// Save organisations in backend DB
orgs := []storage.Org{}
for key := range orgsList {
org, err := s.service.Storage.StoreOrg(ctx, key, key, "", "", req.ServerId, nil)
projects, err := createProjectFromOrgIdAndServerID(s, ctx, req.ServerId, key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will it create the policies too for the project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we are passing skip policies as false, therefore its creating project with all the policies.

if err != nil {
return nil, err
}
org, err := s.service.Storage.StoreOrg(ctx, key, key, "", "", req.ServerId, projects)
if err != nil {
return nil, service.ParseStorageError(err, *req, "org")
}
Expand Down Expand Up @@ -274,3 +279,20 @@ func fromStorageToListOrgs(sl []storage.Org) []*response.Org {

return tl
}

//function to create a new iam project for each client
func createProjectFromOrgIdAndServerID(s *Server, ctx context.Context, serverId string, orgId string) ([]string, error) {

newProject := &authz.CreateProjectReq{
Name: serverId + "_" + orgId,
Id: serverId + "_" + orgId,
SkipPolicies: false,
}

projectID, err := s.service.AuthzProject.CreateProject(ctx, newProject)
if err != nil {
return nil, err
}

return []string{projectID.Project.Name}, nil
}
20 changes: 11 additions & 9 deletions components/infra-proxy-service/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ import (

// Service holds the internal state and configuration of the Infra proxy service.
type Service struct {
Logger logger.Logger
ConnFactory *secureconn.Factory
Storage storage.Storage
Secrets secrets.SecretsServiceClient
Logger logger.Logger
ConnFactory *secureconn.Factory
Storage storage.Storage
Secrets secrets.SecretsServiceClient
AuthzProject authz.ProjectsServiceClient
}

// Start returns an instance of Service that connects to a postgres storage backend.
func Start(l logger.Logger, migrationsConfig migration.Config, connFactory *secureconn.Factory, secretsClient secrets.SecretsServiceClient,
authzClient authz.AuthorizationServiceClient) (*Service, error) {
authzClient authz.AuthorizationServiceClient, authzProjectClient authz.ProjectsServiceClient) (*Service, error) {
p, err := postgres.New(l, migrationsConfig, authzClient)
if err != nil {
return nil, err
}

return &Service{
Logger: l,
ConnFactory: connFactory,
Storage: p,
Secrets: secretsClient,
Logger: l,
ConnFactory: connFactory,
Storage: p,
Secrets: secretsClient,
AuthzProject: authzProjectClient,
}, nil
}

Expand Down
4 changes: 3 additions & 1 deletion components/infra-proxy-service/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func SetupInfraProxyService(ctx context.Context,

authzClient := authz.NewAuthorizationServiceClient(authzConn)

authzProjectClient := authz.NewProjectsServiceClient(authzConn)

secretsClient := secrets.NewMockSecretsServiceClient(gomock.NewController(t))

l, err := logger.NewLogger("text", "debug")
Expand All @@ -120,7 +122,7 @@ func SetupInfraProxyService(ctx context.Context,
migrationConfig, err := migrationConfigIfPGTestsToBeRun(l, "../storage/postgres/migration/sql")
require.NoError(t, err)

serviceRef, err := service.Start(l, *migrationConfig, connFactory, secretsClient, authzClient)
serviceRef, err := service.Start(l, *migrationConfig, connFactory, secretsClient, authzClient, authzProjectClient)

if err != nil {
t.Fatalf("could not create server: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ describe('Infra Viewer Policy', () => {
assert.equal(resp.status, 403);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('chef server details', () => {
cy.get('[data-cy=update-web-ui-key]').contains('Update').click();
cy.get('app-chef-server-details .sidenav-header').should('exist');
cy.get('[data-cy=enter-webui-key]').type(webuiKey);

cy.get('[data-cy=update-webui-key-button]').click();
cy.get('app-chef-server-details .sidenav-header').should('not.be.visible');
});
Expand Down