summaryrefslogtreecommitdiffabout
path: root/src/sg-cl.opt
blob: 69e3fe72c5cfcb5abc861697291055c887ab1568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* This file is part of Eclat.
   Copyright (C) 2013-2014 Sergey Poznyakoff.
 
   Eclat is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
 
   Eclat is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with Eclat.  If not, see <http://www.gnu.org/licenses/>. */

ECLAT_CL_BEGIN([<modify ingress rules of a security group>],
	       [<[GROUPARG]>])

GROUP(Commands)	       
OPTION(add,A,,
       [<add rules>])
BEGIN
       command = "AuthorizeSecurityGroupIngress";
END

OPTION(delete,D,,
       [<delete rules>])
BEGIN
       command = "RevokeSecurityGroupIngress";
END

OPTION(list,L,,
       [<list rules>])
BEGIN
       list_option = 1;
       command = "DescribeSecurityGroups";
END       

GROUP(Rule constituents)

OPTION(protocol,p,[<PROTO>],
       [<IP protocol name or number>])
BEGIN
	proto = optarg;
END

OPTION(group-id,g,[<ID>],
       [<source group ID>])
BEGIN
	struct group_arg *g = grecs_malloc(sizeof(*g));
	translate_ids(1, &optarg, groupkw[GROUP_ID].map);
        g->type = GROUP_ID;
        g->str = optarg;
        g->usr = user;
        if (!group_list)
		group_list = _grecs_simple_list_create(1);
        grecs_list_append(group_list, g);
END

OPTION(group-name,G,[<NAME>],
       [<source group name>])
BEGIN
	struct group_arg *g = grecs_malloc(sizeof(*g));
	translate_ids(1, &optarg, groupkw[GROUP_NAME].map);
        g->type = GROUP_NAME;
        g->str = optarg;
        g->usr = user;
        if (!group_list)
		group_list = _grecs_simple_list_create(1);
        grecs_list_append(group_list, g);
END

OPTION(user,u,[<USER>],
       [<user name for the subsequent --group-name or --group-id option>])
BEGIN
	user = optarg;
END

OPTION(source,s,[<CIDR>],
       [<source CIDR>])
BEGIN
	if (!source_list)
		source_list = grecs_list_create();
        grecs_list_append(source_list, optarg);
END

OPTION(port,P,[<PORT[-PORT]>],
       [<destination port number or range>])
BEGIN
	char *p = strchr(optarg, '-');
        if (p) {
		*p++ = 0;
		to_port = p;
	} else
		to_port = optarg;
        from_port = optarg;
END

GROUP(Modifiers)
OPTION(name,n,,
       [<the GROUPARG argument is a group name>])
BEGIN
       dest_n = GROUP_NAME;
END

OPTION(next,N,,
       [<delimits rules>])
ALIAS(new)
BEGIN
	flush_rule();
END

ECLAT_CL_END

ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[]>],[<
{
	int idx;

	GETOPT(argc, argv, idx, exit(EX_USAGE))
	argc -= idx;
	argv += idx;

	if (!command)
		die(EX_USAGE, "either --list or --add or --delete must be given");
	if (list_option) { 
		if (rule_n > 1 || group_list || source_list ||
		    from_port || to_port)
			die(EX_USAGE, "conflicting options");
		if (argc > 1)
			die(EX_USAGE, "bad number of arguments");
	} else if (argc != 1)
		die(EX_USAGE, "bad number of arguments");
	translate_ids(argc, argv, groupkw[dest_n].map);

	eclat_query_add_param(env->query, "Action", command);
	if (list_option)
		describe_query_create(env, argc, argv, groupkw[dest_n].resid);
	else {
		if (group_list || source_list || from_port || to_port || proto)
			flush_rule();
		if (rule_n == 1)
			die(EX_USAGE, "no rules");

		eclat_query_add_param(query, groupkw[dest_n].resid, argv[0]);
	}
}>])

Return to:

Send suggestions and report system problems to the System administrator.