aboutsummaryrefslogtreecommitdiff
path: root/src/lssattr.c
blob: 66ed07fdecc85a3b05f7bdcf95b514affcf6972c (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
148
149
150
151
152
153
154
155
156
157
158
159
/* This file is part of Eclat.
   Copyright (C) 2012-2015 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/>. */

#include "eclat.h"

static char *attrs[] = {
	"createVolumePermission",
	"productCodes",
	NULL
};

int
eclat_describe_snapshot_attribute(eclat_command_env_t *env,
				  int argc, char **argv)
{
	int i;
	struct ec2_request *q = env->request;
	const char *attrname;
	
	generic_proginfo->args_doc = "SNAP-ID [ATTR]";
	available_attrs = attrs;
	generic_proginfo->print_help_hook = list_attrs;
	generic_parse_options(env->cmd,
			      "describe the attribute of a snapshot",
			      argc, argv, &i);
	argv += i;
	argc -= i;

	switch (argc) {
	default:
		die(EX_USAGE, "wrong number of arguments");
	case 2:
		attrname = canonattrname(attrs, argv[1], NULL, NULL);
		if (!attrname)
			die(EX_USAGE, "unrecognized attribute name");
		break;
	case 1:
		attrname = attrs[0];
	}
		
	translate_ids(1, argv, MAP_SNAPSHOT);
	eclat_request_add_param(q, "SnapshotId", argv[0]);
	eclat_request_add_param(q, "Attribute", attrname);
	return 0;
}

static void
remdash(char *p)
{
	char *q;

	q = p + strspn(p, "0123456789-");
	if (*q)
		die(EX_USAGE, "invalid account ID: %s; stopped near %s",
		    p, q);
	for (q = p;; p++) {
		if (*p == '-')
			continue;
		if (!(*q++ = *p))
			break;
	}
}

int
eclat_modify_snapshot_attribute(eclat_command_env_t *env,
				int argc, char **argv)
{
	int i;
	struct ec2_request *q = env->request;
	char *bufptr = NULL;
	size_t bufsize = 0;
	
	generic_proginfo->args_doc = "{g|u}{-|+}{all|ID} SNAP-ID";
	generic_parse_options(env->cmd,
			      "modify the createVolumePermission attribute of a snapshot",
			      argc, argv, &i);
	argv += i;
	argc -= i;

	if (argc < 2)
		die(EX_USAGE, "wrong number of arguments");
	for (i = 0; i < argc - 1; i++) {
		const char *action, *what;

		switch (argv[i][0]) {
		case 'u':
			what = "UserId";
			break;
		case 'g':
			what = "Group";
			break;
		default:
			die(EX_USAGE, "malformed argument: %s", argv[i]);
		}

		switch (argv[i][1]) {
		case '+':
			action = "Add";
			break;
		case '-':
			action = "Remove";
			break;
		default:
			die(EX_USAGE, "malformed argument: %s", argv[i]);
		}
		
		grecs_asprintf(&bufptr, &bufsize,
			       "CreateVolumePermission.%s.%d.%s", action,
			       i + 1, what);

		if (argv[i][0] == 'u')
			remdash(argv[i] + 2);
		eclat_request_add_param(q, bufptr, argv[i] + 2);
	}
	free(bufptr);
	
	translate_ids(1, argv + i, MAP_SNAPSHOT);
	eclat_request_add_param(q, "SnapshotId", argv[i]);
	
	return 0;
}

int
eclat_reset_snapshot_attribute(eclat_command_env_t *env,
			       int argc, char **argv)
{
	int i;
	struct ec2_request *q = env->request;
	
	generic_proginfo->args_doc = "SNAP-ID";
	generic_parse_options(env->cmd,
			      "reset the createVolumePermission attribute of a snapshot",
			      argc, argv, &i);
	argv += i;
	argc -= i;

	if (argc != 1)
		die(EX_USAGE, "wrong number of arguments");
	
	translate_ids(1, argv, MAP_SNAPSHOT);
	eclat_request_add_param(q, "SnapshotId", argv[0]);
	eclat_request_add_param(q, "Attribute", "CreateVolumePermission");

	return 0;
}
	

Return to:

Send suggestions and report system problems to the System administrator.