# API For information about the supported Rancher APIs see [here](https://ranchermanager.docs.rancher.com/v2.8/api/quickstart) The Rancher UI contains functionality to manage Kubernetes resources. Developers can create, edit, fetch and remove individual resources or fetch collections of them. Resources that are fetched, by default, will be automatically updated via WebSocket In addition the Rancher UI exposes permissions functionality around resources which can determine if the signed in user can perform the various actions around them. # Resource Definitions ## Schemas Schemas are provided in bulk via Rancher and cached locally in the relevant store (`management`, `rancher`, etc). A schema can be fetched synchronously via store getter ```ts import { POD } from '@shell/config/types'; this.$store.getters['cluster/schemaFor'](POD)` ``` > Troubleshooting: Cannot find new schema > > Ensure that your schema text in `/config/types.js` is singular, not plural As mentioned before a schema dictates the functionality available to that type and what is shown for the type in the UI. A resource is an instance of a schema e.g. the `admin` user is an instance of type `management.cattle.io.user`. ## Types Each type has a Kubernetes API group and a name, but not necessarily a human-readable name. Types are used mainly for building side navigation and defining how the UI should build forms and list views for each resource. For more information about types and how to use them, there are helpful comments in `store/type-map.js`. # Vuex Stores There are 3 main stores for communicating with different parts of the Rancher API: - `management`: Points at global-level resources for Rancher as a whole. - `cluster`: Points at resources for the currently selected cluster; changes when you change clusters. - `rancher`: Points at older global-level resources, but some cluster-level resources are actually stored here and not physically in the cluster to be available to the `cluster` store. And then a bunch of others: | Name | For | | ----------- | ---------------------------------------------------------------------------------------------------------------- | | action-menu | Maintains the current selection for tables and handling bulk operations on them | | auth | Authentication, logging in and out, etc | | catalog | Stores the index data for Helm catalogs and methods to find charts, determine if upgrades are available, etc | | github | Part of authentication, communicating with the GitHub API | | growl | Global "growl" notifications in the corner of the screen | | i18n | Internationalization | | index | The root store, manages things like which cluster you're connected to and what namespaces should be shown | | prefs | User preferences | | type-map | Meta-information about all the k8s types that are available to the current user and how they should be displayed | | wm | "Window manager" at the bottom of the screen for things like container shells and logs. | Store objects are accessed in different ways, below are common ways they are referenced by models and components | Location | type | object | example | | ------------------------ | --------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------- | | `/model/` | Dispatching Actions | `this.$dispatch` | `this.$dispatch('cluster/find', { type: WORKLOAD_TYPES.JOB, id: relationship.toId }, { root: true })` | | `/model/` | Access getters (store type) | `this.$getters` | `this.$getters['schemaFor'](this.type)` | | `/model/` | Access getters (all) | `this.$rootGetters` | `this.$rootGetters['productId']` | | component | Dispatching Actions | `this.$store.dispatch` | ``this.$store.dispatch(`${ inStore }/find`, { type: row.type, id: row.id })`` | | component | Access getters | `this.$store.getters` | `this.$store.getters['rancher/byId'](NORMAN.PRINCIPAL, this.value)` | > Prefixing a property in a model with `$`, as per `model` rows above, results in calling properties on the store object directly. > Troubleshooting: Fetching the name of a resource type > > Good - Trims the text and respects `.` in path to type's string - `store.getters['type-map/labelFor']({ id: NORMAN.SPOOFED.GROUP_PRINCIPAL }, 2)` > > Bad - Does not trim text, issues when resource type contains "`.`" - ``store.getters['i18n/t'](`typeLabel.${ NORMAN.SPOOFED.GROUP_PRINCIPAL }`, { count: 2 })`` ## Checking User Permissions with Schemas Schemas dictate - Which resources are shown - What operations (create, update, delete, etc) can be made against resource/s - What actions (archive, change password, etc) can be made against resource/s In addition the resources themselves can dictate - What actions can be made against the collection The above, plus other factors, will effect what is shown by the UI - Resources in the cluster explorer - Edit resource buttons - Delete resource - etc The schema can be checked in the Rancher API at: ``` https:///create', )` | Creates a new Proxy object of the required type (`type` property must be included in the new object) | | `clone` | Clone | `$store.$dispatch('/clone', { resource: })` | Performs a deep clone and creates a proxy from it | | `findAll` | Fetch all of a resource type and watch for changes to the returned resources so that the list updates as it changes. | `$store.dispatch('/findAll', { type: })` | Fetches all resources of the given type. Also, when applicable, will register the type for automatic updates. If the type has already been fetched return the local cached list instead | | `find` | Fetch a resource by ID and watch for changes to that individual resource. | `$store.dispatch('/find', { type: , id: })` | Finds the resource matching the ID. If the type has already been fetched return the local cached instance. | | `findMatching` | Fetch resources by label and watch for changes to the returned resources, a live array that updates as it changes. | `$store.dispatch('/findMatching', { type: , selector: