Skip to content

Commit ec7effa

Browse files
authored
Merge branch 'main' into chore/coderabbit-triage-v0.2.6
2 parents ada475c + 8229beb commit ec7effa

87 files changed

Lines changed: 226 additions & 320 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/ambient-api-server/openapi/openapi.credentials.yaml

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
paths:
2-
# NEW ENDPOINT START
3-
/api/ambient/v1/projects/{id}/credentials:
4-
# NEW ENDPOINT END
2+
/api/ambient/v1/credentials:
53
get:
6-
summary: Returns a list of credentials in a project
4+
summary: Returns a list of credentials
75
security:
86
- Bearer: []
97
responses:
@@ -45,7 +43,7 @@ paths:
4543
type: string
4644
enum: [github, gitlab, jira, google, vertex, kubeconfig]
4745
post:
48-
summary: Create a new credential in a project
46+
summary: Create a new credential
4947
security:
5048
- Bearer: []
5149
requestBody:
@@ -92,11 +90,7 @@ paths:
9290
application/json:
9391
schema:
9492
$ref: 'openapi.yaml#/components/schemas/Error'
95-
parameters:
96-
- $ref: '#/components/parameters/id'
97-
# NEW ENDPOINT START
98-
/api/ambient/v1/projects/{id}/credentials/{cred_id}:
99-
# NEW ENDPOINT END
93+
/api/ambient/v1/credentials/{cred_id}:
10094
get:
10195
summary: Get a credential by id
10296
security:
@@ -218,11 +212,8 @@ paths:
218212
schema:
219213
$ref: 'openapi.yaml#/components/schemas/Error'
220214
parameters:
221-
- $ref: '#/components/parameters/id'
222215
- $ref: '#/components/parameters/cred_id'
223-
# NEW ENDPOINT START
224-
/api/ambient/v1/projects/{id}/credentials/{cred_id}/token:
225-
# NEW ENDPOINT END
216+
/api/ambient/v1/credentials/{cred_id}/token:
226217
get:
227218
summary: Get a decrypted token for a credential
228219
description: Returns the decrypted token value for the given credential. Requires token-reader role.
@@ -260,24 +251,17 @@ paths:
260251
schema:
261252
$ref: 'openapi.yaml#/components/schemas/Error'
262253
parameters:
263-
- $ref: '#/components/parameters/id'
264254
- $ref: '#/components/parameters/cred_id'
265255
components:
266256
schemas:
267-
# NEW SCHEMA START
268257
Credential:
269-
# NEW SCHEMA END
270258
allOf:
271259
- $ref: 'openapi.yaml#/components/schemas/ObjectReference'
272260
- type: object
273261
required:
274262
- name
275263
- provider
276-
- project_id
277264
properties:
278-
project_id:
279-
type: string
280-
description: ID of the project this credential belongs to
281265
name:
282266
type: string
283267
description:
@@ -297,9 +281,7 @@ components:
297281
type: string
298282
annotations:
299283
type: string
300-
# NEW SCHEMA START
301284
CredentialList:
302-
# NEW SCHEMA END
303285
allOf:
304286
- $ref: 'openapi.yaml#/components/schemas/List'
305287
- type: object
@@ -308,9 +290,7 @@ components:
308290
type: array
309291
items:
310292
$ref: '#/components/schemas/Credential'
311-
# NEW SCHEMA START
312293
CredentialPatchRequest:
313-
# NEW SCHEMA END
314294
type: object
315295
properties:
316296
name:
@@ -332,9 +312,7 @@ components:
332312
type: string
333313
annotations:
334314
type: string
335-
# NEW SCHEMA START
336315
CredentialTokenResponse:
337-
# NEW SCHEMA END
338316
type: object
339317
required:
340318
- credential_id
@@ -352,13 +330,6 @@ components:
352330
type: string
353331
description: Decrypted token value
354332
parameters:
355-
id:
356-
name: id
357-
in: path
358-
description: The id of the project
359-
required: true
360-
schema:
361-
type: string
362333
cred_id:
363334
name: cred_id
364335
in: path
@@ -446,7 +417,7 @@ components:
446417
Example: For each Subscription to get id, href, plan(id and kind) and labels (all fields)
447418
448419
```
449-
curl "/api/ambient/v1/sessions?fields=id,href,name,project_id"
420+
curl "/api/ambient/v1/sessions?fields=id,href,name"
450421
```
451422
schema:
452423
type: string

