CheckFilterInput() public static méthode

Method checks to make sure that the filters defined are contained within the collection of valid filters defined
public static CheckFilterInput ( string inputName, List validFilters, List actualFilters ) : bool
inputName string friendly input name used to identify input when throwing exceptions
validFilters List List of strings identifying all valid filter names
actualFilters List collection of filters to test
Résultat bool
Exemple #1
0
        /// <summary>
        /// Private static method responsible for calling http client and performing get for all index calls
        /// </summary>
        /// <param name="filter">list of keyvaluepairs for filtering get request</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <param name="getHref">API href for GET to be performed on</param>
        /// <returns>Collection of Server objects</returns>
        private static List <Server> indexGet(List <Filter> filter, string view, string getHref)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default", "instance_detail"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "cloud_href", "deployment_href", "name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }
            queryString += string.Format("view={0}", view);

            return(GetObjectListByHref(getHref, queryString));
        }
        /// <summary>
        /// Lists deployments of the account.
        /// Using the available filters, one can select or group which deployments to retrieve. The 'inputs20' view is for retrieving inputs in 2.0 serialization
        /// </summary>
        /// <param name="filter">list of KeyValuePair(string,string) to use as filters to query for deployments</param>
        /// <param name="view">name of the view to be returned</param>
        /// <returns>collection of Deployment objects</returns>
        public static List <Deployment> index(List <Filter> filter, string view)
        {
            string getHref = APIHrefs.Deployment;

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default", "inputs", "inputs_2_0"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "name", "server_tag_scope"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryStringValue = string.Empty;

            queryStringValue += string.Format("view={0}&", view);
            queryStringValue += Utility.BuildFilterString(filter);

            string jsonString = Core.APIClient.Instance.Get(getHref, queryStringValue);

            return(deserializeList(jsonString));
        }
