@@ -186,6 +186,38 @@ func (enum *ListGroupsRequestOrderBy) UnmarshalJSON(data []byte) error {
186186 return nil
187187}
188188
189+ type ListJWTsRequestOrderBy string
190+
191+ const (
192+ ListJWTsRequestOrderByCreatedAtAsc = ListJWTsRequestOrderBy ("created_at_asc" )
193+ ListJWTsRequestOrderByCreatedAtDesc = ListJWTsRequestOrderBy ("created_at_desc" )
194+ ListJWTsRequestOrderByUpdatedAtAsc = ListJWTsRequestOrderBy ("updated_at_asc" )
195+ ListJWTsRequestOrderByUpdatedAtDesc = ListJWTsRequestOrderBy ("updated_at_desc" )
196+ )
197+
198+ func (enum ListJWTsRequestOrderBy ) String () string {
199+ if enum == "" {
200+ // return default value if empty
201+ return "created_at_asc"
202+ }
203+ return string (enum )
204+ }
205+
206+ func (enum ListJWTsRequestOrderBy ) MarshalJSON () ([]byte , error ) {
207+ return []byte (fmt .Sprintf (`"%s"` , enum )), nil
208+ }
209+
210+ func (enum * ListJWTsRequestOrderBy ) UnmarshalJSON (data []byte ) error {
211+ tmp := ""
212+
213+ if err := json .Unmarshal (data , & tmp ); err != nil {
214+ return err
215+ }
216+
217+ * enum = ListJWTsRequestOrderBy (ListJWTsRequestOrderBy (tmp ).String ())
218+ return nil
219+ }
220+
189221type ListPermissionSetsRequestOrderBy string
190222
191223const (
@@ -512,6 +544,26 @@ type Group struct {
512544 ApplicationIDs []string `json:"application_ids"`
513545}
514546
547+ // JWT: jwt.
548+ type JWT struct {
549+ // Jti: jWT ID.
550+ Jti string `json:"jti"`
551+ // IssuerID: ID of the user who issued the JWT.
552+ IssuerID string `json:"issuer_id"`
553+ // AudienceID: ID of the user targeted by the JWT.
554+ AudienceID string `json:"audience_id"`
555+ // CreatedAt: creation date of the JWT.
556+ CreatedAt * time.Time `json:"created_at"`
557+ // UpdatedAt: last update date of the JWT.
558+ UpdatedAt * time.Time `json:"updated_at"`
559+ // ExpiresAt: expiration date of the JWT.
560+ ExpiresAt * time.Time `json:"expires_at"`
561+ // IP: IP address used during the creation of the JWT.
562+ IP net.IP `json:"ip"`
563+ // UserAgent: user-agent used during the creation of the JWT.
564+ UserAgent string `json:"user_agent"`
565+ }
566+
515567// ListAPIKeysResponse: list api keys response.
516568type ListAPIKeysResponse struct {
517569 // APIKeys: list of API keys.
@@ -536,6 +588,12 @@ type ListGroupsResponse struct {
536588 TotalCount uint32 `json:"total_count"`
537589}
538590
591+ type ListJWTsResponse struct {
592+ Jwts []* JWT `json:"jwts"`
593+
594+ TotalCount uint64 `json:"total_count"`
595+ }
596+
539597// ListPermissionSetsResponse: list permission sets response.
540598type ListPermissionSetsResponse struct {
541599 // PermissionSets: list of permission sets.
@@ -2177,6 +2235,108 @@ func (s *API) GetQuotum(req *GetQuotumRequest, opts ...scw.RequestOption) (*Quot
21772235 return & resp , nil
21782236}
21792237
2238+ type ListJWTsRequest struct {
2239+ // OrderBy: criteria for sorting results.
2240+ // Default value: created_at_asc
2241+ OrderBy ListJWTsRequestOrderBy `json:"-"`
2242+ // AudienceID: ID of the user to search.
2243+ AudienceID * string `json:"-"`
2244+ // PageSize: number of results per page. Value must be between 1 and 100.
2245+ // Default value: 20
2246+ PageSize * uint32 `json:"-"`
2247+ // Page: number of page. Value must be greater to 1.
2248+ // Default value: 1
2249+ Page * int32 `json:"-"`
2250+ // Expired: filter out expired JWTs or not.
2251+ Expired * bool `json:"-"`
2252+ }
2253+
2254+ // ListJWTs: list JWTs.
2255+ func (s * API ) ListJWTs (req * ListJWTsRequest , opts ... scw.RequestOption ) (* ListJWTsResponse , error ) {
2256+ var err error
2257+
2258+ defaultPageSize , exist := s .client .GetDefaultPageSize ()
2259+ if (req .PageSize == nil || * req .PageSize == 0 ) && exist {
2260+ req .PageSize = & defaultPageSize
2261+ }
2262+
2263+ query := url.Values {}
2264+ parameter .AddToQuery (query , "order_by" , req .OrderBy )
2265+ parameter .AddToQuery (query , "audience_id" , req .AudienceID )
2266+ parameter .AddToQuery (query , "page_size" , req .PageSize )
2267+ parameter .AddToQuery (query , "page" , req .Page )
2268+ parameter .AddToQuery (query , "expired" , req .Expired )
2269+
2270+ scwReq := & scw.ScalewayRequest {
2271+ Method : "GET" ,
2272+ Path : "/iam/v1alpha1/jwts" ,
2273+ Query : query ,
2274+ Headers : http.Header {},
2275+ }
2276+
2277+ var resp ListJWTsResponse
2278+
2279+ err = s .client .Do (scwReq , & resp , opts ... )
2280+ if err != nil {
2281+ return nil , err
2282+ }
2283+ return & resp , nil
2284+ }
2285+
2286+ type GetJWTRequest struct {
2287+ // Jti: jWT ID of the JWT to get.
2288+ Jti string `json:"-"`
2289+ }
2290+
2291+ // GetJWT: get a JWT.
2292+ func (s * API ) GetJWT (req * GetJWTRequest , opts ... scw.RequestOption ) (* JWT , error ) {
2293+ var err error
2294+
2295+ if fmt .Sprint (req .Jti ) == "" {
2296+ return nil , errors .New ("field Jti cannot be empty in request" )
2297+ }
2298+
2299+ scwReq := & scw.ScalewayRequest {
2300+ Method : "GET" ,
2301+ Path : "/iam/v1alpha1/jwts/" + fmt .Sprint (req .Jti ) + "" ,
2302+ Headers : http.Header {},
2303+ }
2304+
2305+ var resp JWT
2306+
2307+ err = s .client .Do (scwReq , & resp , opts ... )
2308+ if err != nil {
2309+ return nil , err
2310+ }
2311+ return & resp , nil
2312+ }
2313+
2314+ type DeleteJWTRequest struct {
2315+ // Jti: jWT ID of the JWT to delete.
2316+ Jti string `json:"-"`
2317+ }
2318+
2319+ // DeleteJWT: delete a JWT.
2320+ func (s * API ) DeleteJWT (req * DeleteJWTRequest , opts ... scw.RequestOption ) error {
2321+ var err error
2322+
2323+ if fmt .Sprint (req .Jti ) == "" {
2324+ return errors .New ("field Jti cannot be empty in request" )
2325+ }
2326+
2327+ scwReq := & scw.ScalewayRequest {
2328+ Method : "DELETE" ,
2329+ Path : "/iam/v1alpha1/jwts/" + fmt .Sprint (req .Jti ) + "" ,
2330+ Headers : http.Header {},
2331+ }
2332+
2333+ err = s .client .Do (scwReq , nil , opts ... )
2334+ if err != nil {
2335+ return err
2336+ }
2337+ return nil
2338+ }
2339+
21802340// UnsafeGetTotalCount should not be used
21812341// Internal usage only
21822342func (r * ListSSHKeysResponse ) UnsafeGetTotalCount () uint32 {
@@ -2347,3 +2507,22 @@ func (r *ListQuotaResponse) UnsafeAppend(res interface{}) (uint64, error) {
23472507 r .TotalCount += uint64 (len (results .Quota ))
23482508 return uint64 (len (results .Quota )), nil
23492509}
2510+
2511+ // UnsafeGetTotalCount should not be used
2512+ // Internal usage only
2513+ func (r * ListJWTsResponse ) UnsafeGetTotalCount () uint64 {
2514+ return r .TotalCount
2515+ }
2516+
2517+ // UnsafeAppend should not be used
2518+ // Internal usage only
2519+ func (r * ListJWTsResponse ) UnsafeAppend (res interface {}) (uint64 , error ) {
2520+ results , ok := res .(* ListJWTsResponse )
2521+ if ! ok {
2522+ return 0 , errors .New ("%T type cannot be appended to type %T" , res , r )
2523+ }
2524+
2525+ r .Jwts = append (r .Jwts , results .Jwts ... )
2526+ r .TotalCount += uint64 (len (results .Jwts ))
2527+ return uint64 (len (results .Jwts )), nil
2528+ }
0 commit comments