Skip to content

Commit

Permalink
Merge 64914e5 into f1091c5
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeykot committed Jul 20, 2018
2 parents f1091c5 + 64914e5 commit c06aa28
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 24 deletions.
36 changes: 19 additions & 17 deletions doc/SCC-API-(Implemented).md
Expand Up @@ -294,7 +294,7 @@ Status: 200 OK
]
}
],
"repositories": [
"repositories": [
{
"id": 1632,
"name": "SLES12-Updates",
Expand Down Expand Up @@ -388,7 +388,7 @@ Status: 200 OK
"expired": false,
"sku": "6A2BC"
} ]
}
}
]
```

Expand Down Expand Up @@ -419,8 +419,9 @@ Status: 200 OK
{
"id": 14,
"login": "SCC_28445cf5f3a84bfdaa44d4a5e499b4fd",
"password": "secret"
}
"password": "secret",
"last_seen_at": "2010-03-14T13:10:21.164Z"
}
]
```

Expand Down Expand Up @@ -453,8 +454,9 @@ Status: 200 OK
{
"id": 14,
"login": "SCC_28445cf5f3a84bfdaa44d4a5e499b4fd",
"password": "secret"
}
"password": "secret",
"last_seen_at": "2010-03-14T13:10:21.164Z"
}
```

***
Expand Down Expand Up @@ -530,7 +532,7 @@ Status: 200 OK
"product_classes": ["SLES"],
"families": ["sles", "sled"],
"skus": ["sku1", "sku2"],
"systems": [{ "id": 1, "login": "login1" }]
"systems": [{ "id": 1, "login": "login1", "last_seen_at": "2010-03-14T13:10:21.164Z" }]
}
]
```
Expand Down Expand Up @@ -825,7 +827,7 @@ curl https://scc.suse.com/connect/systems/products -u<username>:<password> -d id
]
}
],
"repositories": [
"repositories": [
{
"id": 1357,
"name": "SLE10-SDK-SP4-Online",
Expand Down Expand Up @@ -877,7 +879,7 @@ Status: 200 OK
```

```json
{
{
"id": 42,
"name": "SUSE_Linux_Enterprise_Server_12_x86_64",
"url": "https://scc.suse.com/access/services/1106?credentials=SUSE_Linux_Enterprise_Server_12_x86_64",
Expand All @@ -902,7 +904,7 @@ Status: 200 OK
"extensions": [ ],
"product_type": "base",
"recommended": false
}
}
}
```

Expand Down Expand Up @@ -939,7 +941,7 @@ Status: 200 OK
```

```json
{
{
"id": 42,
"name": "SUSE_Linux_Enterprise_Server_High_Availability_12_x86_64",
"url": "https://scc.suse.com/access/services/1106?credentials=SUSE_Linux_Enterprise_Server_12_x86_64",
Expand All @@ -964,7 +966,7 @@ Status: 200 OK
"extensions": [ ],
"product_type": "base",
"recommended": false
}
}
}
```

Expand Down Expand Up @@ -996,7 +998,7 @@ curl https://scc.suse.com/connect/systems/products -X 'PUT' -u<username>:<passwo

###### Response
```json
{
{
"id": 42,
"name": "SUSE_Linux_Enterprise_Server_12_SP1_x86_64",
"obsoleted_service_name": "SUSE_Linux_Enterprise_Server_12_x86_64",
Expand All @@ -1022,7 +1024,7 @@ curl https://scc.suse.com/connect/systems/products -X 'PUT' -u<username>:<passwo
"extensions": [ ],
"product_type": "base",
"recommended": false
}
}
}
```
##### Errors:
Expand Down Expand Up @@ -1232,7 +1234,7 @@ Status: 200 OK
"product_type": "base",
"free": "false"
},
{
{
"friendly_name":"SUSE Linux Enterprise Software Development Kit 12 x86_64",
"shortname": "SLE-SDK12-SP1",
"identifier": "SLE-SDK",
Expand Down Expand Up @@ -1362,7 +1364,7 @@ Status: 200 OK
]
}
],
"repositories": [
"repositories": [
{
"id": 1357,
"name": "SLE10-SDK-SP4-Online",
Expand Down Expand Up @@ -1411,7 +1413,7 @@ Status: 200 OK
"virtual_count": null,
"product_classes": ["7260"],
"families": ["sles", "sled"],
"systems": [{ "id": 117, "login": "login2", "password": "password2" }],
"systems": [{ "id": 117, "login": "login2", "password": "password2", "last_seen_at": "2010-05-14T09:13:26.589Z" }],
"product_ids": [239, 238, 240]
}
]
Expand Down
50 changes: 50 additions & 0 deletions examples/delete_systems.rb
@@ -0,0 +1,50 @@
#!/usr/bin/ruby

require 'rest-client'
require 'net/http'
require 'pp'
require 'json'
require 'base64'

USERNAME = ARGV[0]
PASSWORD = ARGV[1]

AUTH_HEADER = { Authorization: 'Basic ' + Base64.encode64("#{USERNAME}:#{PASSWORD}").chomp }.freeze
API_BASE_URL = 'https://scc.suse.com/connect/'.freeze

def process_rels(response)
links = (response.headers[:link] || '').split(', ').map do |link|
href, name = link.match(/<(.*?)>; rel="(\w+)"/).captures
[name.to_sym, href]
end
Hash[*links.flatten]
end

def get(url)
puts "Requesting #{url}"
res = RestClient.get(url, AUTH_HEADER)
raise StandardError, "Failed with response code #{res.code}" unless res.code == 200
res
end

def process_data(data)
JSON.parse(data).each do |system|
next if system['last_seen_at'].nil?
if Time.now - Time.parse(system['last_seen_at']) > 3600 * 24 * 14 # older than 2 weeks
puts "Deleting system #{system['id']}. Last seen at: #{system['last_seen_at']}"
RestClient.delete(
API_BASE_URL + '/systems',
{
Authorization: 'Basic ' + Base64.encode64("#{system['login']}:#{system['password']}").delete("\n")
}
)
end
end
end

links = { next: API_BASE_URL + 'organizations/systems' }
while links[:next] do
resp = get(links[:next])
process_data(resp)
links = process_rels(resp)
end
11 changes: 4 additions & 7 deletions examples/get_products_paginated.rb
Expand Up @@ -27,16 +27,13 @@ def get(url)
res
end

resp = get(URL)
@entities = []

@page = 1
loop do
links = process_rels(resp)
@entities += JSON.parse(resp)
break unless links[:next]
@page += 1
links = { next: URL }
while links[:next] do
resp = get(links[:next])
@entities += JSON.parse(resp)
links = process_rels(resp)
end

@entities.each do |entity|
Expand Down

0 comments on commit c06aa28

Please sign in to comment.