components/ambient-api-server/plugins/credentials/factory_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ func newCredential(name string) (*credentials.Credential, error) {
1212
credentialService := credentials.Service(&environments.Environment().Services)
1313

1414
credential := &credentials.Credential{
15-
ProjectID: "test-project",
1615
Name: name,
1716
Description: stringPtr("test-description"),
18-
Provider: "test-provider",
17+
Provider: "github",
1918
Token: stringPtr("test-token"),
2019
Url: stringPtr("test-url"),
2120
Email: stringPtr("test-email"),

components/ambient-api-server/plugins/credentials/handler.go

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package credentials
22

33
import (
4-
"fmt"
54
"net/http"
6-
"regexp"
75

86
"github.com/gorilla/mux"
97

@@ -14,8 +12,6 @@ import (
1412
"github.com/openshift-online/rh-trex-ai/pkg/services"
1513
)
1614

17-
var safeProjectIDPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
18-
1915
var _ handlers.RestHandler = credentialHandler{}
2016

2117
type credentialHandler struct {
@@ -39,8 +35,7 @@ func (h credentialHandler) Create(w http.ResponseWriter, r *http.Request) {
3935
},
4036
Action: func() (interface{}, *errors.ServiceError) {
4137
ctx := r.Context()
42-
projectID := mux.Vars(r)["id"]
43-
credentialModel := ConvertCredential(credential, projectID)
38+
credentialModel := ConvertCredential(credential)
4439
credentialModel, err := h.credential.Create(ctx, credentialModel)
4540
if err != nil {
4641
return nil, err
@@ -61,15 +56,11 @@ func (h credentialHandler) Patch(w http.ResponseWriter, r *http.Request) {
6156
Validators: []handlers.Validate{},
6257
Action: func() (interface{}, *errors.ServiceError) {
6358
ctx := r.Context()
64-
projectID := mux.Vars(r)["id"]
6559
id := mux.Vars(r)["cred_id"]
6660
found, err := h.credential.Get(ctx, id)
6761
if err != nil {
6862
return nil, err
6963
}
70-
if found.ProjectID != projectID {
71-
return nil, errors.NotFound("credential with id='%s' not found", id)
72-
}
7364

7465
if patch.Name != nil {
7566
found.Name = *patch.Name
@@ -112,18 +103,7 @@ func (h credentialHandler) List(w http.ResponseWriter, r *http.Request) {
112103
cfg := &handlers.HandlerConfig{
113104
Action: func() (interface{}, *errors.ServiceError) {
114105
ctx := r.Context()
115-
projectID := mux.Vars(r)["id"]
116-
if !safeProjectIDPattern.MatchString(projectID) {
117-
return nil, errors.Validation("invalid project ID format")
118-
}
119-
120106
listArgs := services.NewListArguments(r.URL.Query())
121-
projectFilter := fmt.Sprintf("project_id = '%s'", projectID)
122-
if listArgs.Search != "" {
123-
listArgs.Search = fmt.Sprintf("(%s) and %s", listArgs.Search, projectFilter)
124-
} else {
125-
listArgs.Search = projectFilter
126-
}
127107
var credentials []Credential
128108
paging, err := h.generic.List(ctx, "id", listArgs, &credentials)
129109
if err != nil {
@@ -158,16 +138,12 @@ func (h credentialHandler) List(w http.ResponseWriter, r *http.Request) {
158138
func (h credentialHandler) Get(w http.ResponseWriter, r *http.Request) {
159139
cfg := &handlers.HandlerConfig{
160140
Action: func() (interface{}, *errors.ServiceError) {
161-
projectID := mux.Vars(r)["id"]
162141
id := mux.Vars(r)["cred_id"]
163142
ctx := r.Context()
164143
credential, err := h.credential.Get(ctx, id)
165144
if err != nil {
166145
return nil, err
167146
}
168-
if credential.ProjectID != projectID {
169-
return nil, errors.NotFound("credential with id='%s' not found", id)
170-
}
171147

172148
return PresentCredential(credential), nil
173149
},
@@ -179,17 +155,9 @@ func (h credentialHandler) Get(w http.ResponseWriter, r *http.Request) {
179155
func (h credentialHandler) Delete(w http.ResponseWriter, r *http.Request) {
180156
cfg := &handlers.HandlerConfig{
181157
Action: func() (interface{}, *errors.ServiceError) {
182-
projectID := mux.Vars(r)["id"]
183158
id := mux.Vars(r)["cred_id"]
184159
ctx := r.Context()
185-
found, err := h.credential.Get(ctx, id)
186-
if err != nil {
187-
return nil, err
188-
}
189-
if found.ProjectID != projectID {
190-
return nil, errors.NotFound("credential with id='%s' not found", id)
191-
}
192-
err = h.credential.Delete(ctx, id)
160+
err := h.credential.Delete(ctx, id)
193161
if err != nil {
194162
return nil, err
195163
}
@@ -202,16 +170,12 @@ func (h credentialHandler) Delete(w http.ResponseWriter, r *http.Request) {
202170
func (h credentialHandler) GetToken(w http.ResponseWriter, r *http.Request) {
203171
cfg := &handlers.HandlerConfig{
204172
Action: func() (interface{}, *errors.ServiceError) {
205-
projectID := mux.Vars(r)["id"]
206173
id := mux.Vars(r)["cred_id"]
207174
ctx := r.Context()
208175
credential, err := h.credential.Get(ctx, id)
209176
if err != nil {
210177
return nil, err
211178
}
212-
if credential.ProjectID != projectID {
213-
return nil, errors.NotFound("credential with id='%s' not found", id)
214-
}
215179

216180
return PresentCredentialToken(credential), nil
217181
},

components/ambient-api-server/plugins/credentials/migration.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func addProjectIDMigration() *gormigrate.Migration {
3838
return &gormigrate.Migration{
3939
ID: "202604101200",
4040
Migrate: func(tx *gorm.DB) error {
41-
return tx.Exec("ALTER TABLE credentials ADD COLUMN IF NOT EXISTS project_id TEXT NOT NULL DEFAULT ''").Error
41+
return tx.Exec("ALTER TABLE IF EXISTS credentials ADD COLUMN IF NOT EXISTS project_id TEXT NOT NULL DEFAULT ''").Error
4242
},
4343
Rollback: func(tx *gorm.DB) error {
44-
return tx.Exec("ALTER TABLE credentials DROP COLUMN IF EXISTS project_id").Error
44+
return tx.Exec("ALTER TABLE IF EXISTS credentials DROP COLUMN IF EXISTS project_id").Error
4545
},
4646
}
4747
}
@@ -105,3 +105,15 @@ func rolesMigration() *gormigrate.Migration {
105105
},
106106
}
107107
}
108+
109+
func dropProjectIDMigration() *gormigrate.Migration {
110+
return &gormigrate.Migration{
111+
ID: "202505120001",
112+
Migrate: func(tx *gorm.DB) error {
113+
return tx.Exec(`ALTER TABLE IF EXISTS credentials DROP COLUMN IF EXISTS project_id`).Error
114+
},
115+
Rollback: func(tx *gorm.DB) error {
116+
return tx.Exec(`ALTER TABLE IF EXISTS credentials ADD COLUMN IF NOT EXISTS project_id TEXT NOT NULL DEFAULT ''`).Error
117+
},
118+
}
119+
}

components/ambient-api-server/plugins/credentials/model.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
type Credential struct {
99
api.Meta
10-
ProjectID string `json:"project_id"`
1110
Name string `json:"name"`
1211
Description *string `json:"description"`
1312
Provider string `json:"provider"`

components/ambient-api-server/plugins/credentials/plugin.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ func init() {
5252
}
5353
credentialHandler := NewCredentialHandler(Service(envServices), generic.Service(envServices))
5454

55-
credentialsRouter := apiV1Router.PathPrefix("/projects").Subrouter()
56-
credentialsRouter.HandleFunc("/{id}/credentials", credentialHandler.List).Methods(http.MethodGet)
57-
credentialsRouter.HandleFunc("/{id}/credentials", credentialHandler.Create).Methods(http.MethodPost)
58-
credentialsRouter.HandleFunc("/{id}/credentials/{cred_id}", credentialHandler.Get).Methods(http.MethodGet)
59-
credentialsRouter.HandleFunc("/{id}/credentials/{cred_id}", credentialHandler.Patch).Methods(http.MethodPatch)
60-
credentialsRouter.HandleFunc("/{id}/credentials/{cred_id}", credentialHandler.Delete).Methods(http.MethodDelete)
61-
credentialsRouter.HandleFunc("/{id}/credentials/{cred_id}/token", credentialHandler.GetToken).Methods(http.MethodGet)
55+
credentialsRouter := apiV1Router.PathPrefix("/credentials").Subrouter()
56+
credentialsRouter.HandleFunc("", credentialHandler.List).Methods(http.MethodGet)
57+
credentialsRouter.HandleFunc("", credentialHandler.Create).Methods(http.MethodPost)
58+
credentialsRouter.HandleFunc("/{cred_id}", credentialHandler.Get).Methods(http.MethodGet)
59+
credentialsRouter.HandleFunc("/{cred_id}", credentialHandler.Patch).Methods(http.MethodPatch)
60+
credentialsRouter.HandleFunc("/{cred_id}", credentialHandler.Delete).Methods(http.MethodDelete)
61+
credentialsRouter.HandleFunc("/{cred_id}/token", credentialHandler.GetToken).Methods(http.MethodGet)
6262
credentialsRouter.Use(authMiddleware.AuthenticateAccountJWT)
6363
credentialsRouter.Use(authzMiddleware.AuthorizeApi)
6464
})
@@ -85,4 +85,5 @@ func init() {
8585
db.RegisterMigration(rolesMigration())
8686
db.RegisterMigration(addProjectIDMigration())
8787
db.RegisterMigration(removeCredentialReaderRoleMigration())
88+
db.RegisterMigration(dropProjectIDMigration())
8889
}

components/ambient-api-server/plugins/credentials/presenter.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import (
77
"github.com/openshift-online/rh-trex-ai/pkg/util"
88
)
99

10-
func ConvertCredential(credential openapi.Credential, projectID string) *Credential {
10+
func ConvertCredential(credential openapi.Credential) *Credential {
1111
c := &Credential{
1212
Meta: api.Meta{
1313
ID: util.NilToEmptyString(credential.Id),
1414
},
15-
ProjectID: projectID,
1615
}
1716
c.Name = credential.Name
1817
c.Description = credential.Description
@@ -41,7 +40,6 @@ func PresentCredential(credential *Credential) openapi.Credential {
4140
Href: reference.Href,
4241
CreatedAt: openapi.PtrTime(credential.CreatedAt),
4342
UpdatedAt: openapi.PtrTime(credential.UpdatedAt),
44-
ProjectId: credential.ProjectID,
4543
Name: credential.Name,
4644
Description: credential.Description,
4745
Provider: credential.Provider,

components/ambient-sdk/go-sdk/client/agent_api.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ambient-sdk/go-sdk/client/client.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)