Exemple #3
0
        /// <summary>
        /// Lists ssh keys.
        /// </summary>
        /// <param name="cloudID">ID of cloud to query</param>
        /// <param name="filter">Set of filters to limit return data set</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>List of SSHKey objects</returns>
        public static List <SshKey> index(string cloudID, List <Filter> filter, string view)
        {
            view = validView(view);

            List <string> validFilters = new List <string>()
            {
                "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString += string.Format("view={0}", view);
            string getHref    = string.Format(APIHrefs.SshKey, cloudID);
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
        public static List <VolumeSnapshot> index(string cloudID, List <Filter> filter, string view)
        {
            //GET /api/clouds/:cloud_id/volumes/:volume_id/volume_snapshots
            //GET /api/clouds/:cloud_id/volume_snapshots

            string getHref     = string.Format(APIHrefs.VolumeSnapshots, cloudID);
            string queryString = string.Empty;

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "name", "parent_volume_href", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #5
0
        /// <summary>
        /// Private implementation to centrally manage all calls to index AlertSpecs
        /// </summary>
        /// <param name="getHref">RightScale API Href fragment for indexing AlertSpecs</param>
        /// <param name="filter">Filters for querying AlertSpecs</param>
        /// <param name="view">View name for querying AlertSpecs</param>
        /// <returns>collection of AlertSpecs</returns>
        private static List <AlertSpec> indexGet(string getHref, List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "escalation_name", "name", "subject_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = Utility.BuildFilterString(filter);

            if (!string.IsNullOrEmpty(view))
            {
                queryString += string.Format("view={0}", view);
            }

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #6
0
        public static List <InstanceCustomLodgement> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "timeframe"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            //TODO: implement InstanceCustomLodgement.index
            throw new NotImplementedException();
        }
        public static List <RecurringVolumeAttachment> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "runnable_href", "storage_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            //TODO: implement RecurringVolumeAttachment.index
            throw new NotImplementedException();
        }
        public static List <ServerTemplate> index(List <Filter> filter, string view)
        {
            string getUrl      = APIHrefs.ServerTemplate;
            string queryString = string.Empty;

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default", "inputs", "inputs_2_0"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "multi_cloud_image_href", "name", "revision"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string jsonString = Core.APIClient.Instance.Get(getUrl, queryString);

            return(deserializeList(jsonString));
        }
Exemple #9
0
        /// <summary>
        /// Lists instance types.
        /// </summary>
        /// <param name="cloudID">ID of the cloud to enumerate instance types for</param>
        /// <param name="filter">Collection of filters for limiting the return set</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>Collection of InstanceTypes</returns>
        public static List <InstanceType> index(string cloudID, List <Filter> filter, string view)
        {
            string getHref = string.Format(APIHrefs.InstanceType, cloudID);

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "cpu_architecture", "description", "name", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }
            queryString += string.Format("view={0}", view);
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
        private static List <MultiCloudImage> indexGet(List <Filter> filterList, string getUrl)
        {
            string queryString = string.Empty;

            List <string> validFilters = new List <string>()
            {
                "name", "description", "revision"
            };

            Utility.CheckFilterInput("filter", validFilters, filterList);

            if (filterList != null && filterList.Count > 0)
            {
                queryString += Utility.BuildFilterString(filterList) + "&";
            }

            string jsonString = Core.APIClient.Instance.Get(getUrl, queryString);

            return(deserializeList(jsonString));
        }
Exemple #11
0
        /// <summary>
        /// An IpAddress provides an abstraction for IPv4 addresses bindable to Instance resources running in a Cloud.
        /// </summary>
        /// <param name="cloudID">ID of the Cloud where IP addresses are to be retrieved from</param>
        /// <param name="filter">Set of filters for querying IP Addresses</param>
        /// <returns>Collection of IPAddress objects</returns>
        public static List <IPAddress> index(string cloudID, List <Filter> filter)
        {
            string getHref = string.Format("/api/clouds/{0}/ip_addresses", cloudID);

            List <string> validFilters = new List <string>()
            {
                "name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString = Utility.BuildFilterString(filter);
            }
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #12
0
        /// <summary>
        /// Lists all Datacenters for a particular cloud.
        /// </summary>
        /// <param name="cloudID">ID of cloud to enumerate DataCenters for</param>
        /// <param name="filter">Filter set to limit return data</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include.</param>
        /// <returns>Collection of DataCenter objects</returns>
        public static List <DataCenter> index(string cloudID, List <Filter> filter, string view)
        {
            string getHref = string.Format(APIHrefs.DataCenter, cloudID);

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "name", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            queryString += Utility.BuildFilterString(filter);

            if (!string.IsNullOrWhiteSpace(view))
            {
                queryString += string.Format("&view={0}", view);
            }

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            if (jsonString.ToLower().Contains("unsupported resource"))
            {
                throw new RightScaleAPIException("RightScale API Unsupported Exception", getHref + queryString, jsonString);
            }
            return(deserializeList(jsonString));
        }
Exemple #13
0
        /// <summary>
        /// Lists the enterprise ChildAccounts available for this Account.
        /// </summary>
        /// <param name="filter">Colletion of filters to limit return ste of API</param>
        /// <returns>Collection of ChildAccount objects</returns>
        public static List <ChildAccount> index(List <Filter> filter)
        {
            List <string> validFilters = new List <string>()
            {
                "name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.ChildAccount, queryString);

            return(deserializeList(jsonString));
        }
Exemple #14
0
        /// <summary>
        /// Lists the MultiCloudImageSettings for a MultiCloudImage
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage to query</param>
        /// <param name="filter">Set of filters for querying for MultiCloudImageSettings</param>
        /// <returns>List of MultiCloudImageSettings</returns>
        public static List <MultiCloudImageSetting> index(string multiCloudImageID, List <Filter> filter)
        {
            List <string> validFilters = new List <string>()
            {
                "cloud_href", "multi_cloud_image_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string getHref     = string.Format(APIHrefs.MultiCloudImageSettings, multiCloudImageID);
            string queryString = string.Empty;

            if (filter != null)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
        /// <summary>
        /// Lists Volume Types
        /// </summary>
        /// <param name="cloudID">ID of cloud where volume types are to be listed</param>
        /// <param name="filter">limites return set based on provided filter parameters</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>List of VolumeTypes</returns>
        public static List <VolumeType> index(string cloudID, List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "name", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Format("view={0}&", view);

            if (filter != null)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString = queryString.TrimEnd('&');

            string getHref    = string.Format(APIHrefs.VolumeType, cloudID);
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #16
0
        /// <summary>
        /// List the users available to the the account the user is logged in. Therefore, to list the users of a child account, the user has to login to the child account first.
        /// </summary>
        /// <param name="filter">Filters to limit the retun set</param>
        /// <returns>List of User objects belonging to the logged in account</returns>
        public static List <User> index(List <Filter> filter)
        {
            List <string> validFilters = new List <string>()
            {
                "email", "first_name", "last_name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryStringValue = string.Empty;

            if (filter != null)
            {
                foreach (Filter f in filter)
                {
                    queryStringValue += f.ToString() + "&";
                }
            }

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.User, queryStringValue);

            return(deserializeList(jsonString));
        }
        /// <summary>
        /// Lists the publications available to this account. Only non-HEAD revisions are possible.
        /// </summary>
        /// <param name="filter">List of filters to modify the return set from API</param>
        /// <param name="view">Specifies how many attributes and/or expanded nexted relationships to include.</param>
        /// <returns>List of RightScale publications</returns>
        public static List <Publication> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "name", "publisher", "revision"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString += string.Format("view={0}", view);

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.Publication, queryString);

            return(deserializeList(jsonString));
        }
Exemple #18
0
        /// Lists all of the backups with the given lineage tag. Filters can be used to search for a particular backup. If the 'latest_before' filter is set, only one backup is returned (the latest backup before the given timestamp).
        /// To get the latest completed backup, the 'completed' filter should be set to 'true' and the 'latest_before' filter should be set to the current timestamp. The format of the timestamp must be YYYY/MM/DD HH:MM:SS [+/-]ZZZZ e.g. 2011/07/11 00:00:00 +0000.
        /// To get the latest completed backup just before, say 25 June 2009, then the 'completed' filter should be set to 'true' and the 'latest_before' filter should be set to 2009/06/25 00:00:00 +0000.
        /// <param name="filter">Filters limiting the return set from the API</param>
        /// <param name="lineage">Backups belonging to this lineage</param>
        /// <returns>Collection of Backup objects</returns>
        public static List <Backup> index(List <Filter> filter, string lineage)
        {
            Utility.CheckStringHasValue(lineage);
            List <string> validFilters = new List <string>()
            {
                "cloud_href", "committed", "completed", "from_master", "latest_before"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }
            queryString += string.Format("lineage={0}", lineage);
            string jsonString = Core.APIClient.Instance.Get(APIHrefs.Backup, queryString);

            return(deserializeList(jsonString));
        }
Exemple #19
0
        /// <summary>
        /// Internal method to manage index get calls
        /// </summary>
        /// <param name="filter">Set of filters to limit the number of subnets returned</param>
        /// <param name="getHref">API href for rest call</param>
        /// <returns>list of subnets to return</returns>
        private static List <Subnet> indexGet(List <Filter> filter, string getHref)
        {
            List <string> validFilters = new List <string>()
            {
                "datacenter_href", "name", "resource_uid", "visibility"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #20
0
        /// <summary>
        /// Private method managing central process for getting list of VolumeAttachment classes
        /// </summary>
        /// <param name="getHref">API Href fragment for RSAPI call</param>
        /// <param name="filter">collection of filters for this request</param>
        /// <param name="view">View specified for this request</param>
        /// <returns>List of VolumeAttachmemt objects</returns>
        private static List <VolumeAttachment> indexGet(string getHref, List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "instance_href", "resource_uid", "volume_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString += string.Format("view={0}", view);

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #21
0
        /// <summary>
        /// Lists volumes in a specific cloud
        /// </summary>
        /// <param name="cloudID">ID of the cloud to query for volumes</param>
        /// <param name="filter">Set of filters limits which volumes are returned</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>Returns a list of volumes in a given cloud</returns>
        public static List <Volume> index(string cloudID, List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            List <string> validViews = new List <string>()
            {
                "default", "extended"
            };

            Utility.CheckStringInput("view", validViews, view);

            List <string> validFilters = new List <string>()
            {
                "datacenter_href", "description", "name", "parent_volume_snapshot_href", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string getHref = string.Format(APIHrefs.Volume, cloudID);

            string queryString = string.Empty;

            if (filter != null)
            {
                foreach (Filter f in filter)
                {
                    queryString += filter.ToString() + "&";
                }
                queryString += string.Format("view={0}", view);
            }

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #22
0
        /// <summary>
        /// Lists the ServerTemplateMultiCloudImages that are available to this account
        /// </summary>
        /// <param name="filter">Set of filters to limit return of query</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>List of ServerTemplateMultiCloudImage objects</returns>
        public static List <ServerTemplateMultiCloudImage> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "is_default", "multi_cloud_image_href", "server_template_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter) + "&";
            }

            queryString += string.Format("view={0}", view);

            string getHref    = APIHrefs.ServerTemplateMultiCloudImages;
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Exemple #23
0
        /// <summary>
        /// Lists the clouds available to this account
        /// </summary>
        /// <param name="filter">Filter limits results returned</param>
        /// <returns>List of clouds available to this account</returns>
        public static List <Cloud> index(List <Filter> filter)
        {
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                List <string> validFilters = new List <string>()
                {
                    "cloud_type", "description", "name"
                };
                Utility.CheckFilterInput("filter", validFilters, filter);

                foreach (var f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString = queryString.TrimEnd('&');

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.Cloud, queryString);

            return(Cloud.deserializeList(jsonString));
        }
Exemple #24
0
        /// <summary>
        /// List all permissions for all users of the current account
        /// </summary>
        /// <param name="filter">List of filters for query to RightScale API</param>
        /// <returns>List of Permission objects</returns>
        public static List <Permission> index(List <Filter> filter)
        {
            List <string> validFilters = new List <string>()
            {
                "user_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            queryString = queryString.TrimEnd('&');

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.Permission, queryString);

            return(deserializeList(jsonString));
        }
Exemple #25
0
        /// <summary>
        /// Lists the AccountGroups owned by this Account.
        /// </summary>
        /// <param name="filter">Set of filters to modify query to return AccountGroups from RightScale API</param>
        /// <param name="view">Defines specific view to limit the AccountGroups returned from RightScale API</param>
        /// <returns>Filtered list of AccuntGroups based on filter and view input</returns>
        public static List <AccountGroup> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string getUrl      = "/api/account_groups";
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }

            queryString += string.Format("view={0}", view);

            string jsonString = Core.APIClient.Instance.Get(getUrl, queryString);

            return(deserializeList(jsonString));
        }
Exemple #26
0
        /// <summary>
        /// Lists AuditEntries of the account. Due to the potentially large number of audit entries, a start and end date must be provided during an index call to limit the search. The format of the dates must be YYYY/MM/DD HH:MM:SS [+/-]ZZZZ e.g. 2011/07/11 00:00:00 +0000. A maximum of 1000 records will be returned by each index call.
        /// Using the available filters, one can select or group which audit entries to retrieve.
        /// </summary>
        /// <param name="filter">Filter parameters for index query</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include.</param>
        /// <param name="limit">Limit the audit entries to this number. The limit should >= 1 and <= 1000</param>
        /// <param name="start_date">The start date for retrieving audit entries</param>
        /// <param name="end_date">The end date for retrieving audit entries (the format must be the same as start date). The time period between start and end date must be less than 3 months (93 days).</param>
        /// <returns>Collection of AuditEntry objects from the start_time defined with a limit, filter and view as specified</returns>
        public static List <AuditEntry> index(List <Filter> filter, string view, string limit, DateTime start_date, DateTime end_date)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "auditee_href", "user_email"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            int intCheck;

            if (Int32.TryParse(limit, out intCheck))
            {
                if (intCheck >= 1 && intCheck <= 1000)
                {
                    //this is a good thing... should trace this out
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Input 'limit' was out of bounds.  Limit cannot be less than 1 or greater than 1000: value = " + limit);
                }
            }
            else
            {
                throw new ArgumentException("Input 'limit' was non-numeric: {" + limit + "}");
            }

            if (end_date.Subtract(start_date).Days > 93)
            {
                throw new ArgumentException(string.Format("The difference between the start date [{0}] and the end date [{1}] must not be greater than 93 days", start_date, end_date));
            }

            string timeOffset = DateTime.Now.ToString("%K").Replace(":", "");

            string startDateString = start_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;
            string endDateString   = end_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;

            List <KeyValuePair <string, string> > getParams = new List <KeyValuePair <string, string> >();

            getParams.Add(new KeyValuePair <string, string>("end_date", endDateString));
            getParams.Add(new KeyValuePair <string, string>("limit", limit));
            getParams.Add(new KeyValuePair <string, string>("start_date", startDateString));
            if (!string.IsNullOrWhiteSpace(view))
            {
                getParams.Add(new KeyValuePair <string, string>("view", view));
            }

            string queryString = Utility.BuildGetQueryString(getParams);

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }

            string jsonString = Core.APIClient.Instance.Get(APIHrefs.AuditEntry, queryString);

            return(deserializeList(jsonString));
        }
        /// <summary>
        /// Private method builds query string for index and show calls for MonitoringMetric requests
        /// </summary>
        /// <param name="filter">Set of filters to limit the set of MonitoringMetrics returned</param>
        /// <param name="period">The time scale for which the graph is generated. Default is 'day'</param>
        /// <param name="size">The size of the graph to be generated. Default is 'small'.</param>
        /// <param name="title">The title of the graph.</param>
        /// <param name="tz">The time zone in which the graph will be displayed. Default will be 'America/Los_Angeles'. For more zones, see User Settings -> Preferences.</param>
        /// <returns></returns>
        private static string getMonitoringMetricQueryString(List <Filter> filter, ref string period, ref string size, string title, ref string tz)
        {
            if (string.IsNullOrWhiteSpace(period))
            {
                period = "day";
            }
            else
            {
                List <string> validPeriods = new List <string>()
                {
                    "now", "day", "yday", "week", "lweek", "month", "quarter", "year"
                };
                Utility.CheckStringInput("period", validPeriods, period);
            }

            if (string.IsNullOrWhiteSpace(size))
            {
                size = "small";
            }
            else
            {
                List <string> validSizes = new List <string>()
                {
                    "thumb", "tiny", "small", "large", "xlarge"
                };
                Utility.CheckStringInput("size", validSizes, size);
            }

            if (string.IsNullOrWhiteSpace(tz))
            {
                tz = "America/Los_Angeles";
            }

            List <string> validFilters = new List <string>()
            {
                "plugin", "view"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }

            if (!string.IsNullOrWhiteSpace(period))
            {
                queryString += "period=" + period + "&";
            }
            if (!string.IsNullOrWhiteSpace(size))
            {
                queryString += "size=" + size + "&";
            }
            if (!string.IsNullOrWhiteSpace(title))
            {
                queryString += "title=" + title + "&";
            }
            if (!string.IsNullOrWhiteSpace(tz))
            {
                queryString += "tz=" + tz;
            }
            queryString = queryString.TrimEnd('&');
            return(queryString);
        }