Skip to content

removal of creation of user owned context #202

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

Merged
merged 3 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const command = new Command({
.positional('name', {
describe: 'Name of context',
})
.option('owner', {
describe: 'Owner of the context',
choices: ['user', 'account'],
default: 'account',
})
.option('variable', {
describe: 'Variables list',
default: [],
Expand All @@ -39,7 +34,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const command = new Command({
.positional('name', {
describe: 'Name of context',
})
.option('owner', {
describe: 'Owner of the context',
choices: ['user', 'account'],
default: 'account',
})
.option('variable', {
describe: 'Variables list',
default: [],
Expand All @@ -39,7 +34,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const command = new Command({
.positional('name', {
describe: 'Name of context',
})
.option('owner', {
describe: 'Owner of the context',
choices: ['user', 'account'],
default: 'account',
})
.option('variable', {
describe: 'Variables list',
default: [],
Expand All @@ -38,7 +33,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
6 changes: 0 additions & 6 deletions lib/interface/cli/commands/context/create/createYaml.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const command = new Command({
.positional('name', {
describe: 'Name of context',
})
.option('owner', {
describe: 'Owner of the context',
choices: ['user', 'account'],
default: 'account',
})
.option('variable', {
describe: 'Variables list',
default: [],
Expand All @@ -38,7 +33,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,13 @@ const command = new Command({
describe: 'username that has permissions to use app password',
alias: 'u',
required: true,
})
.option('owner', {
describe: 'Owner of the context, user owned contexts cannot be accessible by other users across the account',
choices: ['account', 'user'],
alias: 'o',
default: 'account',
required: true,
});
return yargs;
},
handler: async (argv) => {
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner || 'account',
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const command = new Command({
alias: 't',
required: true,
})
.option('owner', {
describe: 'Owner of the context, user owned contexts cannot be accessible by other users across the account',
choices: ['account', 'user'],
alias: 'o',
default: 'account',
required: true,
})
.option('use-ssl', {
describe: 'Connect to the git host using ssl',
choices: [true, false],
Expand All @@ -54,7 +47,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner || 'account',
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const command = new Command({
alias: 't',
required: true,
})
.option('owner', {
describe: 'Owner of the context, user owned contexts cannot be accessible by other users across the account',
choices: ['account', 'user'],
alias: 'o',
default: 'account',
required: true,
})
.option('use-ssl', {
describe: 'Connect to the git host using ssl',
choices: [true, false],
Expand All @@ -54,7 +47,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner || 'account',
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,13 @@ const command = new Command({
alias: 's',
default: true,
required: true,
})
.option('owner', {
describe: 'Owner of the context, user owned contexts cannot be accessible by other users across the account',
choices: ['account', 'user'],
alias: 'o',
default: 'account',
required: true,
});
return yargs;
},
handler: async (argv) => {
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner || 'account',
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const command = new Command({
const data = {
apiVersion: 'v1',
kind: 'context',
owner: argv.owner,
metadata: {
name: argv.name,
},
Expand Down
3 changes: 1 addition & 2 deletions lib/interface/cli/commands/context/delete.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ const command = new Command({
},
handler: async (argv) => {
const name = argv.filename ? _.get(argv.filename, 'metadata.name') : argv.name;
const owner = argv.filename ? _.get(argv.filename, 'owner') : argv.owner;

if (!name) {
throw new CFError('Name must be provided');
}

await context.deleteContextByName(name, owner);
await context.deleteContextByName(name);
console.log(`Context: ${name} deleted`);
},
});
Expand Down
9 changes: 1 addition & 8 deletions lib/interface/cli/commands/context/get.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const command = new Command({
describe: 'Context type',
choices: ['config', 'secret', 'helm-repository', 'yaml', 'secret-yaml', 'git'],
})
.option('owner', {
describe: 'Owner of the context',
choices: ['user', 'account'],
})
.example('codefresh get context NAME', 'Get context NAME')
.example('codefresh get contexts', 'Get all contexts')
.example('codefresh get context --type secret', 'Get all secret contexts')
Expand All @@ -43,14 +39,11 @@ const command = new Command({
if (argv.type) {
data.type = argv.type;
}
if (argv.owner) {
data.owner = argv.owner;
}

let contexts = [];
if (!_.isEmpty(names)) {
for (const name of names) {
const currContext = await context.getContextByName(name, data.owner);
const currContext = await context.getContextByName(name);
contexts.push(currContext);
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/interface/cli/commands/root/delete.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const get = new Command({

switch (entity) {
case 'context':
const owner = data.owner;
await context.deleteContextByName(name, owner);
await context.deleteContextByName(name);
console.log(`Context: ${name} deleted`);
break;
case 'pipeline':
Expand Down
18 changes: 6 additions & 12 deletions lib/interface/functional/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ const TYPE_CHOICES = [
'plain-yaml',
'secret-yaml',
];
const OWNER_CHOICES = ['account', 'user'];

const getContext = async (name, owner = OWNER_CHOICES[0]) => {
const getContext = async (name) => {
if (!name) {
throw new CFError('Name must be provided');
}

try {
return context.getContextByName(name, owner);
return context.getContextByName(name);
} catch (err) {
throw new CFError({
cause: err,
Expand All @@ -35,14 +34,11 @@ const getContext = async (name, owner = OWNER_CHOICES[0]) => {
}
};

const getAllContexts = async (type = null, owner = OWNER_CHOICES[0]) => {
const getAllContexts = async (type = null) => {
const data = {};
if (type) {
data.type = type;
}
if (owner) {
data.owner = owner;
}

try {
return context.getContexts(data);
Expand All @@ -55,15 +51,14 @@ const getAllContexts = async (type = null, owner = OWNER_CHOICES[0]) => {
};


const createContext = async (name, type = null, owner = OWNER_CHOICES[0], envVarsDict = {}) => {
const createContext = async (name, type = null, envVarsDict = {}) => {
if (!name) {
throw new CFError('Name must be provided');
}

const data = {
apiVersion: 'v1',
kind: 'context',
owner,
metadata: {
name,
},
Expand All @@ -80,12 +75,12 @@ const createContext = async (name, type = null, owner = OWNER_CHOICES[0], envVar
return context.createContext(data);
};

const deleteContext = async (name, owner = OWNER_CHOICES[0]) => {
const deleteContext = async (name) => {
if (!name) {
throw new CFError('Name must be provided');
}

return context.deleteContextByName(name, owner);
return context.deleteContextByName(name);
};

const applyContext = async (name, data) => {
Expand Down Expand Up @@ -123,5 +118,4 @@ module.exports = {
replaceContext,

TYPE_CHOICES,
OWNER_CHOICES,
};
9 changes: 3 additions & 6 deletions lib/logic/api/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const _extractFieldsForContextEntity = context => ({
apiVersion: context.apiVersion,
kind: context.kind,
metadata: context.metadata,
owner: context.owner,
type: context.spec.type,
spec: context.spec,
});
Expand Down Expand Up @@ -47,11 +46,10 @@ const applyByName = async (name, data) => {
return sendHttpRequest(options);
};

const getContextByName = async (name, owner) => {
const getContextByName = async (name) => {
const options = {
url: `/api/contexts/${name}`,
method: 'GET',
qs: { owner },
};

const context = await sendHttpRequest(options);
Expand All @@ -63,7 +61,7 @@ const getContexts = async (info) => {
const userOptions = {
url: '/api/contexts',
method: 'GET',
qs: _.pick(info, 'owner', 'type'),
qs: _.pick(info, 'type'),
};

const result = await sendHttpRequest(userOptions);
Expand All @@ -77,11 +75,10 @@ const getContexts = async (info) => {
return contexts;
};

const deleteContextByName = async (name, owner) => {
const deleteContextByName = async (name) => {
const options = {
url: `/api/contexts/${name}`,
method: 'DELETE',
body: { owner },
};

return sendHttpRequest(options);
Expand Down
2 changes: 1 addition & 1 deletion lib/logic/entities/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Context extends Entity {
this.name = this.info.metadata.name;
this.type = this.info.type;
this.defaultColumns = ['name', 'type'];
this.wideColumns = this.defaultColumns.concat(['owner']);
this.wideColumns = this.defaultColumns || [];
}

// get the type of the context from spec.type
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.8.59",
"version": "0.8.60",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down