This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 354
Rewrite /capabilities to Go #3870
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d4ad7fd
Rewrote capabilities endpoints to GO
ocket8888 5068b25
Fixed incorrect parameter contraint
ocket8888 ad39fd5
Added godoc
ocket8888 b0d2294
Added support in the Go Client for capabilities
ocket8888 7da227f
Added API/client tests
ocket8888 e0e9e9a
Added Python client support
ocket8888 6939eb0
Updated docs
ocket8888 42ae23e
Added changelog updates
ocket8888 f47dea2
Traffic Portal changes to reflect deprecation
ocket8888 0786c0d
Fix API route definition for consistency
ocket8888 aef5700
Remove unnecessary debug line
ocket8888 9182cda
Use Fatalf when warranted
ocket8888 91e1d6a
Use API functions to write responses
ocket8888 3c1becf
fix compilation error
ocket8888 d61f28d
Switch URL building to use proper net/url encoding
ocket8888 c85c365
add db struct tags
ocket8888 d314d88
Add page/where/orderby/limit support
ocket8888 3af65e6
Removed new PUT/DELETE handlers
ocket8888 8a2b23a
Removed Python client methods for removed handlers
ocket8888 2df73e5
Fixed missing format arg
ocket8888 a571629
Added deprecation notice
ocket8888 f6d56ad
Updated documentation
ocket8888 166848c
Properly removed capabilities from withobjs
ocket8888 0e4b3c4
fixed teardown order
ocket8888 78e826e
setting up API capabilities
ocket8888 0c74ecf
Added missing capabilities
ocket8888 124543f
Added new static capabilities
ocket8888 8eba7e7
Removed premature deprecation notice in the docs
ocket8888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package tc | ||
|
|
||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| // Capability reflects the ability of a user in ATC to perform some operation. | ||
| // | ||
| // In practice, they are assigned to relevant Traffic Ops API endpoints - to describe the | ||
| // capabilites of said endpoint - and to user permission Roles - to describe the capabilities | ||
| // afforded by said Role. Note that enforcement of Capability-based permisions is not currently | ||
| // implemented. | ||
| type Capability struct { | ||
| Description string `json:"description" db:"description"` | ||
| LastUpdated TimeNoMod `json:"lastUpdated" db:"last_updated"` | ||
| Name string `json:"name" db:"name"` | ||
| } | ||
|
|
||
| // CapabilitiesResponse models the structure of a minimal response from the Capabilities API in | ||
| // Traffic Ops. | ||
| type CapabilitiesResponse struct { | ||
| Response []Capability `json:"response"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package client | ||
|
|
||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import "encoding/json" | ||
| import "errors" | ||
| import "net" | ||
| import "net/http" | ||
| import "net/url" | ||
|
|
||
| import "github.com/apache/trafficcontrol/lib/go-tc" | ||
|
|
||
| const API_v14_CAPABILITIES = "/api/1.4/capabilities" | ||
|
|
||
| // CreateCapability creates the passed capability. | ||
| func (to *Session) CreateCapability(c tc.Capability) (tc.Alerts, ReqInf, error) { | ||
| var remoteAddr net.Addr | ||
| reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} | ||
|
|
||
| reqBody, err := json.Marshal(c) | ||
| if err != nil { | ||
| return tc.Alerts{}, reqInf, err | ||
| } | ||
|
|
||
| resp, remoteAddr, err := to.request(http.MethodPost, API_v14_CAPABILITIES, reqBody) | ||
| if err != nil { | ||
| return tc.Alerts{}, reqInf, err | ||
| } | ||
| defer resp.Body.Close() | ||
| reqInf.RemoteAddr = remoteAddr | ||
|
|
||
| var alerts tc.Alerts | ||
| err = json.NewDecoder(resp.Body).Decode(&alerts) | ||
| return alerts, reqInf, err | ||
| } | ||
|
|
||
| // GetCapabilities retrieves all capabilities. | ||
| func (to *Session) GetCapabilities() ([]tc.Capability, ReqInf, error) { | ||
| resp, remoteAddr, err := to.request(http.MethodGet, API_v14_CAPABILITIES, nil) | ||
| reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} | ||
| if err != nil { | ||
| return nil, reqInf, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| var data tc.CapabilitiesResponse | ||
| err = json.NewDecoder(resp.Body).Decode(&data) | ||
| return data.Response, reqInf, err | ||
| } | ||
|
|
||
| // GetCapability retrieves only the capability named 'c' | ||
| func (to *Session) GetCapability(c string) (tc.Capability, ReqInf, error) { | ||
| var v url.Values | ||
| v.Add("name", c) | ||
| endpoint := API_v14_CAPABILITIES + "?" + v.Encode() | ||
| resp, remoteAddr, err := to.request(http.MethodGet, endpoint, nil) | ||
| reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr} | ||
| if err != nil { | ||
| return tc.Capability{}, reqInf, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| var data tc.CapabilitiesResponse | ||
| err = json.NewDecoder(resp.Body).Decode(&data) | ||
| if err != nil { | ||
| return tc.Capability{}, reqInf, err | ||
| } else if data.Response == nil || len(data.Response) < 1 { | ||
| return tc.Capability{}, reqInf, errors.New("Invalid response - no capability returned!") | ||
| } | ||
|
|
||
| return data.Response[0], reqInf, